Commit 9c6fec88 authored by Sergei Petrunia's avatar Sergei Petrunia

MDEV-17171: RocksDB Tables do not have "Creation Date"

- Add SLEEP() calls to the testcase to make it really test that the
  time doesn't change.
- Always use .frm file creation time as a creation timestamp (attempts
  to re-use older create_time when the table DDL changes are not good
  because then create_time will change after server restart)
- Use the same method names as the upstream patch does
- Use std::atomic for m_update_time
parent 9c72963d
......@@ -3010,7 +3010,7 @@ class Rdb_transaction {
time_t tm;
tm = time(nullptr);
for (auto &it : modified_tables) {
it->update_time = tm;
it->m_update_time = tm;
}
modified_tables.clear();
}
......@@ -11040,11 +11040,11 @@ int ha_rocksdb::info(uint flag) {
}
}
stats.create_time = m_tbl_def->get_creation_time();
stats.create_time = m_tbl_def->get_create_time();
}
if (flag & HA_STATUS_TIME) {
stats.update_time = m_tbl_def->update_time;
stats.update_time = m_tbl_def->m_update_time;
}
if (flag & HA_STATUS_ERRKEY) {
......
......@@ -75,7 +75,25 @@ select create_time, update_time into @create_tm, @update_tm
from information_schema.tables
where table_schema=database() and table_name='t1';
# Then, an in-place ALTER TABLE:
select sleep(2);
sleep(2) 0
alter table t1 add key (a);
# create_time will change as .frm file is rewritten:
select
create_time=@create_tm,
update_time
from information_schema.tables
where table_schema=database() and table_name='t1';
create_time=@create_tm 0
update_time NULL
# Check TRUNCATE TABLE
insert into t1 values (10,10);
select create_time, update_time into @create_tm, @update_tm
from information_schema.tables
where table_schema=database() and table_name='t1';
select sleep(2);
sleep(2) 0
truncate table t1;
select
create_time=@create_tm /* should not change */,
update_time
......@@ -86,13 +104,18 @@ update_time NULL
#
# Check what is left after server restart
#
drop table t1;
create table t1 (a int);
insert into t1 values (1);
# Save t1's creation time
create table t2 as
select create_time
from information_schema.tables
where table_schema=database() and table_name='t1';
select sleep(2);
sleep(2) 0
select
create_time=(select create_time from t2) /* should change */,
create_time=(select create_time from t2) /* should not change */,
update_time
from information_schema.tables
where table_schema=database() and table_name='t1';
......
......@@ -114,26 +114,49 @@ from information_schema.tables
where table_schema=database() and table_name='t1';
--echo # Then, an in-place ALTER TABLE:
select sleep(2);
alter table t1 add key (a);
--echo # create_time will change as .frm file is rewritten:
select
create_time=@create_tm,
update_time
from information_schema.tables
where table_schema=database() and table_name='t1';
--echo # Check TRUNCATE TABLE
insert into t1 values (10,10);
select create_time, update_time into @create_tm, @update_tm
from information_schema.tables
where table_schema=database() and table_name='t1';
select sleep(2);
truncate table t1;
select
create_time=@create_tm /* should not change */,
update_time
from information_schema.tables
where table_schema=database() and table_name='t1';
--echo #
--echo # Check what is left after server restart
--echo #
drop table t1;
create table t1 (a int);
insert into t1 values (1);
--echo # Save t1's creation time
create table t2 as
select create_time
from information_schema.tables
where table_schema=database() and table_name='t1';
select sleep(2);
--source include/restart_mysqld.inc
select
create_time=(select create_time from t2) /* should change */,
create_time=(select create_time from t2) /* should not change */,
update_time
from information_schema.tables
where table_schema=database() and table_name='t1';
......
......@@ -3592,7 +3592,7 @@ bool Rdb_tbl_def::put_dict(Rdb_dict_manager *const dict,
return false;
}
time_t Rdb_tbl_def::get_creation_time() {
time_t Rdb_tbl_def::get_create_time() {
time_t create_time = m_create_time;
if (create_time == CREATE_TIME_UNKNOWN) {
......
......@@ -1093,27 +1093,24 @@ class Rdb_tbl_def {
explicit Rdb_tbl_def(const std::string &name)
: m_key_descr_arr(nullptr), m_hidden_pk_val(0), m_auto_incr_val(0),
m_create_time(CREATE_TIME_UNKNOWN) {
m_update_time(0), m_create_time(CREATE_TIME_UNKNOWN) {
set_name(name);
}
Rdb_tbl_def(const char *const name, const size_t len)
: m_key_descr_arr(nullptr), m_hidden_pk_val(0), m_auto_incr_val(0),
m_create_time(CREATE_TIME_UNKNOWN) {
m_update_time(0), m_create_time(CREATE_TIME_UNKNOWN) {
set_name(std::string(name, len));
}
explicit Rdb_tbl_def(const rocksdb::Slice &slice, const size_t pos = 0)
: m_key_descr_arr(nullptr), m_hidden_pk_val(0), m_auto_incr_val(0),
m_create_time(CREATE_TIME_UNKNOWN) {
m_update_time(0), m_create_time(CREATE_TIME_UNKNOWN) {
set_name(std::string(slice.data() + pos, slice.size() - pos));
}
~Rdb_tbl_def();
time_t get_creation_time();
time_t update_time = 0; // in-memory only value, maintained right here
void check_and_set_read_free_rpl_table();
/* Number of indexes */
......@@ -1139,6 +1136,10 @@ class Rdb_tbl_def {
const std::string &base_tablename() const { return m_tablename; }
const std::string &base_partition() const { return m_partition; }
GL_INDEX_ID get_autoincr_gl_index_id();
time_t get_create_time();
std::atomic<time_t> m_update_time; // in-memory only value
private:
const time_t CREATE_TIME_UNKNOWN= 1;
// CREATE_TIME_UNKNOWN means "didn't try to read, yet"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment