Skip to content

Commit 2917bd0

Browse files
Daniele SciasciaJan Lindström
authored andcommitted
Reduce compilation dependencies on wsrep_mysqld.h
Making changes to wsrep_mysqld.h causes large parts of server code to be recompiled. The reason is that wsrep_mysqld.h is included by sql_class.h, even tough very little of wsrep_mysqld.h is needed in sql_class.h. This commit introduces a new header file, wsrep_on.h, which is meant to be included from sql_class.h, and contains only macros and variable declarations used to determine whether wsrep is enabled. Also, header wsrep.h should only contain definitions that are also used outside of sql/. Therefore, move WSREP_TO_ISOLATION* and WSREP_SYNC_WAIT macros to wsrep_mysqld.h. Reviewed-by: Jan Lindström <jan.lindstrom@mariadb.com>
1 parent cf1a944 commit 2917bd0

40 files changed

+188
-131
lines changed

include/wsrep.h

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,44 +17,46 @@
1717
#define WSREP_INCLUDED
1818

1919
#include <my_config.h>
20+
#include "log.h"
2021

2122
#ifdef WITH_WSREP
2223
#define IF_WSREP(A,B) A
2324
#define DBUG_ASSERT_IF_WSREP(A) DBUG_ASSERT(A)
2425

25-
#define WSREP_MYSQL_DB (char *)"mysql"
26-
27-
#define WSREP_TO_ISOLATION_BEGIN(db_, table_, table_list_) \
28-
if (WSREP_ON && WSREP(thd) && wsrep_to_isolation_begin(thd, db_, table_, table_list_)) \
29-
goto wsrep_error_label;
30-
31-
#define WSREP_TO_ISOLATION_BEGIN_ALTER(db_, table_, table_list_, alter_info_, fk_tables_) \
32-
if (WSREP(thd) && wsrep_thd_is_local(thd) && \
33-
wsrep_to_isolation_begin(thd, db_, table_, \
34-
table_list_, alter_info_, fk_tables_))
35-
36-
#define WSREP_TO_ISOLATION_END \
37-
if ((WSREP(thd) && wsrep_thd_is_local_toi(thd)) || \
38-
wsrep_thd_is_in_rsu(thd)) \
39-
wsrep_to_isolation_end(thd);
40-
41-
/*
42-
Checks if lex->no_write_to_binlog is set for statements that use LOCAL or
43-
NO_WRITE_TO_BINLOG.
44-
*/
45-
#define WSREP_TO_ISOLATION_BEGIN_WRTCHK(db_, table_, table_list_) \
46-
if (WSREP(thd) && !thd->lex->no_write_to_binlog \
47-
&& wsrep_to_isolation_begin(thd, db_, table_, table_list_)) goto wsrep_error_label;
26+
extern ulong wsrep_debug; // wsrep_mysqld.cc
27+
extern void WSREP_LOG(void (*fun)(const char* fmt, ...), const char* fmt, ...);
4828

4929
#define WSREP_DEBUG(...) \
5030
if (wsrep_debug) WSREP_LOG(sql_print_information, ##__VA_ARGS__)
5131
#define WSREP_INFO(...) WSREP_LOG(sql_print_information, ##__VA_ARGS__)
5232
#define WSREP_WARN(...) WSREP_LOG(sql_print_warning, ##__VA_ARGS__)
5333
#define WSREP_ERROR(...) WSREP_LOG(sql_print_error, ##__VA_ARGS__)
34+
#define WSREP_UNKNOWN(fmt, ...) WSREP_ERROR("UNKNOWN: " fmt, ##__VA_ARGS__)
35+
36+
#define WSREP_LOG_CONFLICT_THD(thd, role) \
37+
WSREP_INFO("%s: \n " \
38+
" THD: %lu, mode: %s, state: %s, conflict: %s, seqno: %lld\n " \
39+
" SQL: %s", \
40+
role, \
41+
thd_get_thread_id(thd), \
42+
wsrep_thd_client_mode_str(thd), \
43+
wsrep_thd_client_state_str(thd), \
44+
wsrep_thd_transaction_state_str(thd), \
45+
wsrep_thd_trx_seqno(thd), \
46+
wsrep_thd_query(thd) \
47+
);
48+
49+
#define WSREP_LOG_CONFLICT(bf_thd, victim_thd, bf_abort) \
50+
if (wsrep_debug || wsrep_log_conflicts) \
51+
{ \
52+
WSREP_INFO("cluster conflict due to %s for threads:", \
53+
(bf_abort) ? "high priority abort" : "certification failure" \
54+
); \
55+
if (bf_thd) WSREP_LOG_CONFLICT_THD(bf_thd, "Winning thread"); \
56+
if (victim_thd) WSREP_LOG_CONFLICT_THD(victim_thd, "Victim thread"); \
57+
WSREP_INFO("context: %s:%d", __FILE__, __LINE__); \
58+
}
5459

55-
#define WSREP_SYNC_WAIT(thd_, before_) \
56-
{ if (WSREP_CLIENT(thd_) && \
57-
wsrep_sync_wait(thd_, before_)) goto wsrep_error_label; }
5860

5961
#else /* !WITH_WSREP */
6062

@@ -67,11 +69,6 @@
6769
//#define WSREP_INFO(...)
6870
//#define WSREP_WARN(...)
6971
#define WSREP_ERROR(...)
70-
#define WSREP_TO_ISOLATION_BEGIN(db_, table_, table_list_) do { } while(0)
71-
#define WSREP_TO_ISOLATION_BEGIN_ALTER(db_, table_, table_list_, alter_info_, fk_tables_)
72-
#define WSREP_TO_ISOLATION_END
73-
#define WSREP_TO_ISOLATION_BEGIN_WRTCHK(db_, table_, table_list_)
74-
#define WSREP_SYNC_WAIT(thd_, before_)
7572
#endif /* WITH_WSREP */
7673

7774
#endif /* WSREP_INCLUDED */

sql/backup.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
#include "sql_insert.h" // kill_delayed_threads
3535
#include "sql_handler.h" // mysql_ha_cleanup_no_free
3636
#include <my_sys.h>
37-
#include "wsrep_mysqld.h"
37+
#ifdef WITH_WSREP
38+
#include "wsrep_server_state.h"
39+
#endif /* WITH_WSREP */
3840

3941
static const char *stage_names[]=
4042
{"START", "FLUSH", "BLOCK_DDL", "BLOCK_COMMIT", "END", 0};

sql/event_data_objects.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "event_db_repository.h"
3333
#include "sp_head.h"
3434
#include "sql_show.h" // append_definer, append_identifier
35+
#include "wsrep_mysqld.h"
3536
#ifdef WITH_WSREP
3637
#include "wsrep_trans_observer.h"
3738
#endif /* WITH_WSREP */

sql/events.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "sp_head.h" // for Stored_program_creation_ctx
3535
#include "set_var.h"
3636
#include "lock.h" // lock_object_name
37+
#include "wsrep_mysqld.h"
3738

3839
/**
3940
@addtogroup Event_Scheduler

sql/item_func.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@
5555
#include "debug_sync.h"
5656
#include "sql_base.h"
5757
#include "sql_cte.h"
58+
#ifdef WITH_WSREP
59+
#include "mysql/service_wsrep.h"
60+
#endif /* WITH_WSREP */
5861

5962
#ifdef NO_EMBEDDED_ACCESS_CHECKS
6063
#define sp_restore_security_context(A,B) while (0) {}

sql/item_strfunc.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5363,8 +5363,8 @@ String *Item_temptable_rowid::val_str(String *str)
53635363
return &str_value;
53645364
}
53655365
#ifdef WITH_WSREP
5366-
53675366
#include "wsrep_mysqld.h"
5367+
#include "wsrep_server_state.h"
53685368

53695369
String *Item_func_wsrep_last_written_gtid::val_str_ascii(String *str)
53705370
{

sql/lock.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@
8080
#include "sql_acl.h" // SUPER_ACL
8181
#include "sql_handler.h"
8282
#include <hash.h>
83+
#ifdef WITH_WSREP
8384
#include "wsrep_mysqld.h"
85+
#include "wsrep_server_state.h"
86+
#endif
8487

8588
/**
8689
@defgroup Locking Locking

sql/log.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#define LOG_H
1919

2020
#include "handler.h" /* my_xid */
21-
#include "wsrep_mysqld.h"
2221
#include "rpl_constants.h"
2322

2423
class Relay_log_info;

sql/log_event.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@
4343
#include <mysql/psi/mysql_statement.h>
4444
#include <strfunc.h>
4545
#include "compat56.h"
46-
#include "wsrep_mysqld.h"
4746
#include "sql_insert.h"
47+
#ifdef WITH_WSREP
48+
#include "wsrep_mysqld.h"
49+
#endif /* WITH_WSREP */
4850
#else
4951
#include "mysqld_error.h"
5052
#endif /* MYSQL_CLIENT */

sql/mdl.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
#include <mysql/plugin.h>
2525
#include <mysql/service_thd_wait.h>
2626
#include <mysql/psi/mysql_stage.h>
27+
#ifdef WITH_WSREP
28+
#include "wsrep_mysqld.h"
29+
#endif
2730
#ifdef HAVE_PSI_INTERFACE
2831
static PSI_mutex_key key_MDL_wait_LOCK_wait_status;
2932

0 commit comments

Comments
 (0)