diff --git a/mysql-test/suite/rpl_gtid/r/rpl_maintain_database_hlc_rbr.result b/mysql-test/suite/rpl_gtid/r/rpl_maintain_database_hlc_rbr.result index 001b79bb464f..14ea66e134ad 100644 --- a/mysql-test/suite/rpl_gtid/r/rpl_maintain_database_hlc_rbr.result +++ b/mysql-test/suite/rpl_gtid/r/rpl_maintain_database_hlc_rbr.result @@ -418,6 +418,71 @@ DATABASE_NAME APPLIED_HLC test1 2538630000000000007 test2 2538630000000000008 test3 2538630000000000009 +Case 6: Duplicate enabling of maintain_database_hlc should not clear the map +[connection master] +SET @@global.maintain_database_hlc = ON; +SET @@global.maintain_database_hlc = ON; +select * from information_schema.database_applied_hlc order by 2, 1; +DATABASE_NAME APPLIED_HLC +test1 2538630000000000007 +test2 2538630000000000008 +test3 2538630000000000009 +[connection slave] +SET @@global.maintain_database_hlc = ON; +SET @@global.maintain_database_hlc = ON; +select * from information_schema.database_applied_hlc order by 2, 1; +DATABASE_NAME APPLIED_HLC +test1 2538630000000000007 +test2 2538630000000000008 +test3 2538630000000000009 +Case 7: Duplicate enabling of binlog_hlc should not clear the map +[connection master] +SET @@global.enable_binlog_hlc = ON; +SET @@global.enable_binlog_hlc = ON; +select * from information_schema.database_applied_hlc order by 2, 1; +DATABASE_NAME APPLIED_HLC +test1 2538630000000000007 +test2 2538630000000000008 +test3 2538630000000000009 +[connection slave] +SET @@global.enable_binlog_hlc = ON; +SET @@global.enable_binlog_hlc = ON; +select * from information_schema.database_applied_hlc order by 2, 1; +DATABASE_NAME APPLIED_HLC +test1 2538630000000000007 +test2 2538630000000000008 +test3 2538630000000000009 +Case 8: Disabling maintain_database_hlc should clear the map +[connection master] +SET @@global.maintain_database_hlc = OFF; +select * from information_schema.database_applied_hlc order by 2, 1; +DATABASE_NAME APPLIED_HLC +[connection slave] +SET @@global.maintain_database_hlc = OFF; +select * from information_schema.database_applied_hlc order by 2, 1; +DATABASE_NAME APPLIED_HLC +Case 9: Disabling enable_binlog_hlc should clear the map +[connection master] +SET @@global.maintain_database_hlc = ON; +[connection slave] +SET @@global.maintain_database_hlc = ON; +[connection master] +insert into test1.t2 values(100); +commit; +select * from information_schema.database_applied_hlc order by 2, 1; +DATABASE_NAME APPLIED_HLC +test1 2538630000000000010 +SET @@global.enable_binlog_hlc = OFF; +select * from information_schema.database_applied_hlc order by 2, 1; +DATABASE_NAME APPLIED_HLC +include/sync_slave_sql_with_master.inc +[connection slave] +select * from information_schema.database_applied_hlc order by 2, 1; +DATABASE_NAME APPLIED_HLC +test1 2538630000000000010 +SET @@global.enable_binlog_hlc = OFF; +select * from information_schema.database_applied_hlc order by 2, 1; +DATABASE_NAME APPLIED_HLC [connection master] DROP TABLE test1.t1; DROP TABLE test2.t1; diff --git a/mysql-test/suite/rpl_gtid/r/rpl_maintain_database_hlc_sbr.result b/mysql-test/suite/rpl_gtid/r/rpl_maintain_database_hlc_sbr.result index 4eda35ed58a2..6bb16219339d 100644 --- a/mysql-test/suite/rpl_gtid/r/rpl_maintain_database_hlc_sbr.result +++ b/mysql-test/suite/rpl_gtid/r/rpl_maintain_database_hlc_sbr.result @@ -370,6 +370,71 @@ DATABASE_NAME APPLIED_HLC test1 2538630000000000007 test2 2538630000000000008 test3 2538630000000000009 +Case 6: Duplicate enabling of maintain_database_hlc should not clear the map +[connection master] +SET @@global.maintain_database_hlc = ON; +SET @@global.maintain_database_hlc = ON; +select * from information_schema.database_applied_hlc order by 2, 1; +DATABASE_NAME APPLIED_HLC +test1 2538630000000000007 +test2 2538630000000000008 +test3 2538630000000000009 +[connection slave] +SET @@global.maintain_database_hlc = ON; +SET @@global.maintain_database_hlc = ON; +select * from information_schema.database_applied_hlc order by 2, 1; +DATABASE_NAME APPLIED_HLC +test1 2538630000000000007 +test2 2538630000000000008 +test3 2538630000000000009 +Case 7: Duplicate enabling of binlog_hlc should not clear the map +[connection master] +SET @@global.enable_binlog_hlc = ON; +SET @@global.enable_binlog_hlc = ON; +select * from information_schema.database_applied_hlc order by 2, 1; +DATABASE_NAME APPLIED_HLC +test1 2538630000000000007 +test2 2538630000000000008 +test3 2538630000000000009 +[connection slave] +SET @@global.enable_binlog_hlc = ON; +SET @@global.enable_binlog_hlc = ON; +select * from information_schema.database_applied_hlc order by 2, 1; +DATABASE_NAME APPLIED_HLC +test1 2538630000000000007 +test2 2538630000000000008 +test3 2538630000000000009 +Case 8: Disabling maintain_database_hlc should clear the map +[connection master] +SET @@global.maintain_database_hlc = OFF; +select * from information_schema.database_applied_hlc order by 2, 1; +DATABASE_NAME APPLIED_HLC +[connection slave] +SET @@global.maintain_database_hlc = OFF; +select * from information_schema.database_applied_hlc order by 2, 1; +DATABASE_NAME APPLIED_HLC +Case 9: Disabling enable_binlog_hlc should clear the map +[connection master] +SET @@global.maintain_database_hlc = ON; +[connection slave] +SET @@global.maintain_database_hlc = ON; +[connection master] +insert into test1.t2 values(100); +commit; +select * from information_schema.database_applied_hlc order by 2, 1; +DATABASE_NAME APPLIED_HLC +test1 2538630000000000010 +SET @@global.enable_binlog_hlc = OFF; +select * from information_schema.database_applied_hlc order by 2, 1; +DATABASE_NAME APPLIED_HLC +include/sync_slave_sql_with_master.inc +[connection slave] +select * from information_schema.database_applied_hlc order by 2, 1; +DATABASE_NAME APPLIED_HLC +test1 2538630000000000010 +SET @@global.enable_binlog_hlc = OFF; +select * from information_schema.database_applied_hlc order by 2, 1; +DATABASE_NAME APPLIED_HLC [connection master] DROP TABLE test1.t1; DROP TABLE test2.t1; diff --git a/mysql-test/suite/rpl_gtid/t/rpl_maintain_database_hlc.inc b/mysql-test/suite/rpl_gtid/t/rpl_maintain_database_hlc.inc index 33f4f1ae9e2a..fa38e7170dbf 100644 --- a/mysql-test/suite/rpl_gtid/t/rpl_maintain_database_hlc.inc +++ b/mysql-test/suite/rpl_gtid/t/rpl_maintain_database_hlc.inc @@ -101,7 +101,6 @@ SELECT * FROM test1.t1; SELECT * FROM test2.t1; SELECT * FROM information_schema.database_applied_hlc ORDER BY 2, 1; - --echo Case 5: Pure DDL should also update and maintain per database HLC --source include/rpl_connection_master.inc SET autocommit = OFF; @@ -115,6 +114,56 @@ SELECT * FROM information_schema.database_applied_hlc ORDER BY 2, 1; --source include/rpl_connection_slave.inc SELECT * FROM information_schema.database_applied_hlc ORDER BY 2, 1; +-- echo Case 6: Duplicate enabling of maintain_database_hlc should not clear the map +--source include/rpl_connection_master.inc +SET @@global.maintain_database_hlc = ON; +SET @@global.maintain_database_hlc = ON; +select * from information_schema.database_applied_hlc order by 2, 1; + +--source include/rpl_connection_slave.inc +SET @@global.maintain_database_hlc = ON; +SET @@global.maintain_database_hlc = ON; +select * from information_schema.database_applied_hlc order by 2, 1; + +-- echo Case 7: Duplicate enabling of binlog_hlc should not clear the map +--source include/rpl_connection_master.inc +SET @@global.enable_binlog_hlc = ON; +SET @@global.enable_binlog_hlc = ON; +select * from information_schema.database_applied_hlc order by 2, 1; + +--source include/rpl_connection_slave.inc +SET @@global.enable_binlog_hlc = ON; +SET @@global.enable_binlog_hlc = ON; +select * from information_schema.database_applied_hlc order by 2, 1; + +-- echo Case 8: Disabling maintain_database_hlc should clear the map +--source include/rpl_connection_master.inc +SET @@global.maintain_database_hlc = OFF; +select * from information_schema.database_applied_hlc order by 2, 1; + +--source include/rpl_connection_slave.inc +SET @@global.maintain_database_hlc = OFF; +select * from information_schema.database_applied_hlc order by 2, 1; + +-- echo Case 9: Disabling enable_binlog_hlc should clear the map +--source include/rpl_connection_master.inc +SET @@global.maintain_database_hlc = ON; +--source include/rpl_connection_slave.inc +SET @@global.maintain_database_hlc = ON; + +--source include/rpl_connection_master.inc +insert into test1.t2 values(100); +commit; +select * from information_schema.database_applied_hlc order by 2, 1; +SET @@global.enable_binlog_hlc = OFF; +select * from information_schema.database_applied_hlc order by 2, 1; + +--source include/sync_slave_sql_with_master.inc +--source include/rpl_connection_slave.inc +select * from information_schema.database_applied_hlc order by 2, 1; +SET @@global.enable_binlog_hlc = OFF; +select * from information_schema.database_applied_hlc order by 2, 1; + # Cleanup --source include/rpl_connection_master.inc --disable_query_log diff --git a/sql/binlog.cc b/sql/binlog.cc index 03e2be84d3de..a27b0375055b 100644 --- a/sql/binlog.cc +++ b/sql/binlog.cc @@ -2758,6 +2758,11 @@ database_hlc_container HybridLogicalClock::get_database_hlc() const { return database_applied_hlc_; } +void HybridLogicalClock::clear_database_hlc() { + std::unique_lock lock(database_applied_hlc_lock_); + database_applied_hlc_.clear(); +} + /** Write a rollback record of the transaction to the binary log. @@ -9238,7 +9243,7 @@ void MYSQL_BIN_LOG::process_after_commit_stage_queue(THD *thd, THD *first) { // Successfully committed the trx to engine. Update applied hlc for // all databases that this trx touches hlc.update_database_hlc(head->databases, head->hlc_time_ns_next); - } else { + } else if (log_error_verbosity >= 3) { // Log a error line if databases are empty. This could happen in SBR // NO_LINT_DEBUG sql_print_error("Databases were empty for this trx. HLC= %lu", diff --git a/sql/binlog.h b/sql/binlog.h index 76b4d9cef1f7..4863d4f6d7f3 100644 --- a/sql/binlog.h +++ b/sql/binlog.h @@ -207,6 +207,11 @@ class HybridLogicalClock { */ database_hlc_container get_database_hlc() const; + /** + * Clear database HLC map + */ + void clear_database_hlc(); + private: // nanosecond precision internal clock std::atomic current_; @@ -723,6 +728,8 @@ class MYSQL_BIN_LOG : public TC_LOG { return hlc.get_database_hlc(); } + void clear_database_hlc() { return hlc.clear_database_hlc(); } + private: std::atomic atomic_log_state{LOG_CLOSED}; diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index bce2f4a508bf..84f0e2f3d018 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -8536,6 +8536,9 @@ static bool check_enable_binlog_hlc(sys_var * /* self */, THD * /* thd */, if (global_gtid_mode.get() != Gtid_mode::ON && new_enable_binlog_hlc) return true; // Needs gtid mode to enable binlog hlc + // if the feature is being turned off, then clear the map + if (!new_enable_binlog_hlc) mysql_bin_log.clear_database_hlc(); + return false; } @@ -8547,6 +8550,10 @@ static Sys_var_bool Sys_enable_binlog_hlc( static bool check_maintain_database_hlc(sys_var *, THD *, set_var *var) { uint64_t new_maintain_db_hlc = var->save_result.ulonglong_value; + + // if the feature is being turned off, then clear the map + if (!new_maintain_db_hlc) mysql_bin_log.clear_database_hlc(); + if (!enable_binlog_hlc && new_maintain_db_hlc) return true; // Needs enable_binlog_hlc