mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
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
This commit is contained in:
@@ -3010,7 +3010,7 @@ protected:
|
|||||||
time_t tm;
|
time_t tm;
|
||||||
tm = time(nullptr);
|
tm = time(nullptr);
|
||||||
for (auto &it : modified_tables) {
|
for (auto &it : modified_tables) {
|
||||||
it->update_time = tm;
|
it->m_update_time = tm;
|
||||||
}
|
}
|
||||||
modified_tables.clear();
|
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) {
|
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) {
|
if (flag & HA_STATUS_ERRKEY) {
|
||||||
|
@@ -75,7 +75,25 @@ select create_time, update_time into @create_tm, @update_tm
|
|||||||
from information_schema.tables
|
from information_schema.tables
|
||||||
where table_schema=database() and table_name='t1';
|
where table_schema=database() and table_name='t1';
|
||||||
# Then, an in-place ALTER TABLE:
|
# Then, an in-place ALTER TABLE:
|
||||||
|
select sleep(2);
|
||||||
|
sleep(2) 0
|
||||||
alter table t1 add key (a);
|
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
|
select
|
||||||
create_time=@create_tm /* should not change */,
|
create_time=@create_tm /* should not change */,
|
||||||
update_time
|
update_time
|
||||||
@@ -86,13 +104,18 @@ update_time NULL
|
|||||||
#
|
#
|
||||||
# Check what is left after server restart
|
# 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
|
# Save t1's creation time
|
||||||
create table t2 as
|
create table t2 as
|
||||||
select create_time
|
select create_time
|
||||||
from information_schema.tables
|
from information_schema.tables
|
||||||
where table_schema=database() and table_name='t1';
|
where table_schema=database() and table_name='t1';
|
||||||
|
select sleep(2);
|
||||||
|
sleep(2) 0
|
||||||
select
|
select
|
||||||
create_time=(select create_time from t2) /* should change */,
|
create_time=(select create_time from t2) /* should not change */,
|
||||||
update_time
|
update_time
|
||||||
from information_schema.tables
|
from information_schema.tables
|
||||||
where table_schema=database() and table_name='t1';
|
where table_schema=database() and table_name='t1';
|
||||||
|
@@ -114,26 +114,49 @@ from information_schema.tables
|
|||||||
where table_schema=database() and table_name='t1';
|
where table_schema=database() and table_name='t1';
|
||||||
|
|
||||||
--echo # Then, an in-place ALTER TABLE:
|
--echo # Then, an in-place ALTER TABLE:
|
||||||
|
select sleep(2);
|
||||||
alter table t1 add key (a);
|
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
|
select
|
||||||
create_time=@create_tm /* should not change */,
|
create_time=@create_tm /* should not change */,
|
||||||
update_time
|
update_time
|
||||||
from information_schema.tables
|
from information_schema.tables
|
||||||
where table_schema=database() and table_name='t1';
|
where table_schema=database() and table_name='t1';
|
||||||
|
|
||||||
|
|
||||||
--echo #
|
--echo #
|
||||||
--echo # Check what is left after server restart
|
--echo # Check what is left after server restart
|
||||||
--echo #
|
--echo #
|
||||||
|
drop table t1;
|
||||||
|
create table t1 (a int);
|
||||||
|
insert into t1 values (1);
|
||||||
--echo # Save t1's creation time
|
--echo # Save t1's creation time
|
||||||
create table t2 as
|
create table t2 as
|
||||||
select create_time
|
select create_time
|
||||||
from information_schema.tables
|
from information_schema.tables
|
||||||
where table_schema=database() and table_name='t1';
|
where table_schema=database() and table_name='t1';
|
||||||
|
|
||||||
|
select sleep(2);
|
||||||
|
--source include/restart_mysqld.inc
|
||||||
|
|
||||||
select
|
select
|
||||||
create_time=(select create_time from t2) /* should change */,
|
create_time=(select create_time from t2) /* should not change */,
|
||||||
update_time
|
update_time
|
||||||
from information_schema.tables
|
from information_schema.tables
|
||||||
where table_schema=database() and table_name='t1';
|
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;
|
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;
|
time_t create_time = m_create_time;
|
||||||
|
|
||||||
if (create_time == CREATE_TIME_UNKNOWN) {
|
if (create_time == CREATE_TIME_UNKNOWN) {
|
||||||
|
@@ -1093,27 +1093,24 @@ class Rdb_tbl_def {
|
|||||||
|
|
||||||
explicit Rdb_tbl_def(const std::string &name)
|
explicit Rdb_tbl_def(const std::string &name)
|
||||||
: m_key_descr_arr(nullptr), m_hidden_pk_val(0), m_auto_incr_val(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(name);
|
set_name(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
Rdb_tbl_def(const char *const name, const size_t len)
|
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_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));
|
set_name(std::string(name, len));
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit Rdb_tbl_def(const rocksdb::Slice &slice, const size_t pos = 0)
|
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_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));
|
set_name(std::string(slice.data() + pos, slice.size() - pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
~Rdb_tbl_def();
|
~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();
|
void check_and_set_read_free_rpl_table();
|
||||||
|
|
||||||
/* Number of indexes */
|
/* Number of indexes */
|
||||||
@@ -1139,6 +1136,10 @@ class Rdb_tbl_def {
|
|||||||
const std::string &base_tablename() const { return m_tablename; }
|
const std::string &base_tablename() const { return m_tablename; }
|
||||||
const std::string &base_partition() const { return m_partition; }
|
const std::string &base_partition() const { return m_partition; }
|
||||||
GL_INDEX_ID get_autoincr_gl_index_id();
|
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:
|
private:
|
||||||
const time_t CREATE_TIME_UNKNOWN= 1;
|
const time_t CREATE_TIME_UNKNOWN= 1;
|
||||||
// CREATE_TIME_UNKNOWN means "didn't try to read, yet"
|
// CREATE_TIME_UNKNOWN means "didn't try to read, yet"
|
||||||
|
Reference in New Issue
Block a user