[Commits] c000ffa: Debugging patch to log row lock conflicts.

Kristian Nielsen knielsen at knielsen-hq.org
Thu Jul 2 15:33:02 EEST 2015


revision-id: c000ffafc1eb27c992f59ae19b1c4797e648d1f9
parent(s): 19c516c8cb0681dbac6265c9c5b7261ec6be35a0
committer: Kristian Nielsen
branch nick: mariadb
timestamp: 2015-07-02 14:25:12 +0200
message:

Debugging patch to log row lock conflicts.

This patch adds a --gtid-log-all-lock-conflicts option. When enabled, it
causes a line in the error log like this when one transaction needs to wait
for an InnoDB row lock of another:

2015-07-02 12:41:58 140679343929088 [Warning] Lock wait, GTID 0-1-52 waits for 0-1-51

This only works for transactions run by replication threads.

---
 sql/mysqld.cc    |  1 +
 sql/mysqld.h     |  2 ++
 sql/sql_class.cc |  7 +++++++
 sql/sys_vars.cc  | 10 ++++++++++
 4 files changed, 20 insertions(+)

diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index aa08ae1..648ce63 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -572,6 +572,7 @@ ulong opt_binlog_commit_wait_count= 0;
 ulong opt_binlog_commit_wait_usec= 0;
 ulong opt_slave_parallel_max_queued= 131072;
 my_bool opt_gtid_ignore_duplicates= FALSE;
+my_bool opt_gtid_log_all_lock_conflicts= FALSE;
 
 const double log_10[] = {
   1e000, 1e001, 1e002, 1e003, 1e004, 1e005, 1e006, 1e007, 1e008, 1e009,
diff --git a/sql/mysqld.h b/sql/mysqld.h
index 8cf3d63..b489654 100644
--- a/sql/mysqld.h
+++ b/sql/mysqld.h
@@ -215,6 +215,8 @@ extern ulong opt_slave_parallel_mode;
 extern ulong opt_binlog_commit_wait_count;
 extern ulong opt_binlog_commit_wait_usec;
 extern my_bool opt_gtid_ignore_duplicates;
+extern my_bool opt_gtid_log_all_lock_conflicts;
+
 extern ulong back_log;
 extern ulong executed_events;
 extern char language[FN_REFLEN];
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 3ce9b50..49bc65d 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -4490,6 +4490,13 @@ thd_report_wait_for(MYSQL_THD thd, MYSQL_THD other_thd)
   other_rgi= other_thd->rgi_slave;
   if (!rgi || !other_rgi)
     return;
+  if (opt_gtid_log_all_lock_conflicts)
+    sql_print_warning("Lock wait, GTID %u-%u-%llu waits for %u-%u-%llu",
+                      rgi->current_gtid.domain_id, rgi->current_gtid.server_id,
+                      (ulonglong)rgi->current_gtid.seq_no,
+                      other_rgi->current_gtid.domain_id,
+                      other_rgi->current_gtid.server_id,
+                      (ulonglong)other_rgi->current_gtid.seq_no);
   if (!rgi->is_parallel_exec)
     return;
   if (rgi->rli != other_rgi->rli)
diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc
index 7a7b9d1..c26ddb4 100644
--- a/sql/sys_vars.cc
+++ b/sql/sys_vars.cc
@@ -2025,6 +2025,16 @@ static Sys_var_mybool Sys_gtid_ignore_duplicates(
        DEFAULT(FALSE), NO_MUTEX_GUARD,
        NOT_IN_BINLOG, ON_CHECK(check_gtid_ignore_duplicates),
        ON_UPDATE(fix_gtid_ignore_duplicates));
+
+static Sys_var_mybool Sys_gtid_log_all_lock_conflicts(
+       "gtid_log_all_lock_conflicts",
+       "Debugging option. When set, an entry is logged in the error log "
+       "whenever one transaction had to wait for the row lock of another "
+       "transaction, along with the GTIDs of each transaction. Only works for "
+       "transactions executed by a slave thread.",
+       GLOBAL_VAR(opt_gtid_log_all_lock_conflicts), CMD_LINE(OPT_ARG),
+       DEFAULT(FALSE), NO_MUTEX_GUARD,
+       NOT_IN_BINLOG);
 #endif
 
 


More information about the commits mailing list