Skip to content

Commit d73f98b

Browse files
BUG#29049207: SLAVE PERFORMANCE DEGRADES OVER TIME
ANALYSIS: ========= If a slave instance use sysvar_session_track_gtids == OWN_GTID and with MTS enabled, the slave will lag behind master and its performance degrades over time. Each slave worker adds its own gtid into its Session_consistency_gtids_ctx.m_gtid_set during each transaction commit. Overtime, the Session_consistency_gtids_ctx.m_gtid_set may have gno_interval in millions and thus will take long time to insert a gtid into Session_consistency_gtids_ctx.m_gtid_set. This causes the lag/performance degrade. FIX: ==== Disable tracking GTIDs for slave threads. Note: ===== This patch is based on a contribution by Facebook. RB#25006
1 parent f73bdc4 commit d73f98b

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

sql/rpl_context.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -136,6 +136,12 @@ bool Session_consistency_gtids_ctx::notify_after_gtid_executed_update(const THD
136136
DBUG_RETURN(res);
137137
}
138138

139+
void Session_consistency_gtids_ctx::
140+
update_tracking_activeness_from_session_variable(const THD* thd)
141+
{
142+
m_curr_session_track_gtids= thd->variables.session_track_gtids;
143+
}
144+
139145
bool Session_consistency_gtids_ctx::notify_after_response_packet(const THD *thd)
140146
{
141147
int res= false;
@@ -149,7 +155,7 @@ bool Session_consistency_gtids_ctx::notify_after_response_packet(const THD *thd)
149155
this value. It may have changed (the previous command may have been
150156
a SET SESSION session_track_gtids=...;).
151157
*/
152-
m_curr_session_track_gtids= thd->variables.session_track_gtids;
158+
update_tracking_activeness_from_session_variable(thd);
153159
DBUG_RETURN(res);
154160
}
155161

@@ -171,7 +177,7 @@ Session_consistency_gtids_ctx::register_ctx_change_listener(
171177
if the session_track_gtids value is set at startup time to anything
172178
different than OFF.
173179
*/
174-
m_curr_session_track_gtids= thd->variables.session_track_gtids;
180+
update_tracking_activeness_from_session_variable(thd);
175181
}
176182
}
177183

sql/rpl_context.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -202,6 +202,10 @@ class Session_consistency_gtids_ctx
202202
return notify_after_transaction_commit(thd);
203203
}
204204

205+
/**
206+
Update session tracker (m_curr_session_track_gtids) from thd.
207+
*/
208+
void update_tracking_activeness_from_session_variable(const THD* thd);
205209

206210
private:
207211
// not implemented

sql/rpl_slave.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -4207,6 +4207,11 @@ void set_slave_thread_options(THD* thd)
42074207
thd->variables.option_bits= options;
42084208
thd->variables.completion_type= 0;
42094209

4210+
/* Do not track GTIDs for slave threads to avoid performance issues. */
4211+
thd->variables.session_track_gtids= OFF;
4212+
thd->rpl_thd_ctx.session_gtids_ctx()
4213+
.update_tracking_activeness_from_session_variable(thd);
4214+
42104215
/*
42114216
Set autocommit= 1 when info tables are used and autocommit == 0 to
42124217
avoid trigger asserts on mysql_execute_command(THD *thd) caused by

0 commit comments

Comments
 (0)