Skip to content

Commit 30fd84b

Browse files
PS-9148 feature: 8.4-specific DEBUG_SYNC improvements
https://perconadev.atlassian.net/browse/PS-9148 'DBUG_EXECUTE_IF()' / 'DEBUG_SYNC()' calls reworked with 'mysql_debug_keyword_service' / 'mysql_debug_sync_service' mysql service calls (added in 8.4).
1 parent fa7b216 commit 30fd84b

File tree

2 files changed

+63
-26
lines changed

2 files changed

+63
-26
lines changed

Diff for: components/masking_functions/src/component.cpp

+29-10
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
#include <boost/preprocessor/stringize.hpp>
2626

27-
#include <my_dbug.h>
2827
#include <my_inttypes.h>
2928
#include <mysqld_error.h>
3029

@@ -37,6 +36,10 @@
3736
#include <mysql/components/services/log_builtins.h>
3837
#include <mysql/components/services/mysql_command_services.h> // IWYU pragma: keep
3938
#include <mysql/components/services/mysql_current_thread_reader.h> // IWYU pragma: keep
39+
#ifndef NDEBUG
40+
#include <mysql/components/services/mysql_debug_keyword_service.h>
41+
#include <mysql/components/services/mysql_debug_sync_service.h>
42+
#endif
4043
#include <mysql/components/services/mysql_runtime_error.h>
4144
#include <mysql/components/services/mysql_string.h> // IWYU pragma: keep
4245
#include <mysql/components/services/psi_thread.h>
@@ -46,8 +49,6 @@
4649

4750
#include <mysqlpp/udf_error_reporter.hpp>
4851

49-
#include "sql/debug_sync.h" // IWYU pragma: keep
50-
5152
#include "masking_functions/command_service_tuple.hpp"
5253
#include "masking_functions/component_sys_variable_service_tuple.hpp"
5354
#include "masking_functions/default_sql_context_builder.hpp"
@@ -101,6 +102,11 @@ REQUIRES_SERVICE_PLACEHOLDER(log_builtins_string);
101102

102103
REQUIRES_SERVICE_PLACEHOLDER(mysql_runtime_error);
103104

105+
#ifndef NDEBUG
106+
REQUIRES_SERVICE_PLACEHOLDER(mysql_debug_keyword_service);
107+
REQUIRES_SERVICE_PLACEHOLDER(mysql_debug_sync_service);
108+
#endif
109+
104110
SERVICE_TYPE(log_builtins) * log_bi;
105111
SERVICE_TYPE(log_builtins_string) * log_bs;
106112

@@ -213,13 +219,20 @@ mysql_service_status_t component_init() {
213219
masking_functions::dictionary_flusher_thread_ptr>::instance() =
214220
std::move(flusher);
215221

216-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-do-while)
217-
DBUG_EXECUTE_IF("enable_masking_functions_flusher_create_sync", {
218-
MYSQL_THD extracted_thd{nullptr};
219-
mysql_service_mysql_current_thread_reader->get(&extracted_thd);
220-
assert(extracted_thd != nullptr);
221-
DEBUG_SYNC(extracted_thd, "masking_functions_after_flusher_create");
222-
});
222+
// not using 'DBUG_EXECUTE_IF()' macro from the
223+
// 'mysql/components/util/debug_execute_if.h' and 'DEBUG_SYNC()' macro
224+
// fromthe 'mysql/components/util/debug_sync.h' as they are not supposed
225+
// to be used in namespaces (including anonymous)
226+
#ifndef NDEBUG
227+
if (mysql_service_mysql_debug_keyword_service->lookup_debug_keyword(
228+
"enable_masking_functions_flusher_create_sync") != 0) {
229+
MYSQL_THD current_thd{nullptr};
230+
mysql_service_mysql_current_thread_reader->get(&current_thd);
231+
assert(current_thd != nullptr);
232+
mysql_service_mysql_debug_sync_service->debug_sync(
233+
current_thd, "masking_functions_after_flusher_create");
234+
}
235+
#endif
223236
}
224237

225238
LogComponentErr(INFORMATION_LEVEL, ER_LOG_PRINTF_MSG,
@@ -320,6 +333,12 @@ BEGIN_COMPONENT_REQUIRES(CURRENT_COMPONENT_NAME)
320333
REQUIRES_SERVICE(log_builtins_string),
321334

322335
REQUIRES_SERVICE(mysql_runtime_error),
336+
337+
#ifndef NDEBUG
338+
REQUIRES_SERVICE(mysql_debug_keyword_service),
339+
REQUIRES_SERVICE(mysql_debug_sync_service),
340+
#endif
341+
323342
END_COMPONENT_REQUIRES();
324343

325344
BEGIN_COMPONENT_METADATA(CURRENT_COMPONENT_NAME)

Diff for: components/masking_functions/src/masking_functions/dictionary_flusher_thread.cpp

+34-16
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include <thread>
2929
#include <utility>
3030

31-
#include <my_dbug.h>
3231
#include <my_sys.h>
3332
#include <my_thread.h>
3433
#include <mysqld_error.h>
@@ -40,6 +39,10 @@
4039

4140
#include <mysql/components/services/log_builtins.h>
4241
#include <mysql/components/services/mysql_current_thread_reader.h>
42+
#ifndef NDEBUG
43+
#include <mysql/components/services/mysql_debug_keyword_service.h>
44+
#include <mysql/components/services/mysql_debug_sync_service.h>
45+
#endif
4346

4447
#include <mysql/components/services/bits/my_thread_bits.h>
4548
#include <mysql/components/services/bits/psi_bits.h>
@@ -58,9 +61,11 @@
5861
#endif
5962
#include "masking_functions/static_sql_context_builder.hpp"
6063

61-
#include "sql/debug_sync.h" // IWYU pragma: keep
62-
6364
extern REQUIRES_SERVICE_PLACEHOLDER(mysql_current_thread_reader);
65+
#ifndef NDEBUG
66+
extern REQUIRES_SERVICE_PLACEHOLDER(mysql_debug_keyword_service);
67+
extern REQUIRES_SERVICE_PLACEHOLDER(mysql_debug_sync_service);
68+
#endif
6469

6570
namespace {
6671

@@ -294,25 +299,32 @@ void dictionary_flusher_thread::do_periodic_reload() {
294299
}
295300
cache = std::make_unique<term_cache>(cache_core_, sql_ctx_builder);
296301

297-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-do-while)
298-
DBUG_EXECUTE_IF("enable_masking_functions_flush_thread_sync", {
302+
// not using 'DBUG_EXECUTE_IF()' macro from the
303+
// 'mysql/components/util/debug_execute_if.h' and 'DEBUG_SYNC()' macro
304+
// fromthe 'mysql/components/util/debug_sync.h' as they are not supposed
305+
// to be used in namespaces (including anonymous)
306+
#ifndef NDEBUG
307+
if (mysql_service_mysql_debug_keyword_service->lookup_debug_keyword(
308+
"enable_masking_functions_flush_thread_sync") != 0) {
299309
const sql_context_ptr sql_ctx{sql_ctx_builder->build()};
300310
std::string wait_action{
301311
"SET debug_sync = 'masking_functions_before_cache_reload WAIT_FOR "
302312
"masking_functions_before_cache_reload_signal"};
303313
std::string signal_action{
304314
"SET debug_sync = 'masking_functions_after_cache_reload SIGNAL "
305315
"masking_functions_after_cache_reload_signal"};
306-
DBUG_EXECUTE_IF("enable_masking_functions_flush_thread_double_pass", {
316+
if (mysql_service_mysql_debug_keyword_service->lookup_debug_keyword(
317+
"enable_masking_functions_flush_thread_double_pass") != 0) {
307318
wait_action += " EXECUTE 2";
308319
signal_action += " EXECUTE 2";
309-
});
320+
}
310321
wait_action += '\'';
311322
signal_action += '\'';
312323

313324
sql_ctx->execute_dml(wait_action);
314325
sql_ctx->execute_dml(signal_action);
315-
});
326+
}
327+
#endif
316328
} catch (const std::exception &e) {
317329
failure_message.emplace(
318330
"Exception during flusher thread initialization - ");
@@ -352,10 +364,13 @@ void dictionary_flusher_thread::do_periodic_reload() {
352364
auto expires_at{std::chrono::steady_clock::now()};
353365
while (!is_terminated_lambda()) {
354366
if (std::chrono::steady_clock::now() >= expires_at) {
355-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-do-while)
356-
DBUG_EXECUTE_IF("enable_masking_functions_flush_thread_sync", {
357-
DEBUG_SYNC(extracted_thd, "masking_functions_before_cache_reload");
358-
});
367+
#ifndef NDEBUG
368+
if (mysql_service_mysql_debug_keyword_service->lookup_debug_keyword(
369+
"enable_masking_functions_flush_thread_sync") != 0) {
370+
mysql_service_mysql_debug_sync_service->debug_sync(
371+
extracted_thd, "masking_functions_before_cache_reload");
372+
}
373+
#endif
359374

360375
failure_message.reset();
361376
try {
@@ -373,10 +388,13 @@ void dictionary_flusher_thread::do_periodic_reload() {
373388
failure_message->c_str());
374389
}
375390

376-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-do-while)
377-
DBUG_EXECUTE_IF("enable_masking_functions_flush_thread_sync", {
378-
DEBUG_SYNC(extracted_thd, "masking_functions_after_cache_reload");
379-
});
391+
#ifndef NDEBUG
392+
if (mysql_service_mysql_debug_keyword_service->lookup_debug_keyword(
393+
"enable_masking_functions_flush_thread_sync") != 0) {
394+
mysql_service_mysql_debug_sync_service->debug_sync(
395+
extracted_thd, "masking_functions_after_cache_reload");
396+
}
397+
#endif
380398

381399
expires_at = std::chrono::steady_clock::now() + flush_interval_duration;
382400
} else {

0 commit comments

Comments
 (0)