Skip to content

Commit 31d8915

Browse files
Francois Richardinikep
Francois Richard
authored andcommitted
FB8-128: track Semisync_ack Engine_commit time in slow query log (facebook#982) (facebook#982)
Summary: Jira issue: https://jira.percona.com/browse/FB8-128 Reference Patch: facebook@2dd16b3 Reference Pull: facebook#681 Originally Reviewed By: lth Pull Request resolved: facebook#982 Reviewed By: lloyd Differential Revision: D14421316 Pulled By: lth
1 parent 494c845 commit 31d8915

6 files changed

+44
-2
lines changed

Diff for: mysql-test/r/slow_log_engine_fields.result

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SET SESSION long_query_time = 0;
2+
CREATE TABLE t1 (A INT);
3+
INSERT INTO t1 VALUES (1),(2),(3);
4+
DROP TABLE t1;

Diff for: mysql-test/t/slow_log_engine_fields-master.opt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--slow-query-log=1 --log-slow-extra=1

Diff for: mysql-test/t/slow_log_engine_fields.test

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
SET SESSION long_query_time = 0;
2+
3+
CREATE TABLE t1 (A INT);
4+
INSERT INTO t1 VALUES (1),(2),(3);
5+
6+
--let SEARCH_FILE = $MYSQLTEST_VARDIR/mysqld.1/mysqld-slow.log
7+
8+
# Check if Semisync_ack_time is included in slow log results
9+
--let SEARCH_PATTERN= Semisync_ack_time:
10+
--source include/search_pattern_in_file.inc
11+
12+
# Check if Engine_commit_time is included in slow log results
13+
--let SEARCH_PATTERN= Engine_commit_time:
14+
--source include/search_pattern_in_file.inc
15+
16+
DROP TABLE t1;

Diff for: sql/binlog.cc

+7-1
Original file line numberDiff line numberDiff line change
@@ -9507,8 +9507,12 @@ int MYSQL_BIN_LOG::ordered_commit(THD *thd, bool all, bool skip_commit) {
95079507
DBUG_EXECUTE_IF("semi_sync_3-way_deadlock",
95089508
DEBUG_SYNC(thd, "before_process_commit_stage_queue"););
95099509

9510-
if (flush_error == 0 && sync_error == 0)
9510+
ulonglong start_time;
9511+
if (flush_error == 0 && sync_error == 0) {
9512+
start_time = my_timer_now();
95119513
sync_error = call_after_sync_hook(commit_queue);
9514+
thd->semisync_ack_time = my_timer_since(start_time);
9515+
}
95129516

95139517
/*
95149518
process_commit_stage_queue will call update_on_commit or
@@ -9525,7 +9529,9 @@ int MYSQL_BIN_LOG::ordered_commit(THD *thd, bool all, bool skip_commit) {
95259529
Gtid_set, and adding and removing intervals requires a mutex,
95269530
which would reduce performance.
95279531
*/
9532+
start_time = my_timer_now();
95289533
process_commit_stage_queue(thd, commit_queue);
9534+
thd->engine_commit_time = my_timer_since(start_time);
95299535

95309536
/**
95319537
* After commit stage

Diff for: sql/log.cc

+12-1
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ bool File_query_log::write_slow(THD *thd, ulonglong current_utime,
775775
" Sort_rows: %lu Sort_scan_count: %lu"
776776
" Created_tmp_disk_tables: %lu"
777777
" Created_tmp_tables: %lu"
778-
" Start: %s End: %s\n";
778+
" Start: %s End: %s";
779779

780780
// If the query start status is valid - i.e. the current thread's
781781
// status values should be no less than the query start status,
@@ -884,6 +884,17 @@ bool File_query_log::write_slow(THD *thd, ulonglong current_utime,
884884
end_time_buff);
885885
}
886886
if (error == (uint)-1) goto err;
887+
888+
static const char *times =
889+
" Semisync_ack_time: %s Engine_commit_time: %s\n";
890+
/* Semisync ack time and Engine commit time */
891+
sprintf(query_time_buff, "%.6f",
892+
my_timer_to_seconds(thd->semisync_ack_time));
893+
sprintf(lock_time_buff, "%.6f",
894+
my_timer_to_seconds(thd->engine_commit_time));
895+
if (my_b_printf(&log_file, times, query_time_buff, lock_time_buff) ==
896+
(uint)-1)
897+
goto err;
887898
}
888899

889900
if (thd->db().str && strcmp(thd->db().str, db)) { // Database changed

Diff for: sql/sql_class.h

+4
Original file line numberDiff line numberDiff line change
@@ -1604,6 +1604,10 @@ class THD : public MDL_context_owner,
16041604
m_lock_usec = 0;
16051605
}
16061606
void pop_lock_usec(ulonglong top) { m_lock_usec = top; }
1607+
/* record the semisync ack time */
1608+
ulonglong semisync_ack_time = 0;
1609+
/* record the engine commit time */
1610+
ulonglong engine_commit_time = 0;
16071611

16081612
/**
16091613
Type of lock to be used for all DML statements, except INSERT, in cases

0 commit comments

Comments
 (0)