Skip to content

Commit 0ee3e64

Browse files
committed
MDEV-8931: (server part of) session state tracking
Transaction tracker
1 parent c8948b0 commit 0ee3e64

32 files changed

+1169
-266
lines changed

include/mysql.h.pp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@
9494
SESSION_TRACK_STATE_CHANGE,
9595
SESSION_TRACK_GTIDS,
9696
SESSION_TRACK_TRANSACTION_CHARACTERISTICS,
97-
SESSION_TRACK_TRANSACTION_STATE
97+
SESSION_TRACK_TRANSACTION_STATE,
98+
SESSION_TRACK_END
9899
};
99100
my_bool my_net_init(NET *net, Vio* vio, void *thd, unsigned int my_flags);
100101
void my_net_local_init(NET *net);

include/mysql_com.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -550,9 +550,6 @@ enum enum_mysql_set_option
550550
/*
551551
Type of state change information that the server can include in the Ok
552552
packet.
553-
Note : 1) session_state_type shouldn't go past 255 (i.e. 1-byte boundary).
554-
2) Modify the definition of SESSION_TRACK_END when a new member is
555-
added.
556553
*/
557554
enum enum_session_state_type
558555
{
@@ -561,15 +558,14 @@ enum enum_session_state_type
561558
SESSION_TRACK_STATE_CHANGE, /* track session state changes */
562559
SESSION_TRACK_GTIDS,
563560
SESSION_TRACK_TRANSACTION_CHARACTERISTICS, /* Transaction chistics */
564-
SESSION_TRACK_TRANSACTION_STATE /* Transaction state */
561+
SESSION_TRACK_TRANSACTION_STATE, /* Transaction state */
562+
SESSION_TRACK_END /* must be last */
565563
};
566564

567565
#define SESSION_TRACK_BEGIN SESSION_TRACK_SYSTEM_VARIABLES
568566

569-
#define SESSION_TRACK_END SESSION_TRACK_TRANSACTION_STATE
570-
571567
#define IS_SESSION_STATE_TYPE(T) \
572-
(((int)(T) >= SESSION_TRACK_BEGIN) && ((T) <= SESSION_TRACK_END))
568+
(((int)(T) >= SESSION_TRACK_BEGIN) && ((T) < SESSION_TRACK_END))
573569

574570
#define net_new_transaction(net) ((net)->pkt_nr=0)
575571

libmysqld/lib_sql.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,8 +1172,8 @@ bool
11721172
net_send_ok(THD *thd,
11731173
uint server_status, uint statement_warn_count,
11741174
ulonglong affected_rows, ulonglong id, const char *message,
1175-
bool unused1 __attribute__((unused)),
1176-
bool unused2 __attribute__((unused)))
1175+
bool unused1,
1176+
bool unused2)
11771177
{
11781178
DBUG_ENTER("emb_net_send_ok");
11791179
MYSQL_DATA *data;

mysql-test/r/mysqld--help.result

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -904,12 +904,21 @@ The following options may be given as the first argument:
904904
--server-id=# Uniquely identifies the server instance in the community
905905
of replication partners
906906
--session-track-schema
907-
Track changes to the 'default schema'.
907+
Track changes to the default schema.
908908
(Defaults to on; use --skip-session-track-schema to disable.)
909909
--session-track-state-change
910-
Track changes to the 'session state'.
910+
Track changes to the session state.
911911
--session-track-system-variables=name
912912
Track changes in registered system variables.
913+
--session-track-transaction-info=name
914+
Track changes to the transaction attributes. OFF to
915+
disable; STATE to track just transaction state (Is there
916+
an active transaction? Does it have any data? etc.);
917+
CHARACTERISTICS to track transaction state and report all
918+
statements needed to start a transaction withthe same
919+
characteristics (isolation level, read only/read
920+
write,snapshot - but not any work done / data modified
921+
within the transaction).
913922
--show-slave-auth-info
914923
Show user and password in SHOW SLAVE HOSTS on this
915924
master.
@@ -1395,6 +1404,7 @@ server-id 1
13951404
session-track-schema TRUE
13961405
session-track-state-change FALSE
13971406
session-track-system-variables autocommit,character_set_client,character_set_connection,character_set_results,time_zone
1407+
session-track-transaction-info OFF
13981408
show-slave-auth-info FALSE
13991409
silent-startup FALSE
14001410
skip-grant-tables TRUE

mysql-test/suite/sys_vars/r/session_track_system_variables_basic.result

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ VARIABLE_NAME VARIABLE_VALUE
1717
SESSION_TRACK_SCHEMA ON
1818
SESSION_TRACK_STATE_CHANGE OFF
1919
SESSION_TRACK_SYSTEM_VARIABLES autocommit,character_set_client,character_set_connection,character_set_results,time_zone
20+
SESSION_TRACK_TRANSACTION_INFO OFF
2021
# via INFORMATION_SCHEMA.SESSION_VARIABLES
2122
SELECT * FROM INFORMATION_SCHEMA.SESSION_VARIABLES WHERE VARIABLE_NAME LIKE 'session_track%' ORDER BY VARIABLE_NAME;
2223
VARIABLE_NAME VARIABLE_VALUE
2324
SESSION_TRACK_SCHEMA ON
2425
SESSION_TRACK_STATE_CHANGE OFF
2526
SESSION_TRACK_SYSTEM_VARIABLES autocommit,character_set_client,character_set_connection,character_set_results,time_zone
27+
SESSION_TRACK_TRANSACTION_INFO OFF
2628
SET @global_saved_tmp = @@global.session_track_system_variables;
2729

2830
# Altering global variable's value

mysql-test/suite/sys_vars/r/sysvars_server_embedded.result

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3327,34 +3327,6 @@ NUMERIC_BLOCK_SIZE 1
33273327
ENUM_VALUE_LIST NULL
33283328
READ_ONLY NO
33293329
COMMAND_LINE_ARGUMENT REQUIRED
3330-
VARIABLE_NAME SESSION_TRACK_SCHEMA
3331-
SESSION_VALUE ON
3332-
GLOBAL_VALUE ON
3333-
GLOBAL_VALUE_ORIGIN COMPILE-TIME
3334-
DEFAULT_VALUE ON
3335-
VARIABLE_SCOPE SESSION
3336-
VARIABLE_TYPE BOOLEAN
3337-
VARIABLE_COMMENT Track changes to the 'default schema'.
3338-
NUMERIC_MIN_VALUE NULL
3339-
NUMERIC_MAX_VALUE NULL
3340-
NUMERIC_BLOCK_SIZE NULL
3341-
ENUM_VALUE_LIST OFF,ON
3342-
READ_ONLY NO
3343-
COMMAND_LINE_ARGUMENT OPTIONAL
3344-
VARIABLE_NAME SESSION_TRACK_STATE_CHANGE
3345-
SESSION_VALUE OFF
3346-
GLOBAL_VALUE OFF
3347-
GLOBAL_VALUE_ORIGIN COMPILE-TIME
3348-
DEFAULT_VALUE OFF
3349-
VARIABLE_SCOPE SESSION
3350-
VARIABLE_TYPE BOOLEAN
3351-
VARIABLE_COMMENT Track changes to the 'session state'.
3352-
NUMERIC_MIN_VALUE NULL
3353-
NUMERIC_MAX_VALUE NULL
3354-
NUMERIC_BLOCK_SIZE NULL
3355-
ENUM_VALUE_LIST OFF,ON
3356-
READ_ONLY NO
3357-
COMMAND_LINE_ARGUMENT OPTIONAL
33583330
VARIABLE_NAME SKIP_EXTERNAL_LOCKING
33593331
SESSION_VALUE NULL
33603332
GLOBAL_VALUE ON

mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3796,7 +3796,7 @@ GLOBAL_VALUE_ORIGIN COMPILE-TIME
37963796
DEFAULT_VALUE ON
37973797
VARIABLE_SCOPE SESSION
37983798
VARIABLE_TYPE BOOLEAN
3799-
VARIABLE_COMMENT Track changes to the 'default schema'.
3799+
VARIABLE_COMMENT Track changes to the default schema.
38003800
NUMERIC_MIN_VALUE NULL
38013801
NUMERIC_MAX_VALUE NULL
38023802
NUMERIC_BLOCK_SIZE NULL
@@ -3810,7 +3810,7 @@ GLOBAL_VALUE_ORIGIN COMPILE-TIME
38103810
DEFAULT_VALUE OFF
38113811
VARIABLE_SCOPE SESSION
38123812
VARIABLE_TYPE BOOLEAN
3813-
VARIABLE_COMMENT Track changes to the 'session state'.
3813+
VARIABLE_COMMENT Track changes to the session state.
38143814
NUMERIC_MIN_VALUE NULL
38153815
NUMERIC_MAX_VALUE NULL
38163816
NUMERIC_BLOCK_SIZE NULL
@@ -3831,6 +3831,20 @@ NUMERIC_BLOCK_SIZE NULL
38313831
ENUM_VALUE_LIST NULL
38323832
READ_ONLY NO
38333833
COMMAND_LINE_ARGUMENT REQUIRED
3834+
VARIABLE_NAME SESSION_TRACK_TRANSACTION_INFO
3835+
SESSION_VALUE OFF
3836+
GLOBAL_VALUE OFF
3837+
GLOBAL_VALUE_ORIGIN COMPILE-TIME
3838+
DEFAULT_VALUE OFF
3839+
VARIABLE_SCOPE SESSION
3840+
VARIABLE_TYPE ENUM
3841+
VARIABLE_COMMENT Track changes to the transaction attributes. OFF to disable; STATE to track just transaction state (Is there an active transaction? Does it have any data? etc.); CHARACTERISTICS to track transaction state and report all statements needed to start a transaction withthe same characteristics (isolation level, read only/read write,snapshot - but not any work done / data modified within the transaction).
3842+
NUMERIC_MIN_VALUE NULL
3843+
NUMERIC_MAX_VALUE NULL
3844+
NUMERIC_BLOCK_SIZE NULL
3845+
ENUM_VALUE_LIST OFF,STATE,CHARACTERISTICS
3846+
READ_ONLY NO
3847+
COMMAND_LINE_ARGUMENT REQUIRED
38343848
VARIABLE_NAME SKIP_EXTERNAL_LOCKING
38353849
SESSION_VALUE NULL
38363850
GLOBAL_VALUE ON

mysql-test/suite/sys_vars/t/session_track_system_variables_basic.test

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,10 @@ SELECT @@session.session_track_system_variables;
1212
--echo
1313

1414
--echo # via INFORMATION_SCHEMA.GLOBAL_VARIABLES
15-
--disable_warnings
1615
SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE VARIABLE_NAME LIKE 'session_track%' ORDER BY VARIABLE_NAME;
17-
--enable_warnings
1816

1917
--echo # via INFORMATION_SCHEMA.SESSION_VARIABLES
20-
--disable_warnings
2118
SELECT * FROM INFORMATION_SCHEMA.SESSION_VARIABLES WHERE VARIABLE_NAME LIKE 'session_track%' ORDER BY VARIABLE_NAME;
22-
--enable_warnings
2319

2420
# Save the global value to be used to restore the original value.
2521
SET @global_saved_tmp = @@global.session_track_system_variables;

sql/lock.cc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ extern HASH open_cache;
9090
static int lock_external(THD *thd, TABLE **table,uint count);
9191
static int unlock_external(THD *thd, TABLE **table,uint count);
9292

93+
9394
/* Map the return value of thr_lock to an error from errmsg.txt */
9495
static int thr_lock_errno_to_mysql[]=
9596
{ 0, ER_LOCK_ABORTED, ER_LOCK_WAIT_TIMEOUT, ER_LOCK_DEADLOCK };
@@ -243,6 +244,39 @@ void reset_lock_data(MYSQL_LOCK *sql_lock, bool unlock)
243244
}
244245

245246

247+
/**
248+
Scan array of tables for access types; update transaction tracker
249+
accordingly.
250+
251+
@param thd The current thread.
252+
@param tables An array of pointers to the tables to lock.
253+
@param count The number of tables to lock.
254+
*/
255+
256+
#ifndef EMBEDDED_LIBRARY
257+
static void track_table_access(THD *thd, TABLE **tables, size_t count)
258+
{
259+
if (thd->variables.session_track_transaction_info > TX_TRACK_NONE)
260+
{
261+
Transaction_state_tracker *tst= (Transaction_state_tracker *)
262+
thd->session_tracker.get_tracker(TRANSACTION_INFO_TRACKER);
263+
264+
while (count--)
265+
{
266+
TABLE *t= tables[count];
267+
268+
if (t)
269+
tst->add_trx_state(thd, t->reginfo.lock_type,
270+
t->file->has_transactions());
271+
}
272+
}
273+
}
274+
#else
275+
#define track_table_access(A,B,C)
276+
#endif //EMBEDDED_LIBRARY
277+
278+
279+
246280
/**
247281
Lock tables.
248282
@@ -280,6 +314,9 @@ MYSQL_LOCK *mysql_lock_tables(THD *thd, TABLE **tables, uint count, uint flags)
280314
my_free(sql_lock);
281315
sql_lock= 0;
282316
}
317+
318+
track_table_access(thd, tables, count);
319+
283320
DBUG_RETURN(sql_lock);
284321
}
285322

sql/mysqld.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5285,16 +5285,16 @@ static int init_server_components()
52855285
}
52865286
plugins_are_initialized= TRUE; /* Don't separate from init function */
52875287

5288+
#ifndef EMBEDDED_LIBRARY
52885289
{
5289-
Session_tracker session_track_system_variables_check;
5290-
if (session_track_system_variables_check.
5291-
server_boot_verify(system_charset_info))
5290+
if (Session_tracker::server_boot_verify(system_charset_info))
52925291
{
52935292
sql_print_error("The variable session_track_system_variables has "
52945293
"invalid values.");
52955294
unireg_abort(1);
52965295
}
52975296
}
5297+
#endif //EMBEDDED_LIBRARY
52985298

52995299
/* we do want to exit if there are any other unknown options */
53005300
if (remaining_argc > 1)

0 commit comments

Comments
 (0)