Skip to content

Commit cd873c8

Browse files
committed
debug_sync: Implement NO_CLEAR_EVENT syntax
When waiting on a signal, NO_CLEAR_EVENT allows one to not clear the signal, effectively allowing other threads to wait for the same signal.
1 parent 8885225 commit cd873c8

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

mysql-test/main/debug_sync.result

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,4 +299,20 @@ disconnect con1;
299299
disconnect con2;
300300
connection default;
301301
DROP TABLE t1;
302+
#
303+
# Test NO_CLEAR_EVENT flag. The signal should still be visible after
304+
# the wait has completed succesfully.
305+
#
306+
SET DEBUG_SYNC= 'now SIGNAL s1';
307+
SHOW VARIABLES LIKE 'DEBUG_SYNC';
308+
Variable_name Value
309+
debug_sync ON - current signals: 's1'
310+
SET DEBUG_SYNC= 'now WAIT_FOR s1 NO_CLEAR_EVENT';
311+
SHOW VARIABLES LIKE 'DEBUG_SYNC';
312+
Variable_name Value
313+
debug_sync ON - current signals: 's1'
314+
SET DEBUG_SYNC= 'now WAIT_FOR s1';
315+
SHOW VARIABLES LIKE 'DEBUG_SYNC';
316+
Variable_name Value
317+
debug_sync ON - current signals: ''
302318
SET DEBUG_SYNC= 'RESET';

mysql-test/main/debug_sync.test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,17 @@ disconnect con2;
428428
connection default;
429429
DROP TABLE t1;
430430

431+
--echo #
432+
--echo # Test NO_CLEAR_EVENT flag. The signal should still be visible after
433+
--echo # the wait has completed succesfully.
434+
--echo #
435+
SET DEBUG_SYNC= 'now SIGNAL s1';
436+
SHOW VARIABLES LIKE 'DEBUG_SYNC';
437+
SET DEBUG_SYNC= 'now WAIT_FOR s1 NO_CLEAR_EVENT';
438+
SHOW VARIABLES LIKE 'DEBUG_SYNC';
439+
SET DEBUG_SYNC= 'now WAIT_FOR s1';
440+
SHOW VARIABLES LIKE 'DEBUG_SYNC';
441+
431442
#
432443
# Cleanup after test case.
433444
# Otherwise signal would contain 'flushed' here,

sql/debug_sync.cc

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ struct st_debug_sync_action
4848
String wait_for; /* signal to wait for */
4949
String sync_point; /* sync point name */
5050
bool need_sort; /* if new action, array needs sort */
51+
bool clear_event; /* do not clear signal when waited
52+
for if false. */
5153
};
5254

5355
/* Debug sync control. Referenced by THD. */
@@ -1253,6 +1255,7 @@ static bool debug_sync_eval_action(THD *thd, char *action_str, char *action_end)
12531255
/* Set default for EXECUTE and TIMEOUT options. */
12541256
action->execute= 1;
12551257
action->timeout= opt_debug_sync_timeout;
1258+
action->clear_event= true;
12561259

12571260
/* Get next token. If none follows, set action. */
12581261
if (!(ptr= debug_sync_token(&token, &token_length, ptr, action_end)))
@@ -1303,6 +1306,15 @@ static bool debug_sync_eval_action(THD *thd, char *action_str, char *action_end)
13031306
goto set_action;
13041307
}
13051308

1309+
/*
1310+
Try NO_CLEAR_EVENT.
1311+
*/
1312+
if (!my_strcasecmp(system_charset_info, token, "NO_CLEAR_EVENT")) {
1313+
action->clear_event= false;
1314+
/* Get next token. If none follows, set action. */
1315+
if (!(ptr = debug_sync_token(&token, &token_length, ptr, action_end))) goto set_action;
1316+
}
1317+
13061318
/*
13071319
Try HIT_LIMIT.
13081320
*/
@@ -1591,8 +1603,10 @@ static void debug_sync_execute(THD *thd, st_debug_sync_action *action)
15911603
}
15921604
error= 0;
15931605
}
1594-
// TODO conditional on clear-event
1595-
debug_sync_global.clear_signal(action->wait_for);
1606+
1607+
if (action->clear_event)
1608+
debug_sync_global.clear_signal(action->wait_for);
1609+
15961610
DBUG_EXECUTE("debug_sync_exec",
15971611
if (thd->killed)
15981612
DBUG_PRINT("debug_sync_exec",

0 commit comments

Comments
 (0)