MySQL 9.5.0
Source Code Documentation
debug_sync.h
Go to the documentation of this file.
1#ifndef DEBUG_SYNC_INCLUDED
2#define DEBUG_SYNC_INCLUDED
3
4/* Copyright (c) 2009, 2025, Oracle and/or its affiliates.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License, version 2.0,
8 as published by the Free Software Foundation.
9
10 This program is designed to work with certain software (including
11 but not limited to OpenSSL) that is licensed under separate terms,
12 as designated in a particular file or component or in included license
13 documentation. The authors of MySQL hereby grant you an additional
14 permission to link the program and your derivative works with the
15 separately licensed software that they have either included with
16 the program or referenced in the documentation.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License, version 2.0, for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
26
27/**
28 @file
29
30 Declarations for the Debug Sync Facility. See debug_sync.cc for details.
31*/
32
33#include <stddef.h>
34#include <sys/types.h>
35#include <string>
36
37#include "my_compiler.h"
38#include "my_inttypes.h"
39#include "my_sharedlib.h"
40#include "string_with_len.h"
41
42class THD;
43
44#if defined(ENABLED_DEBUG_SYNC)
45
46/* Macro to be put in the code at synchronization points. */
47#define DEBUG_SYNC(_thd_, _sync_point_name_) \
48 do { \
49 if (unlikely(opt_debug_sync_timeout)) \
50 debug_sync(_thd_, STRING_WITH_LEN(_sync_point_name_)); \
51 } while (0)
52
53/* Command line option --debug-sync-timeout. See mysqld.cc. */
54extern MYSQL_PLUGIN_IMPORT uint opt_debug_sync_timeout;
55
56/* Default WAIT_FOR timeout if command line option is given without argument. */
57#define DEBUG_SYNC_DEFAULT_WAIT_TIMEOUT 300
58
59/* Debug Sync prototypes. See debug_sync.cc. */
60extern int debug_sync_init(void);
61extern void debug_sync_end(void);
62extern void debug_sync_init_thread(THD *thd);
63extern void debug_sync_claim_memory_ownership(THD *thd, bool claim);
64extern void debug_sync_end_thread(THD *thd);
65extern void debug_sync(THD *thd, const char *sync_point_name, size_t name_len);
66extern bool debug_sync_set_action(THD *thd, const char *action_str, size_t len);
67extern bool debug_sync_update(THD *thd, char *val_str);
68extern uchar *debug_sync_value_ptr(THD *thd);
69extern void conditional_sync_point_for_timestamp(std::string name);
70extern void conditional_sync_point(std::string name,
71 unsigned short timeout = 0);
72
73/**
74 This macro simplifies when a DBUG_EXECUTE_IF will generate a given
75 signal and then will wait for another signal to continue.
76*/
77#define DBUG_SIGNAL_WAIT_FOR(T, A, B, C) \
78 DBUG_EXECUTE_IF(A, { \
79 const char act[] = "now SIGNAL " B " WAIT_FOR " C; \
80 assert(!debug_sync_set_action(T, STRING_WITH_LEN(act))); \
81 };)
82
83/**
84 Set a sync point that is activated by setting
85 @@debug='d,syncpoint_NAME', and which will emit the signal
86 "reached_NAME" and wait for the signal "continue_NAME"
87
88 @param[in] NAME The name of the debug symbol. This should indicate
89 the logical point in time in the code flow where it
90 appears. Usually it should have the form "before_EVENT" or
91 "after_EVENT", where EVENT identifies something that the code
92 does. EVENT might for instance be the name of a function in the
93 source code. The sync point might be reused by multiple tests, so
94 the name should relate to what the server does and not the test
95 scenario.
96 */
97#define CONDITIONAL_SYNC_POINT(NAME) conditional_sync_point(NAME)
98
99/**
100 Set a sync point that is activated by setting
101 @@debug='d,syncpoint_NAME', and which will emit the signal
102 "reached_NAME" and wait for the signal "continue_NAME"
103
104 @param[in] NAME The name of the debug symbol. This should indicate
105 the logical point in time in the code flow where it
106 appears. Usually it should have the form "before_EVENT" or
107 "after_EVENT", where EVENT identifies something that the code
108 does. EVENT might for instance be the name of a function in the
109 source code. The sync point might be reused by multiple tests, so
110 the name should relate to what the server does and not the test
111 scenario.
112
113 @param[in] TIMEOUT Timeout to use during conditional wait_for.
114*/
115#define CONDITIONAL_SYNC_POINT_TIMEOUT(NAME, TIMEOUT) \
116 conditional_sync_point(NAME, TIMEOUT)
117
118/**
119 Set a sync point that is activated by setting
120 @@debug='d,syncpoint_NAME_TIMESTAMP', where NAME is given as an
121 argument and TIMESTAMP must match the value of @@session.timestamp
122 for the thread. When activated, the sync point will emit the
123 signal "reached_NAME_TIMESTAMP", and wait for the signal
124 "continue_NAME_TIMESTAMP".
125
126 @param[in] NAME The name of the debug symbol. This should indicate
127 the logical point in time in the code flow where it
128 appears. Usually it should have the form "before_EVENT" or
129 "after_EVENT", where EVENT identifies something that the code
130 does. EVENT might for instance be the name of a function in the
131 source code. The sync point might be reused by multiple tests, so
132 the name should relate to what the server does and not the test
133 scenario.
134
135 @param[in] TIMESTAMP The timestamp. Only threads where the session
136 variable @@session.timestamp is set to TIMESTAMP will be
137 affected. TIMESTAMP will be appended to the debug symbol, to the
138 signals that the sync point emits and waits for.
139*/
140#define CONDITIONAL_SYNC_POINT_FOR_TIMESTAMP(NAME) \
141 conditional_sync_point_for_timestamp(NAME)
142
143#else /* defined(ENABLED_DEBUG_SYNC) */
144
145#define DEBUG_SYNC(_thd_, _sync_point_name_) /* disabled DEBUG_SYNC */
146#define DBUG_SIGNAL_WAIT_FOR(T, A, B, C) \
147 do { \
148 } while (0)
149#define CONDITIONAL_SYNC_POINT(NAME)
150#define CONDITIONAL_SYNC_POINT_TIMEOUT(NAME, TIMEOUT)
151#define CONDITIONAL_SYNC_POINT_FOR_TIMESTAMP(NAME)
152
153#endif /* defined(ENABLED_DEBUG_SYNC) */
154
155#endif /* DEBUG_SYNC_INCLUDED */
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
Header for compiler-dependent features.
Some integer typedefs for easier portability.
unsigned char uchar
Definition: my_inttypes.h:52
Functions related to handling of plugins and other dynamically loaded libraries.
#define MYSQL_PLUGIN_IMPORT
Definition: my_sharedlib.h:71
static bool timeout(bool(*wait_condition)())
Timeout function.
Definition: log0meb.cc:498
case opt name
Definition: sslopt-case.h:29