summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/wsrep.h78
-rw-r--r--sql/backup.cc4
-rw-r--r--sql/event_data_objects.cc1
-rw-r--r--sql/events.cc1
-rw-r--r--sql/item_func.cc3
-rw-r--r--sql/item_strfunc.cc2
-rw-r--r--sql/lock.cc3
-rw-r--r--sql/log.h1
-rw-r--r--sql/log_event.cc3
-rw-r--r--sql/mdl.cc3
-rw-r--r--sql/mysqld.cc1
-rw-r--r--sql/sp_head.cc1
-rw-r--r--sql/sql_acl.cc1
-rw-r--r--sql/sql_cache.cc3
-rw-r--r--sql/sql_class.cc1
-rw-r--r--sql/sql_class.h8
-rw-r--r--sql/sql_lex.cc3
-rw-r--r--sql/sql_partition_admin.cc1
-rw-r--r--sql/sql_plugin.cc1
-rw-r--r--sql/sql_reload.cc3
-rw-r--r--sql/sql_rename.cc3
-rw-r--r--sql/sql_sequence.cc3
-rw-r--r--sql/sql_table.cc1
-rw-r--r--sql/sql_trigger.cc1
-rw-r--r--sql/sys_vars.cc3
-rw-r--r--sql/wsrep_binlog.cc2
-rw-r--r--sql/wsrep_check_opts.cc1
-rw-r--r--sql/wsrep_client_service.cc4
-rw-r--r--sql/wsrep_high_priority_service.cc1
-rw-r--r--sql/wsrep_mysqld.h124
-rw-r--r--sql/wsrep_on.h63
-rw-r--r--sql/wsrep_priv.h10
-rw-r--r--sql/wsrep_schema.cc1
-rw-r--r--sql/wsrep_sst.cc2
-rw-r--r--sql/wsrep_thd.cc1
-rw-r--r--sql/wsrep_var.cc1
-rw-r--r--storage/innobase/dict/dict0stats_bg.cc1
-rw-r--r--storage/innobase/handler/ha_innodb.h3
-rw-r--r--storage/innobase/row/row0ins.cc3
-rw-r--r--storage/innobase/row/row0mysql.cc6
40 files changed, 207 insertions, 149 deletions
diff --git a/include/wsrep.h b/include/wsrep.h
index 9150cd04b33..e4535deabfe 100644
--- a/include/wsrep.h
+++ b/include/wsrep.h
@@ -17,47 +17,46 @@
#define WSREP_INCLUDED
#include <my_config.h>
+#include "log.h"
#ifdef WITH_WSREP
-
#define IF_WSREP(A,B) A
-
#define DBUG_ASSERT_IF_WSREP(A) DBUG_ASSERT(A)
-#define WSREP_MYSQL_DB (char *)"mysql"
-
-#define WSREP_TO_ISOLATION_BEGIN(db_, table_, table_list_) \
- if (WSREP_ON && WSREP(thd) && wsrep_to_isolation_begin(thd, db_, table_, table_list_)) \
- goto wsrep_error_label;
-
-#define WSREP_TO_ISOLATION_BEGIN_CREATE(db_, table_, table_list_, create_info_) \
- if (WSREP_ON && WSREP(thd) && \
- wsrep_to_isolation_begin(thd, db_, table_, \
- table_list_, nullptr, nullptr, create_info_))\
- goto wsrep_error_label;
-
-#define WSREP_TO_ISOLATION_BEGIN_ALTER(db_, table_, table_list_, alter_info_, fk_tables_, create_info_) \
- if (WSREP(thd) && wsrep_thd_is_local(thd) && \
- wsrep_to_isolation_begin(thd, db_, table_, \
- table_list_, alter_info_, \
- fk_tables_, create_info_))
-
-#define WSREP_TO_ISOLATION_END \
- if ((WSREP(thd) && wsrep_thd_is_local_toi(thd)) || \
- wsrep_thd_is_in_rsu(thd)) \
- wsrep_to_isolation_end(thd);
-
-/*
- Checks if lex->no_write_to_binlog is set for statements that use LOCAL or
- NO_WRITE_TO_BINLOG.
-*/
-#define WSREP_TO_ISOLATION_BEGIN_WRTCHK(db_, table_, table_list_) \
- if (WSREP(thd) && !thd->lex->no_write_to_binlog \
- && wsrep_to_isolation_begin(thd, db_, table_, table_list_)) goto wsrep_error_label;
+extern ulong wsrep_debug; // wsrep_mysqld.cc
+extern void WSREP_LOG(void (*fun)(const char* fmt, ...), const char* fmt, ...);
+
+#define WSREP_DEBUG(...) \
+ if (wsrep_debug) WSREP_LOG(sql_print_information, ##__VA_ARGS__)
+#define WSREP_INFO(...) WSREP_LOG(sql_print_information, ##__VA_ARGS__)
+#define WSREP_WARN(...) WSREP_LOG(sql_print_warning, ##__VA_ARGS__)
+#define WSREP_ERROR(...) WSREP_LOG(sql_print_error, ##__VA_ARGS__)
+#define WSREP_UNKNOWN(fmt, ...) WSREP_ERROR("UNKNOWN: " fmt, ##__VA_ARGS__)
+
+#define WSREP_LOG_CONFLICT_THD(thd, role) \
+ WSREP_INFO("%s: \n " \
+ " THD: %lu, mode: %s, state: %s, conflict: %s, seqno: %lld\n " \
+ " SQL: %s", \
+ role, \
+ thd_get_thread_id(thd), \
+ wsrep_thd_client_mode_str(thd), \
+ wsrep_thd_client_state_str(thd), \
+ wsrep_thd_transaction_state_str(thd), \
+ wsrep_thd_trx_seqno(thd), \
+ wsrep_thd_query(thd) \
+ );
+
+#define WSREP_LOG_CONFLICT(bf_thd, victim_thd, bf_abort) \
+ if (wsrep_debug || wsrep_log_conflicts) \
+ { \
+ WSREP_INFO("cluster conflict due to %s for threads:", \
+ (bf_abort) ? "high priority abort" : "certification failure" \
+ ); \
+ if (bf_thd) WSREP_LOG_CONFLICT_THD(bf_thd, "Winning thread"); \
+ if (victim_thd) WSREP_LOG_CONFLICT_THD(victim_thd, "Victim thread"); \
+ WSREP_INFO("context: %s:%d", __FILE__, __LINE__); \
+ }
-#define WSREP_SYNC_WAIT(thd_, before_) \
- { if (WSREP_CLIENT(thd_) && \
- wsrep_sync_wait(thd_, before_)) goto wsrep_error_label; }
#else /* !WITH_WSREP */
@@ -65,14 +64,11 @@
* (e.g. embedded) */
#define IF_WSREP(A,B) B
+//#define DBUG_ASSERT_IF_WSREP(A)
#define WSREP_DEBUG(...)
+//#define WSREP_INFO(...)
+//#define WSREP_WARN(...)
#define WSREP_ERROR(...)
-#define WSREP_TO_ISOLATION_BEGIN(db_, table_, table_list_) do { } while(0)
-#define WSREP_TO_ISOLATION_BEGIN_ALTER(db_, table_, table_list_, alter_info_, fk_tables_, create_info_)
-#define WSREP_TO_ISOLATION_END
-#define WSREP_TO_ISOLATION_BEGIN_CREATE(db_, table_, table_list_, create_info_)
-#define WSREP_TO_ISOLATION_BEGIN_WRTCHK(db_, table_, table_list_)
-#define WSREP_SYNC_WAIT(thd_, before_)
#endif /* WITH_WSREP */
#endif /* WSREP_INCLUDED */
diff --git a/sql/backup.cc b/sql/backup.cc
index c856048b49a..b015b2de4a1 100644
--- a/sql/backup.cc
+++ b/sql/backup.cc
@@ -34,7 +34,9 @@
#include "sql_insert.h" // kill_delayed_threads
#include "sql_handler.h" // mysql_ha_cleanup_no_free
#include <my_sys.h>
-#include "wsrep_mysqld.h"
+#ifdef WITH_WSREP
+#include "wsrep_server_state.h"
+#endif /* WITH_WSREP */
static const char *stage_names[]=
{"START", "FLUSH", "BLOCK_DDL", "BLOCK_COMMIT", "END", 0};
diff --git a/sql/event_data_objects.cc b/sql/event_data_objects.cc
index a5e2326127c..1e406e9143f 100644
--- a/sql/event_data_objects.cc
+++ b/sql/event_data_objects.cc
@@ -32,6 +32,7 @@
#include "sp_head.h"
#include "sql_show.h" // append_definer, append_identifier
#include "mysql/psi/mysql_sp.h"
+#include "wsrep_mysqld.h"
#ifdef WITH_WSREP
#include "wsrep_trans_observer.h"
#endif /* WITH_WSREP */
diff --git a/sql/events.cc b/sql/events.cc
index 5f0dd3fd986..6fe0974430c 100644
--- a/sql/events.cc
+++ b/sql/events.cc
@@ -35,6 +35,7 @@
#include "set_var.h"
#include "lock.h" // lock_object_name
#include "mysql/psi/mysql_sp.h"
+#include "wsrep_mysqld.h"
/**
@addtogroup Event_Scheduler
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 1da220d7276..d07640d1120 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -55,6 +55,9 @@
#include "debug_sync.h"
#include "sql_base.h"
#include "sql_cte.h"
+#ifdef WITH_WSREP
+#include "mysql/service_wsrep.h"
+#endif /* WITH_WSREP */
#ifdef NO_EMBEDDED_ACCESS_CHECKS
#define sp_restore_security_context(A,B) while (0) {}
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index d8fb58c2db7..cffeeb7256e 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -5273,8 +5273,8 @@ String *Item_temptable_rowid::val_str(String *str)
}
#ifdef WITH_WSREP
-
#include "wsrep_mysqld.h"
+#include "wsrep_server_state.h"
/* Format is %d-%d-%llu */
#define WSREP_MAX_WSREP_SERVER_GTID_STR_LEN 10+1+10+1+20
diff --git a/sql/lock.cc b/sql/lock.cc
index ec91655375e..70b04e53583 100644
--- a/sql/lock.cc
+++ b/sql/lock.cc
@@ -79,7 +79,10 @@
#include "sql_parse.h" // is_log_table_write_query
#include "sql_handler.h"
#include <hash.h>
+#ifdef WITH_WSREP
#include "wsrep_mysqld.h"
+#include "wsrep_server_state.h"
+#endif
/**
@defgroup Locking Locking
diff --git a/sql/log.h b/sql/log.h
index e4a4d9c2fb2..e0a37c0a250 100644
--- a/sql/log.h
+++ b/sql/log.h
@@ -18,7 +18,6 @@
#define LOG_H
#include "handler.h" /* my_xid */
-#include "wsrep_mysqld.h"
#include "rpl_constants.h"
class Relay_log_info;
diff --git a/sql/log_event.cc b/sql/log_event.cc
index 092ddfb8010..4c4514bb4e2 100644
--- a/sql/log_event.cc
+++ b/sql/log_event.cc
@@ -43,6 +43,9 @@
#include <strfunc.h>
#include "compat56.h"
#include "sql_insert.h"
+#ifdef WITH_WSREP
+#include "wsrep_mysqld.h"
+#endif /* WITH_WSREP */
#else
#include "mysqld_error.h"
#endif /* MYSQL_CLIENT */
diff --git a/sql/mdl.cc b/sql/mdl.cc
index a43c7c99a05..144ce1cfedf 100644
--- a/sql/mdl.cc
+++ b/sql/mdl.cc
@@ -30,6 +30,9 @@
#include <mysql/psi/mysql_mdl.h>
#include <algorithm>
#include <array>
+#ifdef WITH_WSREP
+#include "wsrep_mysqld.h"
+#endif
static PSI_memory_key key_memory_MDL_context_acquire_locks;
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 243a3ee508a..3d1ba5bbea7 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -77,6 +77,7 @@
#ifdef WITH_WSREP
#include "wsrep_thd.h"
#include "wsrep_sst.h"
+#include "wsrep_server_state.h"
#endif /* WITH_WSREP */
#include "proxy_protocol.h"
diff --git a/sql/sp_head.cc b/sql/sp_head.cc
index 35f7c1cb2c7..e8fa8b31dcc 100644
--- a/sql/sp_head.cc
+++ b/sql/sp_head.cc
@@ -46,6 +46,7 @@
#include "sql_audit.h"
#include "debug_sync.h"
#ifdef WITH_WSREP
+#include "wsrep.h"
#include "wsrep_trans_observer.h"
#endif /* WITH_WSREP */
diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc
index c4078ab8711..8dc8da4ee90 100644
--- a/sql/sql_acl.cc
+++ b/sql/sql_acl.cc
@@ -56,6 +56,7 @@
#include "password.h"
#include "sql_plugin_compat.h"
+#include "wsrep_mysqld.h"
#define MAX_SCRAMBLE_LENGTH 1024
diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc
index 9968f2d4ff8..520fbdc0ff2 100644
--- a/sql/sql_cache.cc
+++ b/sql/sql_cache.cc
@@ -347,6 +347,9 @@ TODO list:
#include "probes_mysql.h"
#include "transaction.h"
#include "strfunc.h"
+#ifdef WITH_WSREP
+#include "wsrep_mysqld.h"
+#endif
const uchar *query_state_map;
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 5ff0a904adc..f909158702a 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -67,6 +67,7 @@
#ifdef WITH_WSREP
#include "wsrep_thd.h"
#include "wsrep_trans_observer.h"
+#include "wsrep_server_state.h"
#else
static inline bool wsrep_is_bf_aborted(THD* thd) { return false; }
#endif /* WITH_WSREP */
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 37ffd9a1e32..4b674ce77c0 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -65,7 +65,8 @@ void set_thd_stage_info(void *thd,
#include "my_apc.h"
#include "rpl_gtid.h"
-#include "wsrep_mysqld.h"
+#include "wsrep.h"
+#include "wsrep_on.h"
#ifdef WITH_WSREP
#include <inttypes.h>
/* wsrep-lib */
@@ -75,6 +76,11 @@ void set_thd_stage_info(void *thd,
#include "wsrep_condition_variable.h"
class Wsrep_applier_service;
+enum wsrep_consistency_check_mode {
+ NO_CONSISTENCY_CHECK,
+ CONSISTENCY_CHECK_DECLARED,
+ CONSISTENCY_CHECK_RUNNING,
+};
#endif /* WITH_WSREP */
class Reprepare_observer;
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index 1d160bd9a65..c3b1fa06fbf 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -37,6 +37,9 @@
#include "sql_partition.h"
#include "sql_partition_admin.h" // Sql_cmd_alter_table_*_part
#include "event_parse_data.h"
+#ifdef WITH_WSREP
+#include "mysql/service_wsrep.h"
+#endif
void LEX::parse_error(uint err_number)
{
diff --git a/sql/sql_partition_admin.cc b/sql/sql_partition_admin.cc
index 3a22c9f6201..68dd3379d64 100644
--- a/sql/sql_partition_admin.cc
+++ b/sql/sql_partition_admin.cc
@@ -32,6 +32,7 @@
#include "ha_partition.h" // ha_partition
#endif
#include "sql_base.h" // open_and_lock_tables
+#include "wsrep_mysqld.h"
#ifndef WITH_PARTITION_STORAGE_ENGINE
diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc
index db081c5c559..8c2dbc91ec2 100644
--- a/sql/sql_plugin.cc
+++ b/sql/sql_plugin.cc
@@ -40,6 +40,7 @@
#include <mysql/plugin_data_type.h>
#include <mysql/plugin_function.h>
#include "sql_plugin_compat.h"
+#include "wsrep_mysqld.h"
static PSI_memory_key key_memory_plugin_mem_root;
static PSI_memory_key key_memory_plugin_int_mem_root;
diff --git a/sql/sql_reload.cc b/sql/sql_reload.cc
index 2974c770252..cd75cd45319 100644
--- a/sql/sql_reload.cc
+++ b/sql/sql_reload.cc
@@ -32,6 +32,9 @@
#include "debug_sync.h"
#include "des_key_file.h"
#include "transaction.h"
+#ifdef WITH_WSREP
+#include "wsrep_mysqld.h"
+#endif
static void disable_checkpoints(THD *thd);
diff --git a/sql/sql_rename.cc b/sql/sql_rename.cc
index 77a1e46a75a..063645a4dce 100644
--- a/sql/sql_rename.cc
+++ b/sql/sql_rename.cc
@@ -29,7 +29,8 @@
#include "sql_trigger.h"
#include "sql_base.h" // tdc_remove_table, lock_table_names,
#include "sql_handler.h" // mysql_ha_rm_tables
-#include "sql_statistics.h"
+#include "sql_statistics.h"
+#include "wsrep_mysqld.h"
static TABLE_LIST *rename_tables(THD *thd, TABLE_LIST *table_list,
bool skip_error, bool if_exits,
diff --git a/sql/sql_sequence.cc b/sql/sql_sequence.cc
index 11b5109c349..60da595afd0 100644
--- a/sql/sql_sequence.cc
+++ b/sql/sql_sequence.cc
@@ -26,6 +26,9 @@
#include "transaction.h"
#include "lock.h"
#include "sql_acl.h"
+#ifdef WITH_WSREP
+#include "wsrep_mysqld.h"
+#endif
struct Field_definition
{
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index f6aae1af8e9..6917f24425d 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -57,6 +57,7 @@
#include "tztime.h"
#include "sql_insert.h" // binlog_drop_table
#include <algorithm>
+#include "wsrep_mysqld.h"
#ifdef __WIN__
#include <io.h>
diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc
index 59c70880baf..398cfeabfb0 100644
--- a/sql/sql_trigger.cc
+++ b/sql/sql_trigger.cc
@@ -35,6 +35,7 @@
#include <mysys_err.h>
#include "debug_sync.h"
#include "mysql/psi/mysql_sp.h"
+#include "wsrep_mysqld.h"
/*************************************************************************/
diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc
index 21178698c09..1b33314a15d 100644
--- a/sql/sys_vars.cc
+++ b/sql/sys_vars.cc
@@ -65,6 +65,9 @@
#include "semisync_master.h"
#include "semisync_slave.h"
#include <ssl_compat.h>
+#ifdef WITH_WSREP
+#include "wsrep_mysqld.h"
+#endif
#define PCRE2_STATIC 1 /* Important on Windows */
#include "pcre2.h" /* pcre2 header file */
diff --git a/sql/wsrep_binlog.cc b/sql/wsrep_binlog.cc
index bcc5d2fe46d..5e1fa137fed 100644
--- a/sql/wsrep_binlog.cc
+++ b/sql/wsrep_binlog.cc
@@ -16,11 +16,11 @@
#include "mariadb.h"
#include "mysql/service_wsrep.h"
#include "wsrep_binlog.h"
-#include "wsrep_priv.h"
#include "log.h"
#include "slave.h"
#include "log_event.h"
#include "wsrep_applier.h"
+#include "wsrep_mysqld.h"
#include "transaction.h"
diff --git a/sql/wsrep_check_opts.cc b/sql/wsrep_check_opts.cc
index e5a0dcb2ede..b17a5f164a4 100644
--- a/sql/wsrep_check_opts.cc
+++ b/sql/wsrep_check_opts.cc
@@ -19,6 +19,7 @@
#include "sys_vars_shared.h"
#include "wsrep.h"
#include "wsrep_sst.h"
+#include "wsrep_mysqld.h"
extern char *my_bind_addr_str;
diff --git a/sql/wsrep_client_service.cc b/sql/wsrep_client_service.cc
index 869234de491..5162f13458b 100644
--- a/sql/wsrep_client_service.cc
+++ b/sql/wsrep_client_service.cc
@@ -1,4 +1,4 @@
-/* Copyright 2018-2021 Codership Oy <info@codership.com>
+/* Copyright 2018-2022 Codership Oy <info@codership.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -20,6 +20,8 @@
#include "wsrep_thd.h"
#include "wsrep_xid.h"
#include "wsrep_trans_observer.h"
+#include "wsrep_server_state.h"
+#include "wsrep_mysqld.h"
#include "sql_base.h" /* close_temporary_table() */
#include "sql_class.h" /* THD */
diff --git a/sql/wsrep_high_priority_service.cc b/sql/wsrep_high_priority_service.cc
index db6ba43edec..e165a204f56 100644
--- a/sql/wsrep_high_priority_service.cc
+++ b/sql/wsrep_high_priority_service.cc
@@ -19,6 +19,7 @@
#include "wsrep_schema.h"
#include "wsrep_xid.h"
#include "wsrep_trans_observer.h"
+#include "wsrep_server_state.h"
#include "sql_class.h" /* THD */
#include "transaction.h"
diff --git a/sql/wsrep_mysqld.h b/sql/wsrep_mysqld.h
index c1f6c9fda7d..2437a823df4 100644
--- a/sql/wsrep_mysqld.h
+++ b/sql/wsrep_mysqld.h
@@ -1,5 +1,4 @@
-/* Copyright 2008-2021 Codership Oy <http://www.codership.com>
- Copyright (c) 2020, 2021, MariaDB
+/* Copyright 2008-2022 Codership Oy <http://www.codership.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -20,8 +19,6 @@
#include <wsrep.h>
#ifdef WITH_WSREP
-extern bool WSREP_ON_;
-extern bool WSREP_PROVIDER_EXISTS_;
#include <mysql/plugin.h>
#include "mysql/service_wsrep.h"
@@ -40,21 +37,12 @@ typedef struct st_mysql_show_var SHOW_VAR;
#include "wsrep/provider.hpp"
#include "wsrep/streaming_context.hpp"
#include "wsrep_api.h"
-#include <vector>
#include <map>
-#include "wsrep_server_state.h"
#define WSREP_UNDEFINED_TRX_ID ULONGLONG_MAX
-class set_var;
class THD;
-enum wsrep_consistency_check_mode {
- NO_CONSISTENCY_CHECK,
- CONSISTENCY_CHECK_DECLARED,
- CONSISTENCY_CHECK_RUNNING,
-};
-
// Global wsrep parameters
// MySQL wsrep options
@@ -81,7 +69,6 @@ extern ulong wsrep_max_ws_rows;
extern const char* wsrep_notify_cmd;
extern my_bool wsrep_certify_nonPK;
extern long int wsrep_protocol_version;
-extern ulong wsrep_forced_binlog_format;
extern my_bool wsrep_desync;
extern ulong wsrep_reject_queries;
extern my_bool wsrep_recovery;
@@ -102,7 +89,7 @@ extern ulong wsrep_running_rollbacker_threads;
extern bool wsrep_new_cluster;
extern bool wsrep_gtid_mode;
extern my_bool wsrep_strict_ddl;
-extern uint wsrep_gtid_domain_id;
+extern uint32 wsrep_gtid_domain_id;
enum enum_wsrep_reject_types {
WSREP_REJECT_NONE, /* nothing rejected */
@@ -113,7 +100,7 @@ enum enum_wsrep_reject_types {
enum enum_wsrep_OSU_method {
WSREP_OSU_TOI,
WSREP_OSU_RSU,
- WSREP_OSU_NONE
+ WSREP_OSU_NONE,
};
enum enum_wsrep_sync_wait {
@@ -222,68 +209,46 @@ extern bool wsrep_reload_ssl();
/* Other global variables */
extern wsrep_seqno_t wsrep_locked_seqno;
-#define WSREP_ON unlikely(WSREP_ON_)
-
-/* use xxxxxx_NNULL macros when thd pointer is guaranteed to be non-null to
- * avoid compiler warnings (GCC 6 and later) */
-#define WSREP_NNULL(thd) \
- (WSREP_PROVIDER_EXISTS_ && thd->variables.wsrep_on)
+/* A wrapper function for MySQL log functions. The call will prefix
+ the log message with WSREP and forward the result buffer to fun. */
+void WSREP_LOG(void (*fun)(const char* fmt, ...), const char* fmt, ...);
-#define WSREP(thd) \
- (thd && WSREP_NNULL(thd))
+#define WSREP_SYNC_WAIT(thd_, before_) \
+ { if (WSREP_CLIENT(thd_) && \
+ wsrep_sync_wait(thd_, before_)) goto wsrep_error_label; }
-#define WSREP_CLIENT_NNULL(thd) \
- (WSREP_NNULL(thd) && thd->wsrep_client_thread)
+#define WSREP_MYSQL_DB (char *)"mysql"
-#define WSREP_CLIENT(thd) \
- (WSREP(thd) && thd->wsrep_client_thread)
+#define WSREP_TO_ISOLATION_BEGIN(db_, table_, table_list_) \
+ if (WSREP_ON && WSREP(thd) && wsrep_to_isolation_begin(thd, db_, table_, table_list_)) \
+ goto wsrep_error_label;
-#define WSREP_EMULATE_BINLOG_NNULL(thd) \
- (WSREP_NNULL(thd) && wsrep_emulate_bin_log)
+#define WSREP_TO_ISOLATION_BEGIN_CREATE(db_, table_, table_list_, create_info_) \
+ if (WSREP_ON && WSREP(thd) && \
+ wsrep_to_isolation_begin(thd, db_, table_, \
+ table_list_, nullptr, nullptr, create_info_))\
+ goto wsrep_error_label;
-#define WSREP_EMULATE_BINLOG(thd) \
- (WSREP(thd) && wsrep_emulate_bin_log)
+#define WSREP_TO_ISOLATION_BEGIN_ALTER(db_, table_, table_list_, alter_info_, fk_tables_, create_info_) \
+ if (WSREP(thd) && wsrep_thd_is_local(thd) && \
+ wsrep_to_isolation_begin(thd, db_, table_, \
+ table_list_, alter_info_, fk_tables_, create_info_))
-#define WSREP_BINLOG_FORMAT(my_format) \
- ((wsrep_forced_binlog_format != BINLOG_FORMAT_UNSPEC) ? \
- wsrep_forced_binlog_format : my_format)
+#define WSREP_TO_ISOLATION_END \
+ if ((WSREP(thd) && wsrep_thd_is_local_toi(thd)) || \
+ wsrep_thd_is_in_rsu(thd)) \
+ wsrep_to_isolation_end(thd);
-/* A wrapper function for MySQL log functions. The call will prefix
- the log message with WSREP and forward the result buffer to fun. */
-void WSREP_LOG(void (*fun)(const char* fmt, ...), const char* fmt, ...);
+/*
+ Checks if lex->no_write_to_binlog is set for statements that use LOCAL or
+ NO_WRITE_TO_BINLOG.
+*/
+#define WSREP_TO_ISOLATION_BEGIN_WRTCHK(db_, table_, table_list_) \
+ if (WSREP(thd) && !thd->lex->no_write_to_binlog \
+ && wsrep_to_isolation_begin(thd, db_, table_, table_list_)) \
+ goto wsrep_error_label;
-#define WSREP_DEBUG(...) \
- if (wsrep_debug) sql_print_information( "WSREP: " __VA_ARGS__)
-#define WSREP_INFO(...) sql_print_information( "WSREP: " __VA_ARGS__)
-#define WSREP_WARN(...) sql_print_warning( "WSREP: " __VA_ARGS__)
-#define WSREP_ERROR(...) sql_print_error( "WSREP: " __VA_ARGS__)
-#define WSREP_UNKNOWN(fmt, ...) WSREP_ERROR("UNKNOWN: " fmt, ##__VA_ARGS__)
-
-#define WSREP_LOG_CONFLICT_THD(thd, role) \
- WSREP_INFO( \
- "%s: \n " \
- " THD: %lu, mode: %s, state: %s, conflict: %s, seqno: %lld\n " \
- " SQL: %s", \
- role, \
- thd_get_thread_id(thd), \
- wsrep_thd_client_mode_str(thd), \
- wsrep_thd_client_state_str(thd), \
- wsrep_thd_transaction_state_str(thd), \
- wsrep_thd_trx_seqno(thd), \
- wsrep_thd_query(thd) \
- );
-
-#define WSREP_LOG_CONFLICT(bf_thd, victim_thd, bf_abort) \
- if (wsrep_debug || wsrep_log_conflicts) \
- { \
- WSREP_INFO("cluster conflict due to %s for threads:", \
- (bf_abort) ? "high priority abort" : "certification failure" \
- ); \
- if (bf_thd) WSREP_LOG_CONFLICT_THD(bf_thd, "Winning thread"); \
- if (victim_thd) WSREP_LOG_CONFLICT_THD(victim_thd, "Victim thread"); \
- WSREP_INFO("context: %s:%d", __FILE__, __LINE__); \
- }
#define WSREP_PROVIDER_EXISTS (WSREP_PROVIDER_EXISTS_)
@@ -297,9 +262,6 @@ static inline bool wsrep_cluster_address_exists()
extern my_bool wsrep_ready_get();
extern void wsrep_ready_wait();
-class Ha_trx_info;
-struct THD_TRANS;
-
extern mysql_mutex_t LOCK_wsrep_ready;
extern mysql_cond_t COND_wsrep_ready;
extern mysql_mutex_t LOCK_wsrep_sst;
@@ -323,8 +285,10 @@ extern mysql_mutex_t LOCK_wsrep_donor_monitor;
extern mysql_cond_t COND_wsrep_joiner_monitor;
extern mysql_cond_t COND_wsrep_donor_monitor;
-extern my_bool wsrep_emulate_bin_log;
extern int wsrep_to_isolation;
+#ifdef GTID_SUPPORT
+extern rpl_sidno wsrep_sidno;
+#endif /* GTID_SUPPORT */
extern my_bool wsrep_preordered_opt;
#ifdef HAVE_PSI_INTERFACE
@@ -368,8 +332,6 @@ extern PSI_thread_key key_wsrep_sst_donor_monitor;
struct TABLE_LIST;
class Alter_info;
-struct HA_CREATE_INFO;
-
int wsrep_to_isolation_begin(THD *thd, const char *db_, const char *table_,
const TABLE_LIST* table_list,
const Alter_info* alter_info= nullptr,
@@ -623,12 +585,6 @@ wsrep::key wsrep_prepare_key_for_toi(const char* db, const char* table,
/* These macros are needed to compile MariaDB without WSREP support
* (e.g. embedded) */
-#define WSREP_ON false
-#define WSREP(T) (0)
-#define WSREP_NNULL(T) (0)
-#define WSREP_EMULATE_BINLOG(thd) (0)
-#define WSREP_EMULATE_BINLOG_NNULL(thd) (0)
-#define WSREP_BINLOG_FORMAT(my_format) ((ulong)my_format)
#define WSREP_PROVIDER_EXISTS (0)
#define wsrep_emulate_bin_log (0)
#define wsrep_to_isolation (0)
@@ -641,6 +597,12 @@ wsrep::key wsrep_prepare_key_for_toi(const char* db, const char* table,
#define wsrep_create_appliers(X) do {} while(0)
#define wsrep_should_replicate_ddl(X,Y) (1)
#define wsrep_cluster_address_exists() (false)
+#define WSREP_MYSQL_DB (0)
+#define WSREP_TO_ISOLATION_BEGIN(db_, table_, table_list_) do { } while(0)
+#define WSREP_TO_ISOLATION_BEGIN_ALTER(db_, table_, table_list_, alter_info_, fk_tables_)
+#define WSREP_TO_ISOLATION_END
+#define WSREP_TO_ISOLATION_BEGIN_WRTCHK(db_, table_, table_list_)
+#define WSREP_SYNC_WAIT(thd_, before_)
#endif /* WITH_WSREP */
diff --git a/sql/wsrep_on.h b/sql/wsrep_on.h
new file mode 100644
index 00000000000..f85fe3d5d0d
--- /dev/null
+++ b/sql/wsrep_on.h
@@ -0,0 +1,63 @@
+/* Copyright 2022 Codership Oy <http://www.codership.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; version 2 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */
+
+#ifndef WSREP_ON_H
+#define WSREP_ON_H
+
+#ifdef WITH_WSREP
+
+extern bool WSREP_ON_;
+extern bool WSREP_PROVIDER_EXISTS_;
+extern my_bool wsrep_emulate_bin_log;
+extern ulong wsrep_forced_binlog_format;
+
+#define WSREP_ON unlikely(WSREP_ON_)
+
+/* use xxxxxx_NNULL macros when thd pointer is guaranteed to be non-null to
+ * avoid compiler warnings (GCC 6 and later) */
+
+#define WSREP_NNULL(thd) \
+ (WSREP_PROVIDER_EXISTS_ && thd->variables.wsrep_on)
+
+#define WSREP(thd) \
+ (thd && WSREP_NNULL(thd))
+
+#define WSREP_CLIENT_NNULL(thd) \
+ (WSREP_NNULL(thd) && thd->wsrep_client_thread)
+
+#define WSREP_CLIENT(thd) \
+ (WSREP(thd) && thd->wsrep_client_thread)
+
+#define WSREP_EMULATE_BINLOG_NNULL(thd) \
+ (WSREP_NNULL(thd) && wsrep_emulate_bin_log)
+
+#define WSREP_EMULATE_BINLOG(thd) \
+ (WSREP(thd) && wsrep_emulate_bin_log)
+
+#define WSREP_BINLOG_FORMAT(my_format) \
+ ((wsrep_forced_binlog_format != BINLOG_FORMAT_UNSPEC) ? \
+ wsrep_forced_binlog_format : my_format)
+
+#else
+
+#define WSREP_ON false
+#define WSREP(T) (0)
+#define WSREP_NNULL(T) (0)
+#define WSREP_EMULATE_BINLOG(thd) (0)
+#define WSREP_EMULATE_BINLOG_NNULL(thd) (0)
+#define WSREP_BINLOG_FORMAT(my_format) ((ulong)my_format)
+
+#endif
+#endif
diff --git a/sql/wsrep_priv.h b/sql/wsrep_priv.h
index fb8467adc9d..e88d3c862a0 100644
--- a/sql/wsrep_priv.h
+++ b/sql/wsrep_priv.h
@@ -19,13 +19,8 @@
#ifndef WSREP_PRIV_H
#define WSREP_PRIV_H
-#include <my_global.h>
-#include "wsrep_mysqld.h"
-#include "wsrep_schema.h"
-
-#include <log.h>
-#include <pthread.h>
-#include <cstdio>
+#include "wsrep_api.h"
+#include "wsrep/server_state.hpp"
my_bool wsrep_ready_set (my_bool x);
@@ -39,7 +34,6 @@ wsrep_cb_status wsrep_sst_donate_cb (void* app_ctx,
extern wsrep_uuid_t local_uuid;
extern wsrep_seqno_t local_seqno;
-extern Wsrep_schema* wsrep_schema;
// a helper function
bool wsrep_sst_received(THD*, const wsrep_uuid_t&, wsrep_seqno_t,
diff --git a/sql/wsrep_schema.cc b/sql/wsrep_schema.cc
index 591a2f17bc2..1943136722e 100644
--- a/sql/wsrep_schema.cc
+++ b/sql/wsrep_schema.cc
@@ -30,6 +30,7 @@
#include "wsrep_high_priority_service.h"
#include "wsrep_storage_service.h"
#include "wsrep_thd.h"
+#include "wsrep_server_state.h"
#include <string>
#include <sstream>
diff --git a/sql/wsrep_sst.cc b/sql/wsrep_sst.cc
index 7d8f2c5d789..2d6e4f713c4 100644
--- a/sql/wsrep_sst.cc
+++ b/sql/wsrep_sst.cc
@@ -30,7 +30,7 @@
#include "wsrep_utils.h"
#include "wsrep_xid.h"
#include "wsrep_thd.h"
-#include "wsrep_mysqld.h"
+#include "wsrep_server_state.h"
#include <cstdio>
#include <cstdlib>
diff --git a/sql/wsrep_thd.cc b/sql/wsrep_thd.cc
index 08827cb612e..8639ca91150 100644
--- a/sql/wsrep_thd.cc
+++ b/sql/wsrep_thd.cc
@@ -18,6 +18,7 @@
#include "wsrep_trans_observer.h"
#include "wsrep_high_priority_service.h"
#include "wsrep_storage_service.h"
+#include "wsrep_server_state.h"
#include "transaction.h"
#include "rpl_rli.h"
#include "log_event.h"
diff --git a/sql/wsrep_var.cc b/sql/wsrep_var.cc
index 47dd016e66d..3cb1351d754 100644
--- a/sql/wsrep_var.cc
+++ b/sql/wsrep_var.cc
@@ -26,6 +26,7 @@
#include <cstdio>
#include <cstdlib>
#include "wsrep_trans_observer.h"
+#include "wsrep_server_state.h"
ulong wsrep_reject_queries;
diff --git a/storage/innobase/dict/dict0stats_bg.cc b/storage/innobase/dict/dict0stats_bg.cc
index 638ffc55382..280c5c1dec8 100644
--- a/storage/innobase/dict/dict0stats_bg.cc
+++ b/storage/innobase/dict/dict0stats_bg.cc
@@ -36,7 +36,6 @@ Created Apr 25, 2012 Vasil Dimov
# include "mysql/service_wsrep.h"
# include "wsrep.h"
# include "log.h"
-# include "wsrep_mysqld.h"
#endif
#include <vector>
diff --git a/storage/innobase/handler/ha_innodb.h b/storage/innobase/handler/ha_innodb.h
index 948d231f6a6..b97bbd982e5 100644
--- a/storage/innobase/handler/ha_innodb.h
+++ b/storage/innobase/handler/ha_innodb.h
@@ -574,9 +574,6 @@ bool thd_is_strict_mode(const MYSQL_THD thd);
extern void mysql_bin_log_commit_pos(THD *thd, ulonglong *out_pos, const char **out_file);
struct trx_t;
-#ifdef WITH_WSREP
-#include <mysql/service_wsrep.h>
-#endif /* WITH_WSREP */
extern const struct _ft_vft ft_vft_result;
diff --git a/storage/innobase/row/row0ins.cc b/storage/innobase/row/row0ins.cc
index 8f2f26be5cf..46fcb5d6ef7 100644
--- a/storage/innobase/row/row0ins.cc
+++ b/storage/innobase/row/row0ins.cc
@@ -45,7 +45,8 @@ Created 4/20/1996 Heikki Tuuri
#include "fts0fts.h"
#include "fts0types.h"
#ifdef WITH_WSREP
-#include "wsrep_mysqld.h"
+#include <wsrep.h>
+#include <mysql/service_wsrep.h>
#endif /* WITH_WSREP */
/*************************************************************************
diff --git a/storage/innobase/row/row0mysql.cc b/storage/innobase/row/row0mysql.cc
index 360a5e35fa4..1c135f787f6 100644
--- a/storage/innobase/row/row0mysql.cc
+++ b/storage/innobase/row/row0mysql.cc
@@ -69,12 +69,6 @@ Created 9/17/2000 Heikki Tuuri
#include <deque>
#include <vector>
-#ifdef WITH_WSREP
-#include "mysql/service_wsrep.h"
-#include "wsrep.h"
-#include "log.h"
-#include "wsrep_mysqld.h"
-#endif
/** Provide optional 4.x backwards compatibility for 5.0 and above */
ibool row_rollback_on_timeout = FALSE;