Skip to content

Commit b709e6a

Browse files
MDEV-34358: Add debug status variables to verify encryption thread wait behavior
Added debug-only status variables Innodb_encryption_indefinite_waits to track encryption indefinite thread wait instead of busy-waiting when idle. The counters are incremented in rotate_thread_t::wait_for_work() and exposed via SHOW STATUS in debug builds only. Also added a debug sync point 'rotate_only_2_timed_waits' to reduce the timed wait threshold from 5 to 2 for faster testing of the indefinite wait transition.
1 parent d046032 commit b709e6a

8 files changed

Lines changed: 69 additions & 3 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
create table t1(a serial) engine=innoDB;
2+
set global innodb_encryption_threads=2;
3+
SET GLOBAL debug_dbug="+d,rotate_only_2_timed_waits";
4+
set global debug_key_management_version=10;
5+
SET GLOBAL innodb_encrypt_tables="FORCE";
6+
Indefinite waits happened
7+
drop table t1;
8+
# restart
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--innodb-tablespaces-encryption
2+
--plugin-load-add=$DEBUG_KEY_MANAGEMENT_SO
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
-- source include/have_innodb.inc
2+
-- source include/have_debug.inc
3+
if (`select count(*) = 0 from information_schema.plugins
4+
where plugin_name = 'debug_key_management' and plugin_status='active'`)
5+
{
6+
--skip Needs debug_key_management
7+
}
8+
create table t1(a serial) engine=innoDB;
9+
10+
set global innodb_encryption_threads=2;
11+
SET GLOBAL debug_dbug="+d,rotate_only_2_timed_waits";
12+
set global debug_key_management_version=10;
13+
SET GLOBAL innodb_encrypt_tables="FORCE";
14+
15+
--let $tables_count= `select count(*) + 1 + @@global.innodb_undo_tablespaces from information_schema.tables where engine = 'InnoDB'`
16+
17+
let $wait_condition= select count(*) = $tables_count from information_schema.innodb_tablespaces_encryption where current_key_version=10;
18+
--source include/wait_condition.inc
19+
20+
# Record initial indefinite wait count
21+
--let $initial_indefinite_waits= `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME='INNODB_ENCRYPTION_INDEFINITE_WAITS'`
22+
23+
sleep 20;
24+
25+
# After sleep, verify threads used indefinite waits (not busy looping)
26+
--let $final_indefinite_waits= `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME='INNODB_ENCRYPTION_INDEFINITE_WAITS'`
27+
28+
# Ensure indefinite waits increased (threads are sleeping, not busy-looping)
29+
if (`SELECT $final_indefinite_waits <= $initial_indefinite_waits`)
30+
{
31+
--echo ERROR: Encryption threads did not use indefinite waits during idle period
32+
--echo This indicates potential busy-loop behavior
33+
--die Encryption threads busy-looping detected
34+
}
35+
--echo Indefinite waits happened
36+
drop table t1;
37+
--source include/restart_mysqld.inc

mysql-test/suite/innodb/r/innodb_status_variables.result

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ WHERE variable_name LIKE 'INNODB_%'
33
AND variable_name NOT IN
44
('INNODB_ADAPTIVE_HASH_HASH_SEARCHES','INNODB_ADAPTIVE_HASH_NON_HASH_SEARCHES',
55
'INNODB_MEM_ADAPTIVE_HASH',
6-
'INNODB_BUFFERED_AIO_SUBMITTED','INNODB_BUFFER_POOL_PAGES_LATCHED');
6+
'INNODB_BUFFERED_AIO_SUBMITTED','INNODB_BUFFER_POOL_PAGES_LATCHED',
7+
'INNODB_ENCRYPTION_INDEFINITE_WAITS');
78
variable_name
89
INNODB_BACKGROUND_LOG_SYNC
910
INNODB_BUFFER_POOL_DUMP_STATUS

mysql-test/suite/innodb/t/innodb_status_variables.test

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ WHERE variable_name LIKE 'INNODB_%'
44
AND variable_name NOT IN
55
('INNODB_ADAPTIVE_HASH_HASH_SEARCHES','INNODB_ADAPTIVE_HASH_NON_HASH_SEARCHES',
66
'INNODB_MEM_ADAPTIVE_HASH',
7-
'INNODB_BUFFERED_AIO_SUBMITTED','INNODB_BUFFER_POOL_PAGES_LATCHED');
7+
'INNODB_BUFFERED_AIO_SUBMITTED','INNODB_BUFFER_POOL_PAGES_LATCHED',
8+
'INNODB_ENCRYPTION_INDEFINITE_WAITS');

storage/innobase/fil/fil0crypt.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ uint srv_fil_crypt_rotate_key_age;
6464
/** Whether the encryption plugin does key rotation */
6565
Atomic_relaxed<bool> srv_encrypt_rotate;
6666

67+
#ifdef UNIV_DEBUG
68+
/** Number of times encryption threads used indefinite wait */
69+
Atomic_counter<ulint> fil_crypt_indefinite_waits;
70+
#endif /* UNIV_DEBUG */
71+
6772
/** Condition variable for srv_n_fil_crypt_threads_started */
6873
static pthread_cond_t fil_crypt_cond;
6974

@@ -1131,8 +1136,10 @@ struct rotate_thread_t {
11311136

11321137
if (space == fil_system.space_list.end()) {
11331138
uint max_timed_waits = 5;
1139+
DBUG_EXECUTE_IF("rotate_only_2_timed_waits",
1140+
max_timed_waits = 2;);
11341141
if (timed_wait_count >= max_timed_waits) {
1135-
timed_wait_count= 0;
1142+
timed_wait_count = 0;
11361143
goto indefinite_wait;
11371144
}
11381145

@@ -1151,6 +1158,7 @@ struct rotate_thread_t {
11511158
}
11521159
} else {
11531160
indefinite_wait:
1161+
ut_d(fil_crypt_indefinite_waits++;);
11541162
my_cond_wait(&fil_crypt_threads_cond,
11551163
&fil_crypt_threads_mutex.m_mutex);
11561164
}

storage/innobase/handler/ha_innodb.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,10 @@ static SHOW_VAR innodb_status_variables[]= {
11061106
&export_vars.innodb_n_temp_blocks_decrypted, SHOW_LONGLONG},
11071107
{"encryption_num_key_requests", &export_vars.innodb_encryption_key_requests,
11081108
SHOW_LONGLONG},
1109+
#ifdef UNIV_DEBUG
1110+
{"encryption_indefinite_waits",
1111+
&fil_crypt_indefinite_waits, SHOW_SIZE_T},
1112+
#endif /* UNIV_DEBUG */
11091113

11101114
/* InnoDB bulk operations */
11111115
{"bulk_operations", &export_vars.innodb_bulk_operations, SHOW_SIZE_T},

storage/innobase/include/fil0crypt.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,11 @@ Return crypt statistics
375375
@param[out] stat Crypt statistics */
376376
void fil_crypt_total_stat(fil_crypt_stat_t *stat);
377377

378+
#ifdef UNIV_DEBUG
379+
/** Number of times encryption threads used indefinite wait */
380+
extern Atomic_counter<ulint> fil_crypt_indefinite_waits;
381+
#endif /* UNIV_DEBUG */
382+
378383
#include "fil0crypt.inl"
379384
#endif /* !UNIV_INNOCHECKSUM */
380385

0 commit comments

Comments
 (0)