summaryrefslogtreecommitdiff
path: root/storage
diff options
context:
space:
mode:
authorSergei Petrunia <psergey@askmonty.org>2019-11-01 21:40:10 +0300
committerSergei Petrunia <psergey@askmonty.org>2019-11-01 21:40:10 +0300
commit9c6fec88b10bfe51d87f63e6a6ea474cd18d1952 (patch)
tree9c4fe0f8be7ea3e538ff7296bb68b96047739ed9 /storage
parent9c72963d2aef783cae652b5b8ac01f7aa2bcb43a (diff)
downloadmariadb-git-9c6fec88b10bfe51d87f63e6a6ea474cd18d1952.tar.gz
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
Diffstat (limited to 'storage')
-rw-r--r--storage/rocksdb/ha_rocksdb.cc6
-rw-r--r--storage/rocksdb/mysql-test/rocksdb/r/show_table_status.result25
-rw-r--r--storage/rocksdb/mysql-test/rocksdb/t/show_table_status.test27
-rw-r--r--storage/rocksdb/rdb_datadic.cc2
-rw-r--r--storage/rocksdb/rdb_datadic.h13
5 files changed, 60 insertions, 13 deletions
diff --git a/storage/rocksdb/ha_rocksdb.cc b/storage/rocksdb/ha_rocksdb.cc
index f063d76f49c..d7d1b1665f7 100644
--- a/storage/rocksdb/ha_rocksdb.cc
+++ b/storage/rocksdb/ha_rocksdb.cc
@@ -3010,7 +3010,7 @@ protected:
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) {
diff --git a/storage/rocksdb/mysql-test/rocksdb/r/show_table_status.result b/storage/rocksdb/mysql-test/rocksdb/r/show_table_status.result
index ca373112c1c..d95549be4c1 100644
--- a/storage/rocksdb/mysql-test/rocksdb/r/show_table_status.result
+++ b/storage/rocksdb/mysql-test/rocksdb/r/show_table_status.result
@@ -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';
diff --git a/storage/rocksdb/mysql-test/rocksdb/t/show_table_status.test b/storage/rocksdb/mysql-test/rocksdb/t/show_table_status.test
index 109301a8879..55854710c31 100644
--- a/storage/rocksdb/mysql-test/rocksdb/t/show_table_status.test
+++ b/storage/rocksdb/mysql-test/rocksdb/t/show_table_status.test
@@ -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';
diff --git a/storage/rocksdb/rdb_datadic.cc b/storage/rocksdb/rdb_datadic.cc
index 0cefed77ac8..0d43d4da5c4 100644
--- a/storage/rocksdb/rdb_datadic.cc
+++ b/storage/rocksdb/rdb_datadic.cc
@@ -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) {
diff --git a/storage/rocksdb/rdb_datadic.h b/storage/rocksdb/rdb_datadic.h
index d6cb242bd35..7bcc45d3f62 100644
--- a/storage/rocksdb/rdb_datadic.h
+++ b/storage/rocksdb/rdb_datadic.h
@@ -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"