Skip to content

Commit

Permalink
Add Master_gtid_wait_{count,time,timeouts} status
Browse files Browse the repository at this point in the history
MASTER_GTID_WAIT function needs some status to evaluate its use.

master_gtid_wait_count indicates how many times the function is called.
master_gtid_wait_time indicates how much time in microseconds occurred
waiting (or timing out)
master_gtid_timeouts indicates how many time times this function timed
out rather than all successful gtids events being available.
  • Loading branch information
grooverdan committed Mar 11, 2015
1 parent d61573d commit fa5809c
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 3 deletions.
40 changes: 39 additions & 1 deletion mysql-test/suite/rpl/r/rpl_gtid_basic.result
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,15 @@ NULL
SELECT master_gtid_wait('', NULL);
master_gtid_wait('', NULL)
0
SHOW STATUS LIKE 'Master_gtid_wait_count';
Variable_name Value
Master_gtid_wait_count 1
SHOW STATUS LIKE 'Master_gtid_wait_timeouts';
Variable_name Value
Master_gtid_wait_timeouts 0
SHOW STATUS LIKE 'Master_gtid_wait_time';
Variable_name Value
Master_gtid_wait_time 0
SELECT master_gtid_wait(@pos, 0.5);
master_gtid_wait(@pos, 0.5)
-1
Expand Down Expand Up @@ -271,13 +280,43 @@ SELECT master_gtid_wait('2-1-5');
SELECT master_gtid_wait('2-1-10');
SELECT master_gtid_wait('2-1-5,1-1-4,0-1-110');
SELECT master_gtid_wait('2-1-2');
SHOW STATUS LIKE 'Master_gtid_wait_timeouts';
Variable_name Value
Master_gtid_wait_timeouts 0
SHOW STATUS LIKE 'Master_gtid_wait_count';
Variable_name Value
Master_gtid_wait_count 3
SELECT master_gtid_wait('1-1-1');
master_gtid_wait('1-1-1')
0
SHOW STATUS LIKE 'Master_gtid_wait_timeouts';
Variable_name Value
Master_gtid_wait_timeouts 0
SHOW STATUS LIKE 'Master_gtid_wait_count';
Variable_name Value
Master_gtid_wait_count 4
SELECT MASTER_GTID_WAIT_TIME <= 1000000 AS Master_gtid_wait_less_than_second;
Master_gtid_wait_less_than_second
1
SELECT master_gtid_wait('0-1-109');
SHOW STATUS LIKE 'Master_gtid_wait_timeouts';
Variable_name Value
Master_gtid_wait_timeouts 0
SHOW STATUS LIKE 'Master_gtid_wait_count';
Variable_name Value
Master_gtid_wait_count 4
SELECT master_gtid_wait('2-1-2', 0.5);
master_gtid_wait('2-1-2', 0.5)
-1
SHOW STATUS LIKE 'Master_gtid_wait_timeouts';
Variable_name Value
Master_gtid_wait_timeouts 1
SHOW STATUS LIKE 'Master_gtid_wait_count';
Variable_name Value
Master_gtid_wait_count 5
SELECT MASTER_GTID_WAIT_TIME BETWEEN 500000 AND 3000000 AS Master_gtid_wait_time_between_half_and_3_seconds;
Master_gtid_wait_time_between_half_and_3_seconds
1
KILL QUERY KILL_ID;
ERROR 70100: Query execution was interrupted
SET gtid_domain_id=2;
Expand Down Expand Up @@ -433,6 +472,5 @@ a
31
32
33
34
DROP TABLE t1;
include/rpl_end.inc
24 changes: 22 additions & 2 deletions mysql-test/suite/rpl/t/rpl_gtid_basic.test
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ eval SET @pos= '$pos';
SELECT master_gtid_wait(NULL);
# Check empty argument returns immediately.
SELECT master_gtid_wait('', NULL);
# Check this gets counted
SHOW STATUS LIKE 'Master_gtid_wait_count';
SHOW STATUS LIKE 'Master_gtid_wait_timeouts';
SHOW STATUS LIKE 'Master_gtid_wait_time';
# Let's check that we get a timeout
SELECT master_gtid_wait(@pos, 0.5);
SELECT * FROM t1 ORDER BY a;
Expand Down Expand Up @@ -276,7 +280,7 @@ SELECT master_gtid_wait('1-1-1', 0);
send SELECT master_gtid_wait('2-1-1,1-1-4,0-1-110');

--connect (s2,127.0.0.1,root,,test,$SERVER_MYPORT_2,)
# This will time out.
# This will time out. No event 0-1-1000 exists
send SELECT master_gtid_wait('0-1-1000', 0.5);

--connect (s3,127.0.0.1,root,,test,$SERVER_MYPORT_2,)
Expand Down Expand Up @@ -305,15 +309,31 @@ send SELECT master_gtid_wait('2-1-5,1-1-4,0-1-110');
send SELECT master_gtid_wait('2-1-2');

--connection server_2
# This one completes immediately.
# This one completes immediately ( < 1 ms).
SHOW STATUS LIKE 'Master_gtid_wait_timeouts';
SHOW STATUS LIKE 'Master_gtid_wait_count';
SELECT master_gtid_wait('1-1-1');
SHOW STATUS LIKE 'Master_gtid_wait_timeouts';
SHOW STATUS LIKE 'Master_gtid_wait_count';
let $wait_time = query_get_value(SHOW STATUS LIKE 'Master_gtid_wait_time', Value, 1);
--replace_result $wait_time MASTER_GTID_WAIT_TIME
eval SELECT $wait_time <= 1000000 AS Master_gtid_wait_less_than_second;


--connect (s10,127.0.0.1,root,,test,$SERVER_MYPORT_2,)
send SELECT master_gtid_wait('0-1-109');

--connection server_2
# This one should time out.
SHOW STATUS LIKE 'Master_gtid_wait_timeouts';
SHOW STATUS LIKE 'Master_gtid_wait_count';
SELECT master_gtid_wait('2-1-2', 0.5);
SHOW STATUS LIKE 'Master_gtid_wait_timeouts';
SHOW STATUS LIKE 'Master_gtid_wait_count';
# (0.5-3 seconds)
let $wait_time = query_get_value(SHOW STATUS LIKE 'Master_gtid_wait_time', Value, 1);
--replace_result $wait_time MASTER_GTID_WAIT_TIME
eval SELECT $wait_time BETWEEN 500000 AND 3000000 AS Master_gtid_wait_time_between_half_and_3_seconds;

--replace_result $kill1_id KILL_ID
eval KILL QUERY $kill1_id;
Expand Down
3 changes: 3 additions & 0 deletions sql/mysqld.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7879,6 +7879,9 @@ SHOW_VAR status_vars[]= {
{"Handler_write", (char*) offsetof(STATUS_VAR, ha_write_count), SHOW_LONG_STATUS},
{"Key", (char*) &show_default_keycache, SHOW_FUNC},
{"Last_query_cost", (char*) offsetof(STATUS_VAR, last_query_cost), SHOW_DOUBLE_STATUS},
{"Master_gtid_wait_count", (char*) offsetof(STATUS_VAR, master_gtid_wait_count), SHOW_LONGLONG_STATUS},
{"Master_gtid_wait_timeouts", (char*) offsetof(STATUS_VAR, master_gtid_wait_timeouts), SHOW_LONGLONG_STATUS},
{"Master_gtid_wait_time", (char*) offsetof(STATUS_VAR, master_gtid_wait_time), SHOW_LONGLONG_STATUS},
{"Max_used_connections", (char*) &max_used_connections, SHOW_LONG},
{"Memory_used", (char*) offsetof(STATUS_VAR, memory_used), SHOW_LONGLONG_STATUS},
{"Not_flushed_delayed_rows", (char*) &delayed_rows_in_use, SHOW_LONG_NOFLUSH},
Expand Down
13 changes: 13 additions & 0 deletions sql/rpl_gtid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1911,17 +1911,23 @@ gtid_waiting::wait_for_pos(THD *thd, String *gtid_str, longlong timeout_us)
rpl_gtid *wait_pos;
uint32 count, i;
struct timespec wait_until, *wait_until_ptr;
ulonglong before;

/* Wait for the empty position returns immediately. */
if (gtid_str->length() == 0)
{
status_var_increment(thd->status_var.master_gtid_wait_count);
return 0;
}

if (!(wait_pos= gtid_parse_string_to_list(gtid_str->ptr(), gtid_str->length(),
&count)))
{
my_error(ER_INCORRECT_GTID_STATE, MYF(0));
return 1;
}
status_var_increment(thd->status_var.master_gtid_wait_count);
before = microsecond_interval_timer();

if (timeout_us >= 0)
{
Expand All @@ -1936,6 +1942,13 @@ gtid_waiting::wait_for_pos(THD *thd, String *gtid_str, longlong timeout_us)
if ((err= wait_for_gtid(thd, &wait_pos[i], wait_until_ptr)))
break;
}
switch (err)
{
case -1:
status_var_increment(thd->status_var.master_gtid_wait_timeouts);
case 0: /* deliberate fall through */
status_var_add(thd->status_var.master_gtid_wait_time, microsecond_interval_timer() - before);
}
my_free(wait_pos);
return err;
}
Expand Down
5 changes: 5 additions & 0 deletions sql/sql_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,11 @@ typedef struct system_status_var
ulong feature_trigger; /* +1 opening a table with triggers */
ulong feature_xml; /* +1 when XPATH is used */

/* From MASTER_GTID_WAIT usage */
ulonglong master_gtid_wait_timeouts; /* # of timeouts */
ulonglong master_gtid_wait_time; /* Time in microseconds */
ulonglong master_gtid_wait_count;

ulong empty_queries;
ulong access_denied_errors;
ulong lost_connections;
Expand Down

0 comments on commit fa5809c

Please sign in to comment.