Skip to content

Commit 8ff0a7f

Browse files
committed
Implement DEBUG_SYNC multiple signal firing capability
One can now do: set DEBUG_SYNC='... SIGNAL s1,s2,s3...' Multiple signals can be fired, they need to be split by commas.
1 parent c115559 commit 8ff0a7f

File tree

3 files changed

+38
-14
lines changed

3 files changed

+38
-14
lines changed

mysql-test/main/debug_sync.result

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,4 +315,8 @@ SET DEBUG_SYNC= 'now WAIT_FOR s1';
315315
SHOW VARIABLES LIKE 'DEBUG_SYNC';
316316
Variable_name Value
317317
debug_sync ON - current signals: ''
318+
SET DEBUG_SYNC= 'now SIGNAL s1,s2,s5,s7';
319+
SHOW VARIABLES LIKE 'DEBUG_SYNC';
320+
Variable_name Value
321+
debug_sync ON - current signals: 's2,s7,s1,s5'
318322
SET DEBUG_SYNC= 'RESET';

mysql-test/main/debug_sync.test

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,10 +439,13 @@ SHOW VARIABLES LIKE 'DEBUG_SYNC';
439439
SET DEBUG_SYNC= 'now WAIT_FOR s1';
440440
SHOW VARIABLES LIKE 'DEBUG_SYNC';
441441

442+
SET DEBUG_SYNC= 'now SIGNAL s1,s2,s5,s7';
443+
SHOW VARIABLES LIKE 'DEBUG_SYNC';
444+
445+
442446
#
443447
# Cleanup after test case.
444-
# Otherwise signal would contain 'flushed' here,
445-
# which could confuse the next test.
448+
# Otherwise signal would confuse the next test.
446449
#
447450
SET DEBUG_SYNC= 'RESET';
448451

sql/debug_sync.cc

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ struct st_debug_sync_globals
122122
@retval false otherwise.
123123
*/
124124

125-
inline bool is_signalled(const String &signal_name)
125+
inline bool is_signalled(const char *signal_name, size_t length)
126126
{
127-
return ds_signal_set.find(signal_name.ptr(), signal_name.length());
127+
return ds_signal_set.find(signal_name, length);
128128
}
129129

130130
void clear_signal(const String &signal_name)
@@ -140,21 +140,21 @@ struct st_debug_sync_globals
140140
DBUG_VOID_RETURN;
141141
}
142142

143-
bool set_signal(const String &signal_name)
143+
bool set_signal(const char *signal_name, size_t length)
144144
{
145145
/* Need to check if the signal is already in the hash set, because
146146
Hash_set doesn't differentiate between OOM and key already in. */
147-
if (is_signalled(signal_name))
147+
if (is_signalled(signal_name, length))
148148
return FALSE;
149149
/* LEX_CSTRING and the string allocated with only one malloc. */
150150
LEX_CSTRING *s= (LEX_CSTRING *) my_malloc(PSI_NOT_INSTRUMENTED,
151-
sizeof(LEX_CSTRING) +
152-
signal_name.length() + 1, MYF(0));
151+
sizeof(LEX_CSTRING) + length + 1,
152+
MYF(0));
153153
char *str= (char *)(s + 1);
154-
memcpy(str, signal_name.ptr(), signal_name.length());
155-
str[signal_name.length()]= '\0';
154+
memcpy(str, signal_name, length);
155+
str[length]= '\0';
156156

157-
s->length= signal_name.length();
157+
s->length= length;
158158
s->str= str;
159159
if (ds_signal_set.insert(s))
160160
return TRUE;
@@ -1522,7 +1522,23 @@ static void debug_sync_execute(THD *thd, st_debug_sync_action *action)
15221522

15231523
if (action->signal.length())
15241524
{
1525-
if (debug_sync_global.set_signal(action->signal))
1525+
int offset= 0, pos;
1526+
bool error= false;
1527+
1528+
/* This loop covers all signals in the list except for the last one.
1529+
Split the signal string by commas and set a signal in the global
1530+
variable for each one. */
1531+
while (!error && (pos= action->signal.strstr(",", 1, offset)) > 0)
1532+
{
1533+
error= debug_sync_global.set_signal(action->signal.ptr() + offset,
1534+
pos - offset);
1535+
offset= pos + 1;
1536+
}
1537+
1538+
if (error ||
1539+
/* The last signal in the list. */
1540+
debug_sync_global.set_signal(action->signal.ptr() + offset,
1541+
action->signal.length() - offset))
15261542
{
15271543
/*
15281544
Error is reported by my_malloc().
@@ -1578,8 +1594,9 @@ static void debug_sync_execute(THD *thd, st_debug_sync_action *action)
15781594
The facility can become disabled when some thread cannot get
15791595
the required dynamic memory allocated.
15801596
*/
1581-
while (!debug_sync_global.is_signalled(action->wait_for) &&
1582-
!(thd->killed & KILL_HARD_BIT)&&
1597+
while (!debug_sync_global.is_signalled(action->wait_for.ptr(),
1598+
action->wait_for.length()) &&
1599+
!(thd->killed & KILL_HARD_BIT) &&
15831600
opt_debug_sync_timeout)
15841601
{
15851602
error= mysql_cond_timedwait(&debug_sync_global.ds_cond,

0 commit comments

Comments
 (0)