mariadb/sql/wsrep_mysqld.h

624 lines
21 KiB
C
Raw Normal View History

2022-09-05 12:28:56 +02:00
/* 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
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
2019-05-11 21:19:05 +02:00
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */
2014-09-25 23:00:45 +02:00
#ifndef WSREP_MYSQLD_H
#define WSREP_MYSQLD_H
2019-01-23 12:30:00 +01:00
#include <wsrep.h>
2014-09-25 23:00:45 +02:00
#ifdef WITH_WSREP
2019-01-23 12:30:00 +01:00
#include <mysql/plugin.h>
#include "mysql/service_wsrep.h"
#include <my_global.h>
#include <my_pthread.h>
#include "log.h"
#include "mysqld.h"
typedef struct st_mysql_show_var SHOW_VAR;
#include <sql_priv.h>
#include "mdl.h"
#include "sql_table.h"
#include "wsrep_mysqld_c.h"
2019-01-23 12:30:00 +01:00
#include "wsrep/provider.hpp"
#include "wsrep/streaming_context.hpp"
#include "wsrep_api.h"
#include <map>
2019-01-23 12:30:00 +01:00
#define WSREP_UNDEFINED_TRX_ID ULONGLONG_MAX
class THD;
// Global wsrep parameters
// MySQL wsrep options
extern const char* wsrep_provider;
extern const char* wsrep_provider_options;
extern const char* wsrep_cluster_name;
extern const char* wsrep_cluster_address;
extern const char* wsrep_node_name;
extern const char* wsrep_node_address;
extern const char* wsrep_node_incoming_address;
extern const char* wsrep_data_home_dir;
extern const char* wsrep_dbug_option;
extern long wsrep_slave_threads;
extern int wsrep_slave_count_change;
extern ulong wsrep_debug;
extern my_bool wsrep_convert_LOCK_to_trx;
extern ulong wsrep_retry_autocommit;
extern my_bool wsrep_auto_increment_control;
2019-01-23 12:30:00 +01:00
extern my_bool wsrep_drupal_282555_workaround;
extern my_bool wsrep_incremental_data_collection;
extern const char* wsrep_start_position;
extern ulong wsrep_max_ws_size;
extern ulong wsrep_max_ws_rows;
extern const char* wsrep_notify_cmd;
2019-01-23 12:30:00 +01:00
extern my_bool wsrep_certify_nonPK;
extern long int wsrep_protocol_version;
extern my_bool wsrep_desync;
extern ulong wsrep_reject_queries;
2019-01-23 12:30:00 +01:00
extern my_bool wsrep_recovery;
extern my_bool wsrep_log_conflicts;
extern ulong wsrep_mysql_replication_bundle;
2019-01-23 12:30:00 +01:00
extern my_bool wsrep_load_data_splitting;
extern my_bool wsrep_restart_slave;
extern my_bool wsrep_restart_slave_activated;
extern my_bool wsrep_slave_FK_checks;
extern my_bool wsrep_slave_UK_checks;
2019-01-23 12:30:00 +01:00
extern ulong wsrep_trx_fragment_unit;
extern ulong wsrep_SR_store_type;
extern uint wsrep_ignore_apply_errors;
2014-09-28 12:41:51 +02:00
extern ulong wsrep_running_threads;
MDEV-19746: Galera test failures because of wsrep_slave_threads identification Problem was that tests select INFORMATION_SCHEMA.PROCESSLIST processes from user system user and empty state. Thus, there is not clear state for slave threads. Changes: - Added new status variables that store current amount of applier threads (wsrep_applier_thread_count) and rollbacker threads (wsrep_rollbacker_thread_count). This will make clear how many slave threads of certain type there is. - Added THD state "wsrep applier idle" when applier slave thread is waiting for work. This makes finding slave/applier threads easier. - Added force-restart option for mtr to always restart servers between tests to avoid race on start of the test - Added wait_condition_with_debug to wait until the passed statement returns true, or the operation times out. If operation times out, the additional error statement will be executed Changes to be committed: new file: mysql-test/include/force_restart.inc new file: mysql-test/include/wait_condition_with_debug.inc modified: mysql-test/mysql-test-run.pl modified: mysql-test/suite/galera/disabled.def modified: mysql-test/suite/galera/r/MW-336.result modified: mysql-test/suite/galera/r/galera_kill_applier.result modified: mysql-test/suite/galera/r/galera_var_slave_threads.result new file: mysql-test/suite/galera/t/MW-336.cnf modified: mysql-test/suite/galera/t/MW-336.test modified: mysql-test/suite/galera/t/galera_kill_applier.test modified: mysql-test/suite/galera/t/galera_parallel_autoinc_largetrx.test modified: mysql-test/suite/galera/t/galera_parallel_autoinc_manytrx.test modified: mysql-test/suite/galera/t/galera_var_slave_threads.test modified: mysql-test/suite/wsrep/disabled.def modified: mysql-test/suite/wsrep/r/variables.result modified: mysql-test/suite/wsrep/t/variables.test modified: sql/mysqld.cc modified: sql/wsrep_mysqld.cc modified: sql/wsrep_mysqld.h modified: sql/wsrep_thd.cc modified: sql/wsrep_var.cc
2019-07-11 06:13:58 +02:00
extern ulong wsrep_running_applier_threads;
extern ulong wsrep_running_rollbacker_threads;
MDEV 4427: query timeouts Added MAX_STATEMENT_TIME user variable to automaticly kill queries after a given time limit has expired. - Added timer functions based on pthread_cond_timedwait - Added kill_handlerton() to signal storage engines about kill/timeout - Added support for GRANT ... MAX_STATEMENT_TIME=# - Copy max_statement_time to current user, if stored in mysql.user - Added status variable max_statement_time_exceeded - Added KILL_TIMEOUT - Removed digest hash from performance schema tests as they change all the time. - Updated test results that changed because of the new user variables or new fields in mysql.user This functionallity is inspired by work done by Davi Arnaut at twitter. Test case is copied from Davi's work. Documentation can be found at https://kb.askmonty.org/en/how-to-limittimeout-queries/ mysql-test/r/mysqld--help.result: Updated for new help message mysql-test/suite/perfschema/r/all_instances.result: Added new mutex mysql-test/suite/sys_vars/r/max_statement_time_basic.result: Added testing of max_statement_time mysql-test/suite/sys_vars/t/max_statement_time_basic.test: Added testing of max_statement_time mysql-test/t/max_statement_time.test: Added testing of max_statement_time mysys/CMakeLists.txt: Added thr_timer mysys/my_init.c: mysys/mysys_priv.h: Added new mutex and condition variables Added new mutex and condition variables mysys/thr_timer.c: Added timer functions based on pthread_cond_timedwait() This can be compiled with HAVE_TIMER_CREATE to benchmark agains timer_create()/timer_settime() sql/lex.h: Added MAX_STATEMENT_TIME sql/log_event.cc: Safety fix (timeout should be threated as an interrupted query) sql/mysqld.cc: Added support for timers Added status variable max_statement_time_exceeded sql/share/errmsg-utf8.txt: Added ER_QUERY_TIMEOUT sql/signal_handler.cc: Added support for KILL_TIMEOUT sql/sql_acl.cc: Added support for GRANT ... MAX_STATEMENT_TIME=# Copy max_statement_time to current user sql/sql_class.cc: Added timer functionality to THD. Added thd_kill_timeout() sql/sql_class.h: Added timer functionality to THD. Added KILL_TIMEOUT Added max_statement_time variable in similar manner as long_query_time was done. sql/sql_connect.cc: Added handling of max_statement_time_exceeded sql/sql_parse.cc: Added starting and stopping timers for queries. sql/sql_show.cc: Added max_statement_time_exceeded for user/connects status in MariaDB 10.0 sql/sql_yacc.yy: Added support for GRANT ... MAX_STATEMENT_TIME=# syntax, to be enabled in 10.0 sql/structs.h: Added max_statement_time user resource sql/sys_vars.cc: Added max_statement_time variables mysql-test/suite/roles/create_and_drop_role_invalid_user_table.test Removed test as we require all fields in mysql.user table. scripts/mysql_system_tables.sql scripts/mysql_system_tables_data.sql scripts/mysql_system_tables_fix.sql Updated mysql.user with new max_statement_time field
2014-10-07 10:37:36 +02:00
extern bool wsrep_new_cluster;
extern bool wsrep_gtid_mode;
extern uint32 wsrep_gtid_domain_id;
2022-11-30 12:10:52 +01:00
extern std::atomic <bool > wsrep_thread_create_failed;
extern ulonglong wsrep_mode;
enum enum_wsrep_reject_types {
WSREP_REJECT_NONE, /* nothing rejected */
WSREP_REJECT_ALL, /* reject all queries, with UNKNOWN_COMMAND error */
WSREP_REJECT_ALL_KILL /* kill existing connections and reject all queries*/
};
2015-07-14 22:05:29 +02:00
enum enum_wsrep_OSU_method {
WSREP_OSU_TOI,
WSREP_OSU_RSU,
WSREP_OSU_NONE,
};
enum enum_wsrep_sync_wait {
2019-01-23 12:30:00 +01:00
WSREP_SYNC_WAIT_NONE= 0x0,
// select, begin
2019-01-23 12:30:00 +01:00
WSREP_SYNC_WAIT_BEFORE_READ= 0x1,
WSREP_SYNC_WAIT_BEFORE_UPDATE_DELETE= 0x2,
WSREP_SYNC_WAIT_BEFORE_INSERT_REPLACE= 0x4,
WSREP_SYNC_WAIT_BEFORE_SHOW= 0x8,
WSREP_SYNC_WAIT_MAX= 0xF
};
enum enum_wsrep_ignore_apply_error {
WSREP_IGNORE_ERRORS_NONE= 0x0,
WSREP_IGNORE_ERRORS_ON_RECONCILING_DDL= 0x1,
WSREP_IGNORE_ERRORS_ON_RECONCILING_DML= 0x2,
WSREP_IGNORE_ERRORS_ON_DDL= 0x4,
WSREP_IGNORE_ERRORS_MAX= 0x7
};
/* wsrep_mode features */
enum enum_wsrep_mode {
WSREP_MODE_STRICT_REPLICATION= (1ULL << 0),
WSREP_MODE_BINLOG_ROW_FORMAT_ONLY= (1ULL << 1),
WSREP_MODE_REQUIRED_PRIMARY_KEY= (1ULL << 2),
WSREP_MODE_REPLICATE_MYISAM= (1ULL << 3),
WSREP_MODE_REPLICATE_ARIA= (1ULL << 4),
WSREP_MODE_DISALLOW_LOCAL_GTID= (1ULL << 5)
};
2019-01-23 12:30:00 +01:00
// Streaming Replication
#define WSREP_FRAG_BYTES 0
#define WSREP_FRAG_ROWS 1
#define WSREP_FRAG_STATEMENTS 2
#define WSREP_SR_STORE_NONE 0
#define WSREP_SR_STORE_TABLE 1
extern const char *wsrep_fragment_units[];
extern const char *wsrep_SR_store_types[];
// MySQL status variables
extern my_bool wsrep_connected;
extern my_bool wsrep_ready;
extern const char* wsrep_cluster_state_uuid;
extern long long wsrep_cluster_conf_id;
extern const char* wsrep_cluster_status;
extern long wsrep_cluster_size;
extern long wsrep_local_index;
extern long long wsrep_local_bf_aborts;
extern const char* wsrep_provider_name;
extern const char* wsrep_provider_version;
extern const char* wsrep_provider_vendor;
2019-01-23 12:30:00 +01:00
extern char* wsrep_provider_capabilities;
extern char* wsrep_cluster_capabilities;
int wsrep_show_status(THD *thd, SHOW_VAR *var, void *buff,
system_status_var *status_var, enum_var_type scope);
2019-01-23 12:30:00 +01:00
int wsrep_show_ready(THD *thd, SHOW_VAR *var, char *buff);
void wsrep_free_status(THD *thd);
void wsrep_update_cluster_state_uuid(const char* str);
/* Filters out --wsrep-new-cluster oprtion from argv[]
* should be called in the very beginning of main() */
void wsrep_filter_new_cluster (int* argc, char* argv[]);
int wsrep_init();
void wsrep_deinit(bool free_options);
/* Initialize wsrep thread LOCKs and CONDs */
void wsrep_thr_init();
/* Destroy wsrep thread LOCKs and CONDs */
void wsrep_thr_deinit();
void wsrep_recover();
bool wsrep_before_SE(); // initialize wsrep before storage
// engines (true) or after (false)
/* wsrep initialization sequence at startup
* @param before wsrep_before_SE() value */
void wsrep_init_startup(bool before);
2019-01-23 12:30:00 +01:00
/* Recover streaming transactions from fragment storage */
void wsrep_recover_sr_from_storage(THD *);
// Other wsrep global variables
extern my_bool wsrep_inited; // whether wsrep is initialized ?
extern bool wsrep_service_started;
2019-01-23 12:30:00 +01:00
extern "C" void wsrep_fire_rollbacker(THD *thd);
extern "C" uint32 wsrep_thd_wsrep_rand(THD *thd);
extern "C" time_t wsrep_thd_query_start(THD *thd);
2019-01-23 12:30:00 +01:00
extern void wsrep_close_client_connections(my_bool wait_to_end,
THD *except_caller_thd= NULL);
extern "C" query_id_t wsrep_thd_wsrep_last_query_id(THD *thd);
extern "C" void wsrep_thd_set_wsrep_last_query_id(THD *thd, query_id_t id);
extern int wsrep_wait_committing_connections_close(int wait_time);
extern void wsrep_close_applier(THD *thd);
extern void wsrep_wait_appliers_close(THD *thd);
extern void wsrep_close_applier_threads(int count);
2019-01-23 12:30:00 +01:00
/* new defines */
extern void wsrep_stop_replication(THD *thd);
extern bool wsrep_start_replication(const char *wsrep_cluster_address);
2019-01-23 12:30:00 +01:00
extern void wsrep_shutdown_replication();
extern bool wsrep_check_mode (enum_wsrep_mode mask);
extern bool wsrep_check_mode_after_open_table (THD *thd, const handlerton *hton,
TABLE_LIST *tables);
extern bool wsrep_check_mode_before_cmd_execute (THD *thd);
2019-01-23 12:30:00 +01:00
extern bool wsrep_must_sync_wait (THD* thd, uint mask= WSREP_SYNC_WAIT_BEFORE_READ);
extern bool wsrep_sync_wait (THD* thd, uint mask= WSREP_SYNC_WAIT_BEFORE_READ);
extern bool wsrep_sync_wait (THD* thd, enum enum_sql_command command);
2019-01-23 12:30:00 +01:00
extern enum wsrep::provider::status
wsrep_sync_wait_upto (THD* thd, wsrep_gtid_t* upto, int timeout);
2014-09-28 11:08:07 +02:00
extern int wsrep_check_opts();
extern void wsrep_prepend_PATH (const char* path);
extern bool wsrep_append_fk_parent_table(THD* thd, TABLE_LIST* table, wsrep::key_array* keys);
extern bool wsrep_reload_ssl();
/* Other global variables */
extern wsrep_seqno_t wsrep_locked_seqno;
/* 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_SYNC_WAIT(thd_, before_) \
{ if (WSREP_CLIENT(thd_) && \
wsrep_sync_wait(thd_, before_)) goto wsrep_error_label; }
2019-01-23 12:30:00 +01:00
#define WSREP_MYSQL_DB (char *)"mysql"
2019-01-23 12:30:00 +01:00
#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;
2022-09-05 12:28:56 +02:00
#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;
2019-01-23 12:30:00 +01:00
2022-09-05 12:28:56 +02:00
#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_, \
2022-09-05 12:28:56 +02:00
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;
2019-01-23 12:30:00 +01:00
#define WSREP_PROVIDER_EXISTS (WSREP_PROVIDER_EXISTS_)
static inline bool wsrep_cluster_address_exists()
{
if (mysqld_server_started)
mysql_mutex_assert_owner(&LOCK_global_system_variables);
return wsrep_cluster_address && wsrep_cluster_address[0];
}
extern my_bool wsrep_ready_get();
extern void wsrep_ready_wait();
extern mysql_mutex_t LOCK_wsrep_ready;
extern mysql_cond_t COND_wsrep_ready;
extern mysql_mutex_t LOCK_wsrep_sst;
extern mysql_cond_t COND_wsrep_sst;
extern mysql_mutex_t LOCK_wsrep_sst_init;
extern mysql_cond_t COND_wsrep_sst_init;
extern int wsrep_replaying;
extern mysql_mutex_t LOCK_wsrep_replaying;
extern mysql_cond_t COND_wsrep_replaying;
extern mysql_mutex_t LOCK_wsrep_slave_threads;
extern mysql_cond_t COND_wsrep_slave_threads;
extern mysql_mutex_t LOCK_wsrep_gtid_wait_upto;
extern mysql_mutex_t LOCK_wsrep_cluster_config;
extern mysql_mutex_t LOCK_wsrep_desync;
2019-01-23 12:30:00 +01:00
extern mysql_mutex_t LOCK_wsrep_SR_pool;
extern mysql_mutex_t LOCK_wsrep_SR_store;
extern mysql_mutex_t LOCK_wsrep_config_state;
10.4 wsrep group commit fixes (#1224) * MDEV-16509 Improve wsrep commit performance with binlog disabled Release commit order critical section early after trx_commit_low() if binlog is not transaction coordinator. In order to avoid two phase commit, binlog_hton is not registered for THD during IO_CACHE population. Implemented a test which verifies that the transactions release commit order early. This optimization will change behavior during recovery as the commit is not two phase when binlog is off. Fixed and recorded wsrep-recover-v25 and wsrep-recover to match the behavior. * MDEV-18730 Ordering for wsrep binlog group commit Previously out of order execution was allowed for wsrep commits. Established proper ordering by populating wait_for_commit for every wsrep THD and making group commit leader to wait for prior commits before proceeding to trx_group_commit_leader(). * MDEV-18730 Added a test case to verify correct commit ordering * MDEV-16509, MDEV-18730 Review fixes Use WSREP_EMULATE_BINLOG() macro to decide if the binlog_hton should be registered. Whitespace/syntax fixes and cleanups. * MDEV-16509 Require binlog for galera_var_innodb_disallow_writes test If the commit to InnoDB is done in one phase, the native InnoDB behavior is that the transaction is committed in memory before it is persisted to disk. This means that the innodb_disallow_writes=ON may not prevent transaction to become visible to other readers before commit is completely over. On the other hand, if the commit is two phase (as it is with binlog), the transaction will be blocked in prepare phase. Fixed the test to use binlog, which enforces two phase commit, which in turn makes commit to block before the changes become visible to other connections. This guarantees that the test produces expected result.
2019-03-15 06:09:13 +01:00
extern mysql_mutex_t LOCK_wsrep_group_commit;
extern mysql_mutex_t LOCK_wsrep_joiner_monitor;
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 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
2019-01-23 12:30:00 +01:00
extern PSI_cond_key key_COND_wsrep_thd;
extern PSI_mutex_key key_LOCK_wsrep_ready;
extern PSI_mutex_key key_COND_wsrep_ready;
extern PSI_mutex_key key_LOCK_wsrep_sst;
extern PSI_cond_key key_COND_wsrep_sst;
extern PSI_mutex_key key_LOCK_wsrep_sst_init;
extern PSI_cond_key key_COND_wsrep_sst_init;
extern PSI_mutex_key key_LOCK_wsrep_sst_thread;
extern PSI_cond_key key_COND_wsrep_sst_thread;
extern PSI_mutex_key key_LOCK_wsrep_replaying;
extern PSI_cond_key key_COND_wsrep_replaying;
extern PSI_mutex_key key_LOCK_wsrep_slave_threads;
extern PSI_cond_key key_COND_wsrep_slave_threads;
extern PSI_mutex_key key_LOCK_wsrep_gtid_wait_upto;
extern PSI_cond_key key_COND_wsrep_gtid_wait_upto;
extern PSI_mutex_key key_LOCK_wsrep_cluster_config;
extern PSI_mutex_key key_LOCK_wsrep_desync;
2019-01-23 12:30:00 +01:00
extern PSI_mutex_key key_LOCK_wsrep_SR_pool;
extern PSI_mutex_key key_LOCK_wsrep_SR_store;
extern PSI_mutex_key key_LOCK_wsrep_global_seqno;
extern PSI_mutex_key key_LOCK_wsrep_thd_queue;
extern PSI_cond_key key_COND_wsrep_thd_queue;
extern PSI_mutex_key key_LOCK_wsrep_joiner_monitor;
extern PSI_mutex_key key_LOCK_wsrep_donor_monitor;
extern PSI_file_key key_file_wsrep_gra_log;
extern PSI_thread_key key_wsrep_sst_joiner;
extern PSI_thread_key key_wsrep_sst_donor;
extern PSI_thread_key key_wsrep_rollbacker;
extern PSI_thread_key key_wsrep_applier;
extern PSI_thread_key key_wsrep_sst_joiner_monitor;
extern PSI_thread_key key_wsrep_sst_donor_monitor;
#endif /* HAVE_PSI_INTERFACE */
struct TABLE_LIST;
class Alter_info;
Changing field::field_name and Item::name to LEX_CSTRING Benefits of this patch: - Removed a lot of calls to strlen(), especially for field_string - Strings generated by parser are now const strings, less chance of accidently changing a string - Removed a lot of calls with LEX_STRING as parameter (changed to pointer) - More uniform code - Item::name_length was not kept up to date. Now fixed - Several bugs found and fixed (Access to null pointers, access of freed memory, wrong arguments to printf like functions) - Removed a lot of casts from (const char*) to (char*) Changes: - This caused some ABI changes - lex_string_set now uses LEX_CSTRING - Some fucntions are now taking const char* instead of char* - Create_field::change and after changed to LEX_CSTRING - handler::connect_string, comment and engine_name() changed to LEX_CSTRING - Checked printf() related calls to find bugs. Found and fixed several errors in old code. - A lot of changes from LEX_STRING to LEX_CSTRING, especially related to parsing and events. - Some changes from LEX_STRING and LEX_STRING & to LEX_CSTRING* - Some changes for char* to const char* - Added printf argument checking for my_snprintf() - Introduced null_clex_str, star_clex_string, temp_lex_str to simplify code - Added item_empty_name and item_used_name to be able to distingush between items that was given an empty name and items that was not given a name This is used in sql_yacc.yy to know when to give an item a name. - select table_name."*' is not anymore same as table_name.* - removed not used function Item::rename() - Added comparision of item->name_length before some calls to my_strcasecmp() to speed up comparison - Moved Item_sp_variable::make_field() from item.h to item.cc - Some minimal code changes to avoid copying to const char * - Fixed wrong error message in wsrep_mysql_parse() - Fixed wrong code in find_field_in_natural_join() where real_item() was set when it shouldn't - ER_ERROR_ON_RENAME was used with extra arguments. - Removed some (wrong) ER_OUTOFMEMORY, as alloc_root will already give the error. TODO: - Check possible unsafe casts in plugin/auth_examples/qa_auth_interface.c - Change code to not modify LEX_CSTRING for database name (as part of lower_case_table_names)
2017-04-23 18:39:57 +02:00
int wsrep_to_isolation_begin(THD *thd, const char *db_, const char *table_,
const TABLE_LIST* table_list,
2020-11-13 20:54:21 +01:00
const Alter_info* alter_info= nullptr,
const wsrep::key_array *fk_tables= nullptr,
const HA_CREATE_INFO* create_info= nullptr);
bool wsrep_should_replicate_ddl(THD* thd, const handlerton *db_type);
bool wsrep_should_replicate_ddl_iterate(THD* thd, const TABLE_LIST* table_list);
2019-01-23 12:30:00 +01:00
void wsrep_to_isolation_end(THD *thd);
2019-01-23 12:30:00 +01:00
bool wsrep_append_SR_keys(THD *thd);
int wsrep_to_buf_helper(
THD* thd, const char *query, uint query_len, uchar** buf, size_t* buf_len);
2019-01-23 12:30:00 +01:00
int wsrep_create_trigger_query(THD *thd, uchar** buf, size_t* buf_len);
int wsrep_create_event_query(THD *thd, uchar** buf, size_t* buf_len);
2019-01-23 12:30:00 +01:00
void wsrep_init_sidno(const wsrep_uuid_t&);
bool wsrep_node_is_donor();
bool wsrep_node_is_synced();
2019-01-23 12:30:00 +01:00
void wsrep_init_SR();
void wsrep_verify_SE_checkpoint(const wsrep_uuid_t& uuid, wsrep_seqno_t seqno);
int wsrep_replay_from_SR_store(THD*, const wsrep_trx_meta_t&);
class Log_event;
int wsrep_ignored_error_code(Log_event* ev, int error);
int wsrep_must_ignore_error(THD* thd);
struct wsrep_server_gtid_t
{
uint32 domain_id;
uint32 server_id;
uint64 seqno;
};
class Wsrep_gtid_server
{
public:
uint32 domain_id;
uint32 server_id;
Wsrep_gtid_server()
: m_force_signal(false)
, m_seqno(0)
, m_committed_seqno(0)
{ }
void gtid(const wsrep_server_gtid_t& gtid)
{
domain_id= gtid.domain_id;
server_id= gtid.server_id;
m_seqno= gtid.seqno;
}
wsrep_server_gtid_t gtid()
{
wsrep_server_gtid_t gtid;
gtid.domain_id= domain_id;
gtid.server_id= server_id;
gtid.seqno= m_seqno;
return gtid;
}
void seqno(const uint64 seqno) { m_seqno= seqno; }
uint64 seqno() const { return m_seqno; }
uint64 seqno_committed() const { return m_committed_seqno; }
uint64 seqno_inc()
{
m_seqno++;
return m_seqno;
}
const wsrep_server_gtid_t& undefined()
{
return m_undefined;
}
int wait_gtid_upto(const uint64_t seqno, uint timeout)
{
int wait_result= 0;
struct timespec wait_time;
int ret= 0;
mysql_cond_t wait_cond;
mysql_cond_init(key_COND_wsrep_gtid_wait_upto, &wait_cond, NULL);
set_timespec(wait_time, timeout);
mysql_mutex_lock(&LOCK_wsrep_gtid_wait_upto);
std::multimap<uint64, mysql_cond_t*>::iterator it;
if (seqno > m_seqno)
{
try
{
it= m_wait_map.insert(std::make_pair(seqno, &wait_cond));
}
catch (std::bad_alloc& e)
{
ret= ENOMEM;
}
while (!ret && (m_committed_seqno < seqno) && !m_force_signal)
{
wait_result= mysql_cond_timedwait(&wait_cond,
&LOCK_wsrep_gtid_wait_upto,
&wait_time);
if (wait_result == ETIMEDOUT || wait_result == ETIME)
{
ret= wait_result;
break;
}
}
if (ret != ENOMEM)
{
m_wait_map.erase(it);
}
}
mysql_mutex_unlock(&LOCK_wsrep_gtid_wait_upto);
mysql_cond_destroy(&wait_cond);
return ret;
}
void signal_waiters(uint64 seqno, bool signal_all)
{
mysql_mutex_lock(&LOCK_wsrep_gtid_wait_upto);
if (!signal_all && (m_committed_seqno >= seqno))
{
mysql_mutex_unlock(&LOCK_wsrep_gtid_wait_upto);
return;
}
m_force_signal= true;
std::multimap<uint64, mysql_cond_t*>::iterator it_end;
std::multimap<uint64, mysql_cond_t*>::iterator it_begin;
if (signal_all)
{
it_end= m_wait_map.end();
}
else
{
it_end= m_wait_map.upper_bound(seqno);
}
if (m_committed_seqno < seqno)
{
m_committed_seqno= seqno;
}
for (it_begin = m_wait_map.begin(); it_begin != it_end; ++it_begin)
{
mysql_cond_signal(it_begin->second);
}
m_force_signal= false;
mysql_mutex_unlock(&LOCK_wsrep_gtid_wait_upto);
}
private:
const wsrep_server_gtid_t m_undefined= {0,0,0};
std::multimap<uint64, mysql_cond_t*> m_wait_map;
bool m_force_signal;
Atomic_counter<uint64_t> m_seqno;
Atomic_counter<uint64_t> m_committed_seqno;
};
extern Wsrep_gtid_server wsrep_gtid_server;
void wsrep_init_gtid();
bool wsrep_check_gtid_seqno(const uint32&, const uint32&, uint64&);
bool wsrep_get_binlog_gtid_seqno(wsrep_server_gtid_t&);
2019-01-23 12:30:00 +01:00
typedef struct wsrep_key_arr
{
wsrep_key_t* keys;
size_t keys_len;
} wsrep_key_arr_t;
bool wsrep_prepare_keys_for_isolation(THD* thd,
const char* db,
const char* table,
const TABLE_LIST* table_list,
wsrep_key_arr_t* ka);
void wsrep_keys_free(wsrep_key_arr_t* key_arr);
2018-06-12 18:39:37 +02:00
2019-01-23 12:30:00 +01:00
extern void
wsrep_handle_mdl_conflict(MDL_context *requestor_ctx,
const MDL_ticket *ticket,
2019-01-23 12:30:00 +01:00
const MDL_key *key);
MDEV-19746: Galera test failures because of wsrep_slave_threads identification Problem was that tests select INFORMATION_SCHEMA.PROCESSLIST processes from user system user and empty state. Thus, there is not clear state for slave threads. Changes: - Added new status variables that store current amount of applier threads (wsrep_applier_thread_count) and rollbacker threads (wsrep_rollbacker_thread_count). This will make clear how many slave threads of certain type there is. - Added THD state "wsrep applier idle" when applier slave thread is waiting for work. This makes finding slave/applier threads easier. - Added force-restart option for mtr to always restart servers between tests to avoid race on start of the test - Added wait_condition_with_debug to wait until the passed statement returns true, or the operation times out. If operation times out, the additional error statement will be executed Changes to be committed: new file: mysql-test/include/force_restart.inc new file: mysql-test/include/wait_condition_with_debug.inc modified: mysql-test/mysql-test-run.pl modified: mysql-test/suite/galera/disabled.def modified: mysql-test/suite/galera/r/MW-336.result modified: mysql-test/suite/galera/r/galera_kill_applier.result modified: mysql-test/suite/galera/r/galera_var_slave_threads.result new file: mysql-test/suite/galera/t/MW-336.cnf modified: mysql-test/suite/galera/t/MW-336.test modified: mysql-test/suite/galera/t/galera_kill_applier.test modified: mysql-test/suite/galera/t/galera_parallel_autoinc_largetrx.test modified: mysql-test/suite/galera/t/galera_parallel_autoinc_manytrx.test modified: mysql-test/suite/galera/t/galera_var_slave_threads.test modified: mysql-test/suite/wsrep/disabled.def modified: mysql-test/suite/wsrep/r/variables.result modified: mysql-test/suite/wsrep/t/variables.test modified: sql/mysqld.cc modified: sql/wsrep_mysqld.cc modified: sql/wsrep_mysqld.h modified: sql/wsrep_thd.cc modified: sql/wsrep_var.cc
2019-07-11 06:13:58 +02:00
enum wsrep_thread_type {
WSREP_APPLIER_THREAD=1,
WSREP_ROLLBACKER_THREAD=2
};
2019-01-23 12:30:00 +01:00
typedef void (*wsrep_thd_processor_fun)(THD*, void *);
class Wsrep_thd_args
{
public:
Wsrep_thd_args(wsrep_thd_processor_fun fun,
wsrep_thread_type thread_type,
pthread_t thread_id)
2019-01-23 12:30:00 +01:00
:
fun_ (fun),
thread_type_ (thread_type),
thread_id_ (thread_id)
2019-01-23 12:30:00 +01:00
{ }
wsrep_thd_processor_fun fun() { return fun_; }
pthread_t* thread_id() {return &thread_id_; }
2019-07-25 17:42:06 +02:00
enum wsrep_thread_type thread_type() {return thread_type_;}
2019-01-23 12:30:00 +01:00
private:
Wsrep_thd_args(const Wsrep_thd_args&);
Wsrep_thd_args& operator=(const Wsrep_thd_args&);
wsrep_thd_processor_fun fun_;
2019-07-25 17:42:06 +02:00
enum wsrep_thread_type thread_type_;
pthread_t thread_id_;
2019-01-23 12:30:00 +01:00
};
void* start_wsrep_THD(void*);
void wsrep_close_threads(THD *thd);
bool wsrep_is_show_query(enum enum_sql_command command);
void wsrep_replay_transaction(THD *thd);
bool wsrep_create_like_table(THD* thd, TABLE_LIST* table,
TABLE_LIST* src_table,
HA_CREATE_INFO *create_info);
bool wsrep_node_is_donor();
bool wsrep_node_is_synced();
/**
* Check if the wsrep provider (ie the Galera library) is capable of
* doing streaming replication.
* @return true if SR capable
*/
bool wsrep_provider_is_SR_capable();
/**
* Initialize WSREP server instance.
*
* @return Zero on success, non-zero on error.
*/
int wsrep_init_server();
/**
* Initialize WSREP globals. This should be done after server initialization
* is complete and the server has joined to the cluster.
*
*/
void wsrep_init_globals();
/**
* Deinit and release WSREP resources.
*/
void wsrep_deinit_server();
/**
* Convert streaming fragment unit (WSREP_FRAG_BYTES, WSREP_FRAG_ROWS...)
* to corresponding wsrep-lib fragment_unit
*/
enum wsrep::streaming_context::fragment_unit wsrep_fragment_unit(ulong unit);
MDEV-21577 MDL BF-BF conflict Some DDL statements appear to acquire MDL locks for a table referenced by foreign key constraint from the actual affected table of the DDL statement. OPTIMIZE, REPAIR and ALTER TABLE belong to this class of DDL statements. Earlier MariaDB version did not take this in consideration, and appended only affected table in the certification key list in write set. Because of missing certification information, it could happen that e.g. OPTIMIZE table for FK child table could be allowed to apply in parallel with DML operating on the foreign key parent table, and this could lead to unhandled MDL lock conflicts between two high priority appliers (BF). The fix in this patch, changes the TOI replication for OPTIMIZE, REPAIR and ALTER TABLE statements so that before the execution of respective DDL statement, there is foreign key parent search round. This FK parent search contains following steps: * open and lock the affected table (with permissive shared locks) * iterate over foreign key contstraints and collect and array of Fk parent table names * close all tables open for the THD and release MDL locks * do the actual TOI replication with the affected table and FK parent table names as key values The patch contains also new mtr test for verifying that the above mentioned DDL statements replicate without problems when operating on FK child table. The mtr test scenario #1, which can be used to check if some other DDL (on top of OPTIMIZE, REPAIR and ALTER) could cause similar excessive FK parent table locking. Reviewed-by: Aleksey Midenkov <aleksey.midenkov@mariadb.com> Reviewed-by: Jan Lindström <jan.lindstrom@mariadb.com>
2020-10-27 11:45:42 +01:00
wsrep::key wsrep_prepare_key_for_toi(const char* db, const char* table,
enum wsrep::key::type type);
2019-01-23 12:30:00 +01:00
#else /* !WITH_WSREP */
/* These macros are needed to compile MariaDB without WSREP support
* (e.g. embedded) */
2014-09-25 23:00:45 +02:00
2015-02-06 16:14:23 +01:00
#define WSREP_PROVIDER_EXISTS (0)
2014-09-25 23:00:45 +02:00
#define wsrep_emulate_bin_log (0)
#define wsrep_to_isolation (0)
#define wsrep_before_SE() (0)
#define wsrep_init_startup(X)
#define wsrep_check_opts() (0)
#define wsrep_thr_init() do {} while(0)
#define wsrep_thr_deinit() do {} while(0)
2019-01-23 12:30:00 +01:00
#define wsrep_init_globals() do {} while(0)
#define wsrep_create_appliers(X) do {} while(0)
2020-06-14 11:46:37 +02:00
#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_)
2019-01-23 12:30:00 +01:00
2014-09-25 23:00:45 +02:00
#endif /* WITH_WSREP */
2019-01-23 12:30:00 +01:00
#endif /* WSREP_MYSQLD_H */