Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log all statements in transaction with same id, lp:897715 #1243

Merged
merged 1 commit into from
Feb 22, 2017

Conversation

ihanick
Copy link
Contributor

@ihanick ihanick commented Dec 15, 2016

https://bugs.launchpad.net/percona-server/+bug/897715
http://jenkins.percona.com/job/percona-server-5.6-param/

I have considered to use thread_id + statement start time as a uniq identifier.
Only explicit transactions are tracked.
I'm not sure if additional flag is required for log_slow_verbosity or existing one (e.g. microtime) could be used.
It could be also implemented for 5.5 in the same way.

This kind of functionality will be useful with:

  • find a transactions caused metadata lock
  • find whole transaction (including non-innodb statements at transaction start) by thread id (from processlist) or innodb transaction id (from innodb status).
  • find incorrect transactions usage (set auto_commit = 0, connection pool on application side, some application threads using transactions and some expecting auto_commit=1).

Mysql 5.7 has thd->get_transaction()->sequence_number but it always empty.

@@ -2082,6 +2082,18 @@ bool MYSQL_QUERY_LOG::write(THD *thd, ulonglong current_utime,
#if defined(ENABLED_PROFILING)
thd->profiling.print_current(&log_file);
#endif
if ((thd->variables.log_slow_verbosity & (1ULL << SLOG_V_MICROTIME))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this attached to microtime verbosity?

if (!(thd->server_status & SERVER_STATUS_IN_TRANS))
thd->trx_start_utime= 0;
if (my_b_printf(&log_file,
"# Trx_id: %s\n", buf) == (uint) -1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We end up with two trx ids, innodb one, and thread id. Probably it's better to implement the InnoDB trx id for "COMMIT", and nothing for "BEGIN" (maybe in some cases BEGIN gets InnoDB trx id - what about "WITH CONSISTENT SNAPSHOT"?)

@ihanick
Copy link
Contributor Author

ihanick commented Dec 15, 2016

http://jenkins.percona.com/job/percona-server-5.6-param/1535/

  • changed transaction id to innodb_trx_id
  • now transaction tracked after any innodb statement inside transaction until commit or rollback.

both timestamp based and Innodb_trx_id producing different numbers for base session and for consistent snapshot.

Copy link
Contributor

@laurynas-biveinis laurynas-biveinis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you provide an example of a slow query log with changed output?

@@ -2431,6 +2431,7 @@ class THD :public MDL_context_owner,
default values only if (innodb_was_used==TRUE)
*/
ulonglong innodb_trx_id;
ulonglong saved_innodb_trx_id;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming it is needed, then it probably needs some sort of initialisation/reset in THD or it looks like some of the reads will be uninitialized

@ihanick ihanick force-pushed the 5.6-ps-bug897715 branch 2 times, most recently from 8469096 to 1f53377 Compare December 16, 2016 13:53
@ihanick
Copy link
Contributor Author

ihanick commented Dec 16, 2016

http://jenkins.percona.com/job/percona-server-5.6-param/1541/

  • clear_slow_extended clears innodb_trx_id only if not running inside transaction
  • during init innodb_trx_id always cleared, because server_status= SERVER_STATUS_AUTOCOMMIT; (no SERVER_STATUS_IN_TRANS).
  • remove save_innodb_trx_id variable

Test queries:

create table t(c int) engine=innodb;
select 1;
begin;
  select 2;
  select * from t;
  select 3;
commit;
select 4;

Slow log example

# User@Host: root[root] @ localhost []  Id:     2
# Schema: test  Last_errno: 0  Killed: 0
# Query_time: 0.000131  Lock_time: 0.000000  Rows_sent: 1  Rows_examined: 0  Rows_affected: 0
# Bytes_sent: 56
# No InnoDB statistics available for this query
SET timestamp=1481896052;
select 1;
# User@Host: root[root] @ localhost []  Id:     2
# Schema: test  Last_errno: 0  Killed: 0
# Query_time: 0.000047  Lock_time: 0.000000  Rows_sent: 0  Rows_examined: 0  Rows_affected: 0
# Bytes_sent: 11
# No InnoDB statistics available for this query
SET timestamp=1481896052;
begin;
# User@Host: root[root] @ localhost []  Id:     2
# Schema: test  Last_errno: 0  Killed: 0
# Query_time: 0.000071  Lock_time: 0.000000  Rows_sent: 1  Rows_examined: 0  Rows_affected: 0
# Bytes_sent: 56
# No InnoDB statistics available for this query
SET timestamp=1481896052;
select 2;
# User@Host: root[root] @ localhost []  Id:     2
# Schema: test  Last_errno: 0  Killed: 0
# Query_time: 0.001138  Lock_time: 0.000909  Rows_sent: 0  Rows_examined: 0  Rows_affected: 0
# Bytes_sent: 57
# InnoDB_trx_id: 509
#   InnoDB_IO_r_ops: 8  InnoDB_IO_r_bytes: 131072  InnoDB_IO_r_wait: 0.000142
#   InnoDB_rec_lock_wait: 0.000000  InnoDB_queue_wait: 0.000000
#   InnoDB_pages_distinct: 22
SET timestamp=1481896052;
select * from t;
# User@Host: root[root] @ localhost []  Id:     2
# Schema: test  Last_errno: 0  Killed: 0
# Query_time: 0.000158  Lock_time: 0.000000  Rows_sent: 1  Rows_examined: 0  Rows_affected: 0
# Bytes_sent: 56
# InnoDB_trx_id: 509
# No InnoDB statistics available for this query
SET timestamp=1481896052;
select 3;
# User@Host: root[root] @ localhost []  Id:     2
# Schema: test  Last_errno: 0  Killed: 0
# Query_time: 0.000104  Lock_time: 0.000000  Rows_sent: 0  Rows_examined: 0  Rows_affected: 0
# Bytes_sent: 11
# InnoDB_trx_id: 509
# No InnoDB statistics available for this query
SET timestamp=1481896052;
commit;
# User@Host: root[root] @ localhost []  Id:     2
# Schema: test  Last_errno: 0  Killed: 0
# Query_time: 0.000684  Lock_time: 0.000000  Rows_sent: 1  Rows_examined: 0  Rows_affected: 0
# Bytes_sent: 56
# No InnoDB statistics available for this query
SET timestamp=1481896052;
select 4;
# User@Host: root[root] @ localhost []  Id:     2
# Schema: test  Last_errno: 0  Killed: 0
# Query_time: 0.000013  Lock_time: 0.000000  Rows_sent: 0  Rows_examined: 0  Rows_affected: 0
# Bytes_sent: 0
# No InnoDB statistics available for this query
SET timestamp=1481896052;

@@ -2083,7 +2083,7 @@ bool MYSQL_QUERY_LOG::write(THD *thd, ulonglong current_utime,
thd->profiling.print_current(&log_file);
#endif
if ((thd->variables.log_slow_verbosity & (1ULL << SLOG_V_INNODB))
&& thd->innodb_was_used)
&& (thd->innodb_was_used || thd->innodb_trx_id))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove thd->innodb_was_used check?

@ihanick
Copy link
Contributor Author

ihanick commented Jan 4, 2017

http://jenkins.percona.com/job/percona-server-5.6-param/1579/

  • removed redundant thd->innodb_was_use check:
    thd->innodb_trx_id is zero if not in transaction in clear_slow_extended, called from THD::init and before running command at dispatch_command.

@ihanick ihanick mentioned this pull request Jan 20, 2017
@ihanick ihanick merged commit 5c176fa into percona:5.6 Feb 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants