MySQL 8.3.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, 2023, 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 also distributed 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 included with MySQL.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License, version 2.0, for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
25
26/**
27 @file
28
29 Declarations for the Debug Sync Facility. See debug_sync.cc for details.
30*/
31
32#include <stddef.h>
33#include <sys/types.h>
34#include <string>
35
36#include "my_compiler.h"
37#include "my_inttypes.h"
38#include "my_sharedlib.h"
39#include "string_with_len.h"
40
41class THD;
42
43#if defined(ENABLED_DEBUG_SYNC)
44
45/* Macro to be put in the code at synchronization points. */
46#define DEBUG_SYNC(_thd_, _sync_point_name_) \
47 do { \
48 if (unlikely(opt_debug_sync_timeout)) \
49 debug_sync(_thd_, STRING_WITH_LEN(_sync_point_name_)); \
50 } while (0)
51
52/* Command line option --debug-sync-timeout. See mysqld.cc. */
53extern MYSQL_PLUGIN_IMPORT uint opt_debug_sync_timeout;
54
55/* Default WAIT_FOR timeout if command line option is given without argument. */
56#define DEBUG_SYNC_DEFAULT_WAIT_TIMEOUT 300
57
58/* Debug Sync prototypes. See debug_sync.cc. */
59extern int debug_sync_init(void);
60extern void debug_sync_end(void);
61extern void debug_sync_init_thread(THD *thd);
62extern void debug_sync_claim_memory_ownership(THD *thd, bool claim);
63extern void debug_sync_end_thread(THD *thd);
64extern void debug_sync(THD *thd, const char *sync_point_name, size_t name_len);
65extern bool debug_sync_set_action(THD *thd, const char *action_str, size_t len);
66extern bool debug_sync_update(THD *thd, char *val_str);
67extern uchar *debug_sync_value_ptr(THD *thd);
68extern void conditional_sync_point_for_timestamp(std::string name);
69extern void conditional_sync_point(std::string name);
70
71/**
72 This macro simplifies when a DBUG_EXECUTE_IF will generate a given
73 signal and then will wait for another signal to continue.
74*/
75#define DBUG_SIGNAL_WAIT_FOR(T, A, B, C) \
76 DBUG_EXECUTE_IF(A, { \
77 const char act[] = "now SIGNAL " B " WAIT_FOR " C; \
78 assert(!debug_sync_set_action(T, STRING_WITH_LEN(act))); \
79 };)
80
81/**
82 Set a sync point that is activated by setting
83 @@debug='d,syncpoint_NAME', and which will emit the signal
84 "reached_NAME" and wait for the signal "continue_NAME"
85
86 @param[in] NAME The name of the debug symbol. This should indicate
87 the logical point in time in the code flow where it
88 appears. Usually it should have the form "before_EVENT" or
89 "after_EVENT", where EVENT identifies something that the code
90 does. EVENT might for instance be the name of a function in the
91 source code. The sync point might be reused by multiple tests, so
92 the name should relate to what the server does and not the test
93 scenario.
94 */
95#define CONDITIONAL_SYNC_POINT(NAME) conditional_sync_point(NAME)
96
97/**
98 Set a sync point that is activated by setting
99 @@debug='d,syncpoint_NAME_TIMESTAMP', where NAME is given as an
100 argument and TIMESTAMP must match the value of @@session.timestamp
101 for the thread. When activated, the sync point will emit the
102 signal "reached_NAME_TIMESTAMP", and wait for the signal
103 "continue_NAME_TIMESTAMP".
104
105 @param[in] NAME The name of the debug symbol. This should indicate
106 the logical point in time in the code flow where it
107 appears. Usually it should have the form "before_EVENT" or
108 "after_EVENT", where EVENT identifies something that the code
109 does. EVENT might for instance be the name of a function in the
110 source code. The sync point might be reused by multiple tests, so
111 the name should relate to what the server does and not the test
112 scenario.
113
114 @param[in] TIMESTAMP The timestamp. Only threads where the session
115 variable @@session.timestamp is set to TIMESTAMP will be
116 affected. TIMESTAMP will be appended to the debug symbol, to the
117 signals that the sync point emits and waits for.
118*/
119#define CONDITIONAL_SYNC_POINT_FOR_TIMESTAMP(NAME) \
120 conditional_sync_point_for_timestamp(NAME)
121
122#else /* defined(ENABLED_DEBUG_SYNC) */
123
124#define DEBUG_SYNC(_thd_, _sync_point_name_) /* disabled DEBUG_SYNC */
125#define DBUG_SIGNAL_WAIT_FOR(T, A, B, C) \
126 do { \
127 } while (0)
128#define CONDITIONAL_SYNC_POINT(NAME)
129#define CONDITIONAL_SYNC_POINT_FOR_TIMESTAMP(NAME)
130
131#endif /* defined(ENABLED_DEBUG_SYNC) */
132
133#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:35
Header for compiler-dependent features.
Some integer typedefs for easier portability.
unsigned char uchar
Definition: my_inttypes.h:51
Functions related to handling of plugins and other dynamically loaded libraries.
#define MYSQL_PLUGIN_IMPORT
Definition: my_sharedlib.h:70
case opt name
Definition: sslopt-case.h:32