From 7e8ed15b95b64af2068a3515fe97f2c245311323 Mon Sep 17 00:00:00 2001 From: Julius Goryavsky Date: Thu, 9 Aug 2018 02:24:12 +0000 Subject: Fixes after review and correction of the problems caused by the fact that during the SST innodb plugin is not yet initialized, as well as problems with running tests from the root user (not directly related to the MDEV-10754). --- sql/wsrep_mysqld.h | 1 + sql/wsrep_sst.cc | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) (limited to 'sql') diff --git a/sql/wsrep_mysqld.h b/sql/wsrep_mysqld.h index 272e4ac4984..9fc8aa02df4 100644 --- a/sql/wsrep_mysqld.h +++ b/sql/wsrep_mysqld.h @@ -160,6 +160,7 @@ extern "C" time_t wsrep_thd_query_start(THD *thd); extern "C" query_id_t wsrep_thd_query_id(THD *thd); 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 "C" void wsrep_set_data_home_dir(const char *data_dir); extern void wsrep_close_client_connections(my_bool wait_to_end); extern int wsrep_wait_committing_connections_close(int wait_time); diff --git a/sql/wsrep_sst.cc b/sql/wsrep_sst.cc index 155051bfe84..0274a364bc5 100644 --- a/sql/wsrep_sst.cc +++ b/sql/wsrep_sst.cc @@ -67,6 +67,13 @@ bool wsrep_sst_method_update (sys_var *self, THD* thd, enum_var_type type) return 0; } +static const char* data_home_dir = NULL; + +extern "C" +void wsrep_set_data_home_dir(const char *data_dir) +{ + data_home_dir= (data_dir && *data_dir) ? data_dir : NULL; +} static void make_wsrep_defaults_file() { @@ -549,6 +556,29 @@ static int sst_append_auth_env(wsp::env& env, const char* sst_auth) return -env.error(); } +#define DATA_HOME_DIR_ENV "INNODB_DATA_HOME_DIR" + +static int sst_append_data_dir(wsp::env& env, const char* data_dir) +{ + int const data_dir_size= strlen(DATA_HOME_DIR_ENV) + 1 /* = */ + + (data_dir ? strlen(data_dir) : 0) + 1 /* \0 */; + + wsp::string data_dir_str(data_dir_size); // for automatic cleanup on return + if (!data_dir_str()) return -ENOMEM; + + int ret= snprintf(data_dir_str(), data_dir_size, "%s=%s", + DATA_HOME_DIR_ENV, data_dir ? data_dir : ""); + + if (ret < 0 || ret >= data_dir_size) + { + WSREP_ERROR("sst_append_data_dir(): snprintf() failed: %d", ret); + return (ret < 0 ? ret : -EMSGSIZE); + } + + env.append(data_dir_str()); + return -env.error(); +} + static ssize_t sst_prepare_other (const char* method, const char* sst_auth, const char* addr_in, @@ -610,6 +640,16 @@ static ssize_t sst_prepare_other (const char* method, return ret; } + if (data_home_dir) + { + if ((ret= sst_append_data_dir(env, data_home_dir))) + { + WSREP_ERROR("sst_prepare_other(): appending data " + "directory failed: %d", ret); + return ret; + } + } + pthread_t tmp; sst_thread_arg arg(cmd_str(), env()); mysql_mutex_lock (&arg.lock); @@ -1301,6 +1341,16 @@ wsrep_cb_status_t wsrep_sst_donate_cb (void* app_ctx, void* recv_ctx, return WSREP_CB_FAILURE; } + if (data_home_dir) + { + if ((ret= sst_append_data_dir(env, data_home_dir))) + { + WSREP_ERROR("wsrep_sst_donate_cb(): appending data " + "directory failed: %d", ret); + return WSREP_CB_FAILURE; + } + } + if (!strcmp (WSREP_SST_MYSQLDUMP, method)) { ret = sst_donate_mysqldump(data, ¤t_gtid->uuid, uuid_str, -- cgit v1.2.1 From b245023fe0bc6fa0bd6e2dfa9352b30b71d0d27d Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Thu, 30 Aug 2018 00:51:39 -0700 Subject: MDEV-16992 Assertion `table_ref->table || table_ref->view' failed in Field_iterator_table_ref::set_field_iterator Several functions that processed different prepare statements missed the DT_INIT flag in last parameter of the open_normal_and_derived_tables() calls. It made context analysis of derived tables dependent on the order in which the derived tables were processed by mysql_handle_derived(). This order was induced by the order of SELECTs in all_select_list. In 10.4 the order of SELECTs in all_select_list became different and lack of the DT_INIT flags in some open_normal_and_derived_tables() call became critical as some derived tables were not identified as such. --- sql/sql_prepare.cc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'sql') diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index d209707fbd7..0d7b0433bdd 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -1637,7 +1637,7 @@ static bool mysql_test_do_fields(Prepared_statement *stmt, DBUG_RETURN(TRUE); if (open_normal_and_derived_tables(thd, tables, MYSQL_OPEN_FORCE_SHARED_MDL, - DT_PREPARE | DT_CREATE)) + DT_INIT | DT_PREPARE | DT_CREATE)) DBUG_RETURN(TRUE); DBUG_RETURN(setup_fields(thd, Ref_ptr_array(), *values, MARK_COLUMNS_NONE, 0, NULL, 0)); @@ -1669,7 +1669,7 @@ static bool mysql_test_set_fields(Prepared_statement *stmt, if ((tables && check_table_access(thd, SELECT_ACL, tables, FALSE, UINT_MAX, FALSE)) || open_normal_and_derived_tables(thd, tables, MYSQL_OPEN_FORCE_SHARED_MDL, - DT_PREPARE | DT_CREATE)) + DT_INIT | DT_PREPARE | DT_CREATE)) goto error; while ((var= it++)) @@ -1706,7 +1706,8 @@ static bool mysql_test_call_fields(Prepared_statement *stmt, if ((tables && check_table_access(thd, SELECT_ACL, tables, FALSE, UINT_MAX, FALSE)) || - open_normal_and_derived_tables(thd, tables, MYSQL_OPEN_FORCE_SHARED_MDL, DT_PREPARE)) + open_normal_and_derived_tables(thd, tables, MYSQL_OPEN_FORCE_SHARED_MDL, + DT_INIT | DT_PREPARE)) goto err; while ((item= it++)) @@ -1833,7 +1834,7 @@ static bool mysql_test_create_table(Prepared_statement *stmt) if (open_normal_and_derived_tables(stmt->thd, lex->query_tables, MYSQL_OPEN_FORCE_SHARED_MDL, - DT_PREPARE | DT_CREATE)) + DT_INIT | DT_PREPARE | DT_CREATE)) DBUG_RETURN(TRUE); select_lex->context.resolve_in_select_list= TRUE; @@ -1854,7 +1855,7 @@ static bool mysql_test_create_table(Prepared_statement *stmt) */ if (open_normal_and_derived_tables(stmt->thd, lex->query_tables, MYSQL_OPEN_FORCE_SHARED_MDL, - DT_PREPARE)) + DT_INIT | DT_PREPARE)) DBUG_RETURN(TRUE); } @@ -2081,7 +2082,7 @@ static bool mysql_test_create_view(Prepared_statement *stmt) lex->context_analysis_only|= CONTEXT_ANALYSIS_ONLY_VIEW; if (open_normal_and_derived_tables(thd, tables, MYSQL_OPEN_FORCE_SHARED_MDL, - DT_PREPARE)) + DT_INIT | DT_PREPARE)) goto err; res= select_like_stmt_test(stmt, 0, 0); -- cgit v1.2.1 From 3b5d3cd68e4acceb613822adc66b87f396920e59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Fri, 31 Aug 2018 11:41:59 +0300 Subject: Revert MDEV-9519 due to regressions This reverts commit 75dfd4acb995789ca5f86ccbd361fff9d2797e79. --- sql/field.h | 46 --------------------------- sql/handler.cc | 31 ++---------------- sql/mysqld.cc | 14 -------- sql/sql_class.h | 11 ------- sql/sys_vars.cc | 93 +----------------------------------------------------- sql/wsrep_mysqld.h | 4 --- sql/wsrep_thd.cc | 22 ------------- 7 files changed, 4 insertions(+), 217 deletions(-) (limited to 'sql') diff --git a/sql/field.h b/sql/field.h index 30b4b9fd68e..c21bba6936f 100644 --- a/sql/field.h +++ b/sql/field.h @@ -1329,17 +1329,6 @@ public: /* Hash value */ virtual void hash(ulong *nr, ulong *nr2); - /** - Get the upper limit of the MySQL integral and floating-point type. - - @return maximum allowed value for the field - */ - virtual ulonglong get_max_int_value() const - { - DBUG_ASSERT(false); - return 0ULL; - } - /** Checks whether a string field is part of write_set. @@ -1807,11 +1796,6 @@ public: *to= *from; return from + 1; } - - virtual ulonglong get_max_int_value() const - { - return unsigned_flag ? 0xFFULL : 0x7FULL; - } }; @@ -1853,10 +1837,6 @@ public: virtual const uchar *unpack(uchar* to, const uchar *from, const uchar *from_end, uint param_data) { return unpack_int16(to, from, from_end); } - virtual ulonglong get_max_int_value() const - { - return unsigned_flag ? 0xFFFFULL : 0x7FFFULL; - } }; class Field_medium :public Field_num { @@ -1890,10 +1870,6 @@ public: { return Field::pack(to, from, max_length); } - virtual ulonglong get_max_int_value() const - { - return unsigned_flag ? 0xFFFFFFULL : 0x7FFFFFULL; - } }; @@ -1939,10 +1915,6 @@ public: { return unpack_int32(to, from, from_end); } - virtual ulonglong get_max_int_value() const - { - return unsigned_flag ? 0xFFFFFFFFULL : 0x7FFFFFFFULL; - } }; @@ -1992,10 +1964,6 @@ public: { return unpack_int64(to, from, from_end); } - virtual ulonglong get_max_int_value() const - { - return unsigned_flag ? 0xFFFFFFFFFFFFFFFFULL : 0x7FFFFFFFFFFFFFFFULL; - } }; @@ -2029,13 +1997,6 @@ public: uint32 pack_length() const { return sizeof(float); } uint row_pack_length() const { return pack_length(); } void sql_type(String &str) const; - virtual ulonglong get_max_int_value() const - { - /* - We use the maximum as per IEEE754-2008 standard, 2^24 - */ - return 0x1000000ULL; - } private: int do_save_field_metadata(uchar *first_byte); }; @@ -2078,13 +2039,6 @@ public: uint32 pack_length() const { return sizeof(double); } uint row_pack_length() const { return pack_length(); } void sql_type(String &str) const; - virtual ulonglong get_max_int_value() const - { - /* - We use the maximum as per IEEE754-2008 standard, 2^53 - */ - return 0x20000000000000ULL; - } private: int do_save_field_metadata(uchar *first_byte); }; diff --git a/sql/handler.cc b/sql/handler.cc index e2690023807..9c319b995da 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -2853,15 +2853,9 @@ compute_next_insert_id(ulonglong nr,struct system_variables *variables) nr= nr + 1; // optimization of the formula below else { - /* - Calculating the number of complete auto_increment_increment extents: - */ nr= (((nr+ variables->auto_increment_increment - variables->auto_increment_offset)) / (ulonglong) variables->auto_increment_increment); - /* - Adding an offset to the auto_increment_increment extent boundary: - */ nr= (nr* (ulonglong) variables->auto_increment_increment + variables->auto_increment_offset); } @@ -2917,14 +2911,8 @@ prev_insert_id(ulonglong nr, struct system_variables *variables) } if (variables->auto_increment_increment == 1) return nr; // optimization of the formula below - /* - Calculating the number of complete auto_increment_increment extents: - */ nr= (((nr - variables->auto_increment_offset)) / (ulonglong) variables->auto_increment_increment); - /* - Adding an offset to the auto_increment_increment extent boundary: - */ return (nr * (ulonglong) variables->auto_increment_increment + variables->auto_increment_offset); } @@ -3146,23 +3134,10 @@ int handler::update_auto_increment() if (unlikely(tmp)) // Out of range value in store { /* - first test if the query was aborted due to strict mode constraints - */ - if (thd->killed == KILL_BAD_DATA || - nr > table->next_number_field->get_max_int_value()) - DBUG_RETURN(HA_ERR_AUTOINC_ERANGE); - - /* - field refused this value (overflow) and truncated it, use the result of - the truncation (which is going to be inserted); however we try to - decrease it to honour auto_increment_* variables. - That will shift the left bound of the reserved interval, we don't - bother shifting the right bound (anyway any other value from this - interval will cause a duplicate key). + It's better to return an error here than getting a confusing + 'duplicate key error' later. */ - nr= prev_insert_id(table->next_number_field->val_int(), variables); - if (unlikely(table->next_number_field->store((longlong) nr, TRUE))) - nr= table->next_number_field->val_int(); + result= HA_ERR_AUTOINC_ERANGE; } if (append) { diff --git a/sql/mysqld.cc b/sql/mysqld.cc index a65f430f74e..34bb75cbfba 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -4192,20 +4192,6 @@ static int init_common_variables() DBUG_PRINT("info",("%s Ver %s for %s on %s\n",my_progname, server_version, SYSTEM_TYPE,MACHINE_TYPE)); -#ifdef WITH_WSREP - /* - We need to initialize auxiliary variables, that will be - further keep the original values of auto-increment options - as they set by the user. These variables used to restore - user-defined values of the auto-increment options after - setting of the wsrep_auto_increment_control to 'OFF'. - */ - global_system_variables.saved_auto_increment_increment= - global_system_variables.auto_increment_increment; - global_system_variables.saved_auto_increment_offset= - global_system_variables.auto_increment_offset; -#endif /* WITH_WSREP */ - #ifdef HAVE_LARGE_PAGES /* Initialize large page size */ if (opt_large_pages) diff --git a/sql/sql_class.h b/sql/sql_class.h index f0c486bd172..53e451511d5 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -552,17 +552,6 @@ typedef struct system_variables ha_rows max_join_size; ha_rows expensive_subquery_limit; ulong auto_increment_increment, auto_increment_offset; -#ifdef WITH_WSREP - /* - Variables with stored values of the auto_increment_increment - and auto_increment_offset options that are will be needed when - wsrep_auto_increment_control will be set to 'OFF', because the - setting it to 'ON' leads to overwriting of the original values - (which are set by the user) by calculated values (which are - based on the cluster's size): - */ - ulong saved_auto_increment_increment, saved_auto_increment_offset; -#endif /* WITH_WSREP */ ulong lock_wait_timeout; ulong join_cache_level; ulong max_allowed_packet; diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index 8a67c1d38f3..f941794f89e 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -345,56 +345,13 @@ static Sys_var_long Sys_pfs_connect_attrs_size( #endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */ -#ifdef WITH_WSREP - -/* - We need to keep the original values set by the user, as they will - be lost if wsrep_auto_increment_control set to 'ON': -*/ -static bool update_auto_increment_increment (sys_var *self, THD *thd, enum_var_type type) -{ - if (type == OPT_GLOBAL) - global_system_variables.saved_auto_increment_increment= - global_system_variables.auto_increment_increment; - else - thd->variables.saved_auto_increment_increment= - thd->variables.auto_increment_increment; - return false; -} - -#endif /* WITH_WSREP */ - static Sys_var_ulong Sys_auto_increment_increment( "auto_increment_increment", "Auto-increment columns are incremented by this", SESSION_VAR(auto_increment_increment), CMD_LINE(OPT_ARG), VALID_RANGE(1, 65535), DEFAULT(1), BLOCK_SIZE(1), -#ifdef WITH_WSREP - NO_MUTEX_GUARD, IN_BINLOG, ON_CHECK(0), - ON_UPDATE(update_auto_increment_increment)); -#else NO_MUTEX_GUARD, IN_BINLOG); -#endif /* WITH_WSREP */ - -#ifdef WITH_WSREP - -/* - We need to keep the original values set by the user, as they will - be lost if wsrep_auto_increment_control set to 'ON': -*/ -static bool update_auto_increment_offset (sys_var *self, THD *thd, enum_var_type type) -{ - if (type == OPT_GLOBAL) - global_system_variables.saved_auto_increment_offset= - global_system_variables.auto_increment_offset; - else - thd->variables.saved_auto_increment_offset= - thd->variables.auto_increment_offset; - return false; -} - -#endif /* WITH_WSREP */ static Sys_var_ulong Sys_auto_increment_offset( "auto_increment_offset", @@ -403,12 +360,7 @@ static Sys_var_ulong Sys_auto_increment_offset( SESSION_VAR(auto_increment_offset), CMD_LINE(OPT_ARG), VALID_RANGE(1, 65535), DEFAULT(1), BLOCK_SIZE(1), -#ifdef WITH_WSREP - NO_MUTEX_GUARD, IN_BINLOG, ON_CHECK(0), - ON_UPDATE(update_auto_increment_offset)); -#else NO_MUTEX_GUARD, IN_BINLOG); -#endif /* WITH_WSREP */ static Sys_var_mybool Sys_automatic_sp_privileges( "automatic_sp_privileges", @@ -4895,54 +4847,11 @@ static Sys_var_ulong Sys_wsrep_retry_autocommit( SESSION_VAR(wsrep_retry_autocommit), CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 10000), DEFAULT(1), BLOCK_SIZE(1)); -static bool update_wsrep_auto_increment_control (sys_var *self, THD *thd, enum_var_type type) -{ - if (wsrep_auto_increment_control) - { - /* - The variables that control auto increment shall be calculated - automaticaly based on the size of the cluster. This usually done - within the wsrep_view_handler_cb callback. However, if the user - manually sets the value of wsrep_auto_increment_control to 'ON', - then we should to re-calculate these variables again (because - these values may be required before wsrep_view_handler_cb will - be re-invoked, which is rarely invoked if the cluster stays in - the stable state): - */ - global_system_variables.auto_increment_increment= - wsrep_cluster_size ? wsrep_cluster_size : 1; - global_system_variables.auto_increment_offset= - wsrep_local_index >= 0 ? wsrep_local_index + 1 : 1; - thd->variables.auto_increment_increment= - global_system_variables.auto_increment_increment; - thd->variables.auto_increment_offset= - global_system_variables.auto_increment_offset; - } - else - { - /* - We must restore the last values of the variables that - are explicitly specified by the user: - */ - global_system_variables.auto_increment_increment= - global_system_variables.saved_auto_increment_increment; - global_system_variables.auto_increment_offset= - global_system_variables.saved_auto_increment_offset; - thd->variables.auto_increment_increment= - thd->variables.saved_auto_increment_increment; - thd->variables.auto_increment_offset= - thd->variables.saved_auto_increment_offset; - } - return false; -} - static Sys_var_mybool Sys_wsrep_auto_increment_control( "wsrep_auto_increment_control", "To automatically control the " "assignment of autoincrement variables", GLOBAL_VAR(wsrep_auto_increment_control), - CMD_LINE(OPT_ARG), DEFAULT(TRUE), - NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0), - ON_UPDATE(update_wsrep_auto_increment_control)); + CMD_LINE(OPT_ARG), DEFAULT(TRUE)); static Sys_var_mybool Sys_wsrep_drupal_282555_workaround( "wsrep_drupal_282555_workaround", "Enable a workaround to handle the " diff --git a/sql/wsrep_mysqld.h b/sql/wsrep_mysqld.h index c015f94e165..9fc8aa02df4 100644 --- a/sql/wsrep_mysqld.h +++ b/sql/wsrep_mysqld.h @@ -162,10 +162,6 @@ 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 "C" void wsrep_set_data_home_dir(const char *data_dir); -extern "C" void wsrep_thd_auto_increment_variables(THD*, - unsigned long long *offset, - unsigned long long *increment); - extern void wsrep_close_client_connections(my_bool wait_to_end); extern int wsrep_wait_committing_connections_close(int wait_time); extern void wsrep_close_applier(THD *thd); diff --git a/sql/wsrep_thd.cc b/sql/wsrep_thd.cc index cd7359160d6..eb26da61282 100644 --- a/sql/wsrep_thd.cc +++ b/sql/wsrep_thd.cc @@ -676,25 +676,3 @@ bool wsrep_thd_has_explicit_locks(THD *thd) assert(thd); return thd->mdl_context.has_explicit_locks(); } - -/* - Get auto increment variables for THD. Use global settings for - applier threads. - */ -extern "C" -void wsrep_thd_auto_increment_variables(THD* thd, - unsigned long long* offset, - unsigned long long* increment) -{ - if (thd->wsrep_exec_mode == REPL_RECV && - thd->wsrep_conflict_state != REPLAYING) - { - *offset= global_system_variables.auto_increment_offset; - *increment= global_system_variables.auto_increment_increment; - } - else - { - *offset= thd->variables.auto_increment_offset; - *increment= thd->variables.auto_increment_increment; - } -} -- cgit v1.2.1