Skip to content

Commit

Permalink
add histogram for rpl_semi_sync_master_trx_wait
Browse files Browse the repository at this point in the history
Summary:
add histogram for rpl_semi_sync_master_trx_wait.

8.0 porting notes: Keeps the same histogram status variables as before
since these are already being read by various applications. We should
eventually remove this.

Reference Patch: facebook@d1a1394
Reference Patch: facebook@15333b2e6f9

Differential Revision: D21832889
  • Loading branch information
santoshbanda authored and Herman Lee committed Jul 14, 2022
1 parent 068f5be commit 19345e3
Show file tree
Hide file tree
Showing 14 changed files with 667 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ SET PERSIST_ONLY rpl_receive_buffer_size = @@GLOBAL.rpl_receive_buffer_size;
SET PERSIST_ONLY rpl_semi_sync_replica_enabled = @@GLOBAL.rpl_semi_sync_replica_enabled;
SET PERSIST_ONLY rpl_semi_sync_replica_trace_level = @@GLOBAL.rpl_semi_sync_replica_trace_level;
SET PERSIST_ONLY rpl_semi_sync_source_enabled = @@GLOBAL.rpl_semi_sync_source_enabled;
SET PERSIST_ONLY rpl_semi_sync_source_histogram_trx_wait_step_size = @@GLOBAL.rpl_semi_sync_source_histogram_trx_wait_step_size;
SET PERSIST_ONLY rpl_semi_sync_source_timeout = @@GLOBAL.rpl_semi_sync_source_timeout;
SET PERSIST_ONLY rpl_semi_sync_source_trace_level = @@GLOBAL.rpl_semi_sync_source_trace_level;
SET PERSIST_ONLY rpl_semi_sync_source_wait_for_replica_count = @@GLOBAL.rpl_semi_sync_source_wait_for_replica_count;
Expand Down Expand Up @@ -386,6 +387,7 @@ RESET PERSIST rpl_receive_buffer_size;
RESET PERSIST rpl_semi_sync_replica_enabled;
RESET PERSIST rpl_semi_sync_replica_trace_level;
RESET PERSIST rpl_semi_sync_source_enabled;
RESET PERSIST rpl_semi_sync_source_histogram_trx_wait_step_size;
RESET PERSIST rpl_semi_sync_source_timeout;
RESET PERSIST rpl_semi_sync_source_trace_level;
RESET PERSIST rpl_semi_sync_source_wait_for_replica_count;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ SET PERSIST rpl_receive_buffer_size = @@GLOBAL.rpl_receive_buffer_size;
SET PERSIST rpl_semi_sync_replica_enabled = @@GLOBAL.rpl_semi_sync_replica_enabled;
SET PERSIST rpl_semi_sync_replica_trace_level = @@GLOBAL.rpl_semi_sync_replica_trace_level;
SET PERSIST rpl_semi_sync_source_enabled = @@GLOBAL.rpl_semi_sync_source_enabled;
SET PERSIST rpl_semi_sync_source_histogram_trx_wait_step_size = @@GLOBAL.rpl_semi_sync_source_histogram_trx_wait_step_size;
SET PERSIST rpl_semi_sync_source_timeout = @@GLOBAL.rpl_semi_sync_source_timeout;
SET PERSIST rpl_semi_sync_source_trace_level = @@GLOBAL.rpl_semi_sync_source_trace_level;
SET PERSIST rpl_semi_sync_source_wait_for_replica_count = @@GLOBAL.rpl_semi_sync_source_wait_for_replica_count;
Expand Down Expand Up @@ -402,6 +403,7 @@ RESET PERSIST IF EXISTS rpl_receive_buffer_size;
RESET PERSIST IF EXISTS rpl_semi_sync_replica_enabled;
RESET PERSIST IF EXISTS rpl_semi_sync_replica_trace_level;
RESET PERSIST IF EXISTS rpl_semi_sync_source_enabled;
RESET PERSIST IF EXISTS rpl_semi_sync_source_histogram_trx_wait_step_size;
RESET PERSIST IF EXISTS rpl_semi_sync_source_timeout;
RESET PERSIST IF EXISTS rpl_semi_sync_source_trace_level;
RESET PERSIST IF EXISTS rpl_semi_sync_source_wait_for_replica_count;
Expand Down
12 changes: 12 additions & 0 deletions mysql-test/suite/rpl_nogtid/r/rpl_semi_sync.result
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ Rpl_semi_sync_source_status ON
show status like 'Rpl_semi_sync_source_yes_tx';
Variable_name Value
Rpl_semi_sync_source_yes_tx 0
show status like 'Rpl_semi_sync_master_trx_wait_histogram%';
Variable_name Value
Rpl_semi_sync_master_trx_wait_histogram_0-500us 0
Rpl_semi_sync_master_trx_wait_histogram_500-1500us 0
Rpl_semi_sync_master_trx_wait_histogram_1500-3500us 0
Rpl_semi_sync_master_trx_wait_histogram_3500-7500us 0
Rpl_semi_sync_master_trx_wait_histogram_7500-15500us 0
Rpl_semi_sync_master_trx_wait_histogram_15500-31500us 0
Rpl_semi_sync_master_trx_wait_histogram_31500-63500us 0
Rpl_semi_sync_master_trx_wait_histogram_63500-127500us 0
Rpl_semi_sync_master_trx_wait_histogram_127500-255500us 0
Rpl_semi_sync_master_trx_wait_histogram_255500-MAXus 0
#
# BUG#45672 Semisync repl: ActiveTranx:insert_tranx_node: transaction node allocation failed
# BUG#45673 Semisync reports correct operation even if no slave is connected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ Rpl_semi_sync_source_status ON
show status like 'Rpl_semi_sync_source_yes_tx';
Variable_name Value
Rpl_semi_sync_source_yes_tx 0
show status like 'Rpl_semi_sync_master_trx_wait_histogram%';
Variable_name Value
Rpl_semi_sync_master_trx_wait_histogram_0-500us 0
Rpl_semi_sync_master_trx_wait_histogram_500-1500us 0
Rpl_semi_sync_master_trx_wait_histogram_1500-3500us 0
Rpl_semi_sync_master_trx_wait_histogram_3500-7500us 0
Rpl_semi_sync_master_trx_wait_histogram_7500-15500us 0
Rpl_semi_sync_master_trx_wait_histogram_15500-31500us 0
Rpl_semi_sync_master_trx_wait_histogram_31500-63500us 0
Rpl_semi_sync_master_trx_wait_histogram_63500-127500us 0
Rpl_semi_sync_master_trx_wait_histogram_127500-255500us 0
Rpl_semi_sync_master_trx_wait_histogram_255500-MAXus 0
#
# BUG#45672 Semisync repl: ActiveTranx:insert_tranx_node: transaction node allocation failed
# BUG#45673 Semisync reports correct operation even if no slave is connected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ Rpl_semi_sync_source_status ON
show status like 'Rpl_semi_sync_source_yes_tx';
Variable_name Value
Rpl_semi_sync_source_yes_tx 0
show status like 'Rpl_semi_sync_master_trx_wait_histogram%';
Variable_name Value
Rpl_semi_sync_master_trx_wait_histogram_0-500us 0
Rpl_semi_sync_master_trx_wait_histogram_500-1500us 0
Rpl_semi_sync_master_trx_wait_histogram_1500-3500us 0
Rpl_semi_sync_master_trx_wait_histogram_3500-7500us 0
Rpl_semi_sync_master_trx_wait_histogram_7500-15500us 0
Rpl_semi_sync_master_trx_wait_histogram_15500-31500us 0
Rpl_semi_sync_master_trx_wait_histogram_31500-63500us 0
Rpl_semi_sync_master_trx_wait_histogram_63500-127500us 0
Rpl_semi_sync_master_trx_wait_histogram_127500-255500us 0
Rpl_semi_sync_master_trx_wait_histogram_255500-MAXus 0
#
# BUG#45672 Semisync repl: ActiveTranx:insert_tranx_node: transaction node allocation failed
# BUG#45673 Semisync reports correct operation even if no slave is connected
Expand Down
1 change: 1 addition & 0 deletions mysql-test/suite/rpl_nogtid/t/rpl_semi_sync.test
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ echo [ status of semi-sync on master should be ON even without any semi-sync sla
show status like 'Rpl_semi_sync_source_clients';
show status like 'Rpl_semi_sync_source_status';
show status like 'Rpl_semi_sync_source_yes_tx';
show status like 'Rpl_semi_sync_master_trx_wait_histogram%';

--echo #
--echo # BUG#45672 Semisync repl: ActiveTranx:insert_tranx_node: transaction node allocation failed
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
SELECT COUNT(@@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size);
COUNT(@@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size)
1
1 Expected
SET @start_global_value = @@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size;
SELECT @start_global_value;
@start_global_value
500us
16ms Expected
SET @@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size='16us';
select @@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size;
@@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size
16us
16us Expected
select * from performance_schema.global_variables where variable_name='rpl_semi_sync_master_histogram_trx_wait_step_size';
VARIABLE_NAME VARIABLE_VALUE
rpl_semi_sync_master_histogram_trx_wait_step_size 16us
SELECT @@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size = VARIABLE_VALUE
FROM performance_schema.global_variables
WHERE VARIABLE_NAME='rpl_semi_sync_master_histogram_trx_wait_step_size';
@@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size = VARIABLE_VALUE
1
1 Expected
SELECT COUNT(@@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size);
COUNT(@@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size)
1
1 Expected
SELECT COUNT(VARIABLE_VALUE)
FROM performance_schema.global_variables
WHERE VARIABLE_NAME='rpl_semi_sync_master_histogram_trx_wait_step_size';
COUNT(VARIABLE_VALUE)
1
1 Expected
SELECT COUNT(@@local.rpl_semi_sync_master_histogram_trx_wait_step_size);
ERROR HY000: Variable 'rpl_semi_sync_master_histogram_trx_wait_step_size' is a GLOBAL variable
Expected error 'Variable is a GLOBAL variable'
SELECT COUNT(@@SESSION.rpl_semi_sync_master_histogram_trx_wait_step_size);
ERROR HY000: Variable 'rpl_semi_sync_master_histogram_trx_wait_step_size' is a GLOBAL variable
Expected error 'Variable is a GLOBAL variable'
SET @@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size='32';
ERROR 42000: Variable 'rpl_semi_sync_master_histogram_trx_wait_step_size' can't be set to the value of '32'
Expected error 'Variable cannot be set to this value';
SET @@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size='0';
select @@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size;
@@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size
0
0 Expected
SET @@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size='ms32';
ERROR 42000: Variable 'rpl_semi_sync_master_histogram_trx_wait_step_size' can't be set to the value of 'ms32'
Expected error 'Variable cannot be set to this value';
SET @@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size='32ps';
ERROR 42000: Variable 'rpl_semi_sync_master_histogram_trx_wait_step_size' can't be set to the value of '32ps'
Expected error 'Variable cannot be set to this value';
SET @@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size='3s2';
ERROR 42000: Variable 'rpl_semi_sync_master_histogram_trx_wait_step_size' can't be set to the value of '3s2'
Expected error 'Variable cannot be set to this value';
SET @@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size='32@s';
ERROR 42000: Variable 'rpl_semi_sync_master_histogram_trx_wait_step_size' can't be set to the value of '32@s'
Expected error 'Variable cannot be set to this value';
SET @@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size='32s.';
ERROR 42000: Variable 'rpl_semi_sync_master_histogram_trx_wait_step_size' can't be set to the value of '32s.'
Expected error 'Variable cannot be set to this value';
SET @@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size='s';
ERROR 42000: Variable 'rpl_semi_sync_master_histogram_trx_wait_step_size' can't be set to the value of 's'
Expected error 'Variable cannot be set to this value'
SET @@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size='16.5us';
select @@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size;
@@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size
16.5us
16.5us Expected
SET @@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size = @start_global_value;
SELECT @@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size;
@@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size
500us
16ms Expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$SEMISYNC_MASTER_PLUGIN_OPT $SEMISYNC_MASTER_PLUGIN_LOAD
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
SELECT COUNT(@@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size);
--echo 1 Expected

SET @start_global_value = @@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size;
SELECT @start_global_value;
--echo 16ms Expected

SET @@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size='16us';
select @@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size;
--echo 16us Expected

select * from performance_schema.global_variables where variable_name='rpl_semi_sync_master_histogram_trx_wait_step_size';

SELECT @@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size = VARIABLE_VALUE
FROM performance_schema.global_variables
WHERE VARIABLE_NAME='rpl_semi_sync_master_histogram_trx_wait_step_size';
--echo 1 Expected

SELECT COUNT(@@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size);
--echo 1 Expected

SELECT COUNT(VARIABLE_VALUE)
FROM performance_schema.global_variables
WHERE VARIABLE_NAME='rpl_semi_sync_master_histogram_trx_wait_step_size';
--echo 1 Expected

--Error ER_INCORRECT_GLOBAL_LOCAL_VAR
SELECT COUNT(@@local.rpl_semi_sync_master_histogram_trx_wait_step_size);
--echo Expected error 'Variable is a GLOBAL variable'

--Error ER_INCORRECT_GLOBAL_LOCAL_VAR
SELECT COUNT(@@SESSION.rpl_semi_sync_master_histogram_trx_wait_step_size);
--echo Expected error 'Variable is a GLOBAL variable'

--Error ER_WRONG_VALUE_FOR_VAR
SET @@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size='32';
--echo Expected error 'Variable cannot be set to this value';

SET @@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size='0';
select @@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size;
--echo 0 Expected

--Error ER_WRONG_VALUE_FOR_VAR
SET @@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size='ms32';
--echo Expected error 'Variable cannot be set to this value';

--Error ER_WRONG_VALUE_FOR_VAR
SET @@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size='32ps';
--echo Expected error 'Variable cannot be set to this value';

--Error ER_WRONG_VALUE_FOR_VAR
SET @@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size='3s2';
--echo Expected error 'Variable cannot be set to this value';

--Error ER_WRONG_VALUE_FOR_VAR
SET @@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size='32@s';
--echo Expected error 'Variable cannot be set to this value';

--Error ER_WRONG_VALUE_FOR_VAR
SET @@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size='32s.';
--echo Expected error 'Variable cannot be set to this value';

--Error ER_WRONG_VALUE_FOR_VAR
SET @@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size='s';
--echo Expected error 'Variable cannot be set to this value'

SET @@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size='16.5us';
select @@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size;
--echo 16.5us Expected

SET @@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size = @start_global_value;
SELECT @@GLOBAL.rpl_semi_sync_master_histogram_trx_wait_step_size;
--echo 16ms Expected
22 changes: 22 additions & 0 deletions plugin/semisync/semisync_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ unsigned long long rpl_semi_sync_source_net_wait_time = 0;
unsigned long long rpl_semi_sync_source_trx_wait_time = 0;
bool rpl_semi_sync_source_wait_no_replica = true;
unsigned int rpl_semi_sync_source_wait_for_replica_count = 1;
char *histogram_trx_wait_step_size = 0;
latency_histogram histogram_trx_wait;
SHOW_VAR latency_histogram_trx_wait[NUMBER_OF_HISTOGRAM_BINS + 1];
ulonglong histogram_trx_wait_values[NUMBER_OF_HISTOGRAM_BINS];

static int getWaitTime(const struct timespec &start_ts);

Expand Down Expand Up @@ -439,6 +443,7 @@ int ReplSemiSyncMaster::initObject() {
else
result = disableMaster();

latency_histogram_init(&histogram_trx_wait, histogram_trx_wait_step_size);
return result;
}

Expand Down Expand Up @@ -509,6 +514,7 @@ int ReplSemiSyncMaster::disableMaster() {
}

ReplSemiSyncMaster::~ReplSemiSyncMaster() {
free_latency_histogram_sysvars(latency_histogram_trx_wait);
if (init_done_) {
mysql_mutex_destroy(&LOCK_binlog_);
}
Expand Down Expand Up @@ -832,6 +838,10 @@ int ReplSemiSyncMaster::commitTrx(const char *trx_wait_binlog_name,
} else {
rpl_semi_sync_source_trx_wait_num++;
rpl_semi_sync_source_trx_wait_time += wait_time;
if (histogram_trx_wait_step_size)
latency_histogram_increment(
&histogram_trx_wait,
microseconds_to_my_timer((double)wait_time), 1);
}
}
}
Expand Down Expand Up @@ -1215,6 +1225,11 @@ int ReplSemiSyncMaster::setWaitSlaveCount(unsigned int new_value) {
reportReplyBinlog(ackinfo->binlog_name, ackinfo->binlog_pos);
}

for (size_t i_bins = 0; i_bins < NUMBER_OF_HISTOGRAM_BINS; ++i_bins) {
histogram_trx_wait_values[i_bins] =
latency_histogram_get_count(&histogram_trx_wait, i_bins);
}

unlock();
return function_exit(kWho, result);
}
Expand Down Expand Up @@ -1321,3 +1336,10 @@ static int getWaitTime(const struct timespec &start_ts) {

return (int)(end_usecs - start_usecs);
}

void ReplSemiSyncMaster::update_histogram_trx_wait_step_size(
const char *step_size) {
lock();
latency_histogram_init(&histogram_trx_wait, step_size);
unlock();
}
15 changes: 15 additions & 0 deletions plugin/semisync/semisync_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "my_io.h"
#include "my_psi_config.h"
#include "plugin/semisync/semisync.h"
#include "sql/mysqld.h"

extern PSI_memory_key key_ss_memory_TranxNodeAllocator_block;

Expand Down Expand Up @@ -833,6 +834,14 @@ class ReplSemiSyncMaster : public ReplSemiSyncBase {
}
unlock();
}

/* Reinitializes the latency histogram when trx_wait_step_size
* is updated.
*
* Input:
* step_size - (IN) updated step_size
*/
void update_histogram_trx_wait_step_size(const char *step_size);
};

/* System and status variables for the master component */
Expand All @@ -856,6 +865,12 @@ extern unsigned long long rpl_semi_sync_source_trx_wait_num;
extern unsigned long long rpl_semi_sync_source_net_wait_time;
extern unsigned long long rpl_semi_sync_source_trx_wait_time;

extern char *histogram_trx_wait_step_size;
extern latency_histogram histogram_trx_wait;
/* status variables for trx_wait_time histogram */
extern SHOW_VAR latency_histogram_trx_wait[NUMBER_OF_HISTOGRAM_BINS + 1];
extern ulonglong histogram_trx_wait_values[NUMBER_OF_HISTOGRAM_BINS];

/*
This indicates whether we should keep waiting if no semi-sync slave
is available.
Expand Down
Loading

0 comments on commit 19345e3

Please sign in to comment.