Skip to content

Commit

Permalink
decrease log level and clear map when feature is diabled
Browse files Browse the repository at this point in the history
Summary:
See some instance being spammed by a log line. Decreasing the verbosity of log.
Also, clear the in-memory map containing database applied hlc when the feature is disabled

Differential Revision: D21408194
  • Loading branch information
bhatvinay authored and inikep committed May 24, 2024
1 parent 2a3d3f4 commit af26260
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 2 deletions.
65 changes: 65 additions & 0 deletions mysql-test/suite/rpl_gtid/r/rpl_maintain_database_hlc_rbr.result
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
65 changes: 65 additions & 0 deletions mysql-test/suite/rpl_gtid/r/rpl_maintain_database_hlc_sbr.result
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
51 changes: 50 additions & 1 deletion mysql-test/suite/rpl_gtid/t/rpl_maintain_database_hlc.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
7 changes: 6 additions & 1 deletion sql/binlog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2758,6 +2758,11 @@ database_hlc_container HybridLogicalClock::get_database_hlc() const {
return database_applied_hlc_;
}

void HybridLogicalClock::clear_database_hlc() {
std::unique_lock<std::mutex> lock(database_applied_hlc_lock_);
database_applied_hlc_.clear();
}

/**
Write a rollback record of the transaction to the binary log.

Expand Down Expand Up @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions sql/binlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint64_t> current_;
Expand Down Expand Up @@ -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<enum_log_state> atomic_log_state{LOG_CLOSED};

Expand Down
7 changes: 7 additions & 0 deletions sql/sys_vars.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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

Expand Down

0 comments on commit af26260

Please sign in to comment.