Commit e1d31a10 authored by Yuchen Pei's avatar Yuchen Pei

MDEV-31524 Fixing spider table param / variable overriding

The existing (incorrect) overriding mechanism is:

Non-minus-one var value overrides table param overrides default value.

Before MDEV-27169, unspecified var value is -1. So if the user sets
both the var to be a value other than -1 and the table param, the var
value will prevail, which is incorrect.

After MDEV-27169, unspecified var value is default value. So if the
user does not set the var but sets the table param, the default value
will prevail, which is even more incorrect.

This patch fixes it so that table param, if specified, always
overrides var value, and the latter if not specified or set to -1,
falls back to the default value

We achieve this by replacing all such overriding in spd_param.cc with
macros that override in the correct way, and removing all the
"overriding -1" lines involving table params in
spider_set_connect_info_default() except for those table params not
defined as sysvar/thdvar in spd_params.cc

We also introduced macros for non-overriding sysvar and thdvar, so
that the code is cleaner and less error-prone

In server versions where MDEV-27169 has not been applied, we also
backport the patch, that is, replacing -1 default values with real
default values

In server versions where MDEV-28006 has not been applied, we do the
same for udf params
parent 7dde504a
MDEV-31524 Spider variables that double as table params overriding mechanism is buggy
for master_1
for child2
for child3
SET @old_spider_read_only_mode = @@session.spider_read_only_mode;
CREATE SERVER $srv FOREIGN DATA WRAPPER MYSQL OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');
set session spider_read_only_mode = default;
create table t2 (c int);
create table t1 (c int) ENGINE=Spider COMMENT='WRAPPER "mysql", srv "srv_mdev_31524",TABLE "t2"';
/* 1 */ insert into t1 values (42);
drop table t1, t2;
set session spider_read_only_mode = 1;
create table t2 (c int);
create table t1 (c int) ENGINE=Spider COMMENT='WRAPPER "mysql", srv "srv_mdev_31524",TABLE "t2"';
/* 2 */ insert into t1 values (42);
ERROR HY000: Table 'test.t1' is read only
drop table t1, t2;
set session spider_read_only_mode = -1;
create table t2 (c int);
create table t1 (c int) ENGINE=Spider COMMENT='WRAPPER "mysql", srv "srv_mdev_31524",TABLE "t2"';
/* 3 */ insert into t1 values (42);
drop table t1, t2;
SET session spider_read_only_mode = default;
create table t2 (c int);
create table t1 (c int) ENGINE=Spider COMMENT='read_only_mode "1", WRAPPER "mysql", srv "srv_mdev_31524",TABLE "t2"';
/* 4 */ insert into t1 values (42);
ERROR HY000: Table 'test.t1' is read only
drop table t1, t2;
set session spider_read_only_mode = 1;
create table t2 (c int);
create table t1 (c int) ENGINE=Spider COMMENT='read_only_mode "0", WRAPPER "mysql", srv "srv_mdev_31524",TABLE "t2"';
/* 5 */ insert into t1 values (42);
drop table t1, t2;
SET session spider_read_only_mode = -1;
create table t2 (c int);
create table t1 (c int) ENGINE=Spider COMMENT='read_only_mode "1", WRAPPER "mysql", srv "srv_mdev_31524",TABLE "t2"';
/* 6 */ insert into t1 values (42);
ERROR HY000: Table 'test.t1' is read only
drop table t1, t2;
drop server srv_mdev_31524;
SET session spider_read_only_mode = @old_spider_read_only_mode;
for master_1
for child2
for child3
--echo
--echo MDEV-31524 Spider variables that double as table params overriding mechanism is buggy
--echo
--disable_query_log
--disable_result_log
--source ../../t/test_init.inc
--enable_result_log
--enable_query_log
--let $srv=srv_mdev_31524
SET @old_spider_read_only_mode = @@session.spider_read_only_mode;
evalp CREATE SERVER $srv FOREIGN DATA WRAPPER MYSQL OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');
# when the user does not set var nor the table option, the default
# value (0 in this case) takes effect.
set session spider_read_only_mode = default;
create table t2 (c int);
eval create table t1 (c int) ENGINE=Spider COMMENT='WRAPPER "mysql", srv "$srv",TABLE "t2"';
/* 1 */ insert into t1 values (42);
drop table t1, t2;
# when the user sets var but not the table option, the var should be
# take effect.
set session spider_read_only_mode = 1;
create table t2 (c int);
eval create table t1 (c int) ENGINE=Spider COMMENT='WRAPPER "mysql", srv "$srv",TABLE "t2"';
--error 12518
/* 2 */ insert into t1 values (42);
drop table t1, t2;
# when the user sets var to -1 and does not set the table option, the
# default value takes effect.
set session spider_read_only_mode = -1;
create table t2 (c int);
eval create table t1 (c int) ENGINE=Spider COMMENT='WRAPPER "mysql", srv "$srv",TABLE "t2"';
/* 3 */ insert into t1 values (42);
drop table t1, t2;
# when the user does not set the var, but sets the table option, the
# table option should take effect
SET session spider_read_only_mode = default;
create table t2 (c int);
eval create table t1 (c int) ENGINE=Spider COMMENT='read_only_mode "1", WRAPPER "mysql", srv "$srv",TABLE "t2"';
--error 12518
/* 4 */ insert into t1 values (42);
drop table t1, t2;
# when the user sets both var and table option, the table option
# should take precedence
set session spider_read_only_mode = 1;
create table t2 (c int);
eval create table t1 (c int) ENGINE=Spider COMMENT='read_only_mode "0", WRAPPER "mysql", srv "$srv",TABLE "t2"';
/* 5 */ insert into t1 values (42);
drop table t1, t2;
# when the user sets the var to -1 and sets the table option, the
# table option should take effect
SET session spider_read_only_mode = -1;
create table t2 (c int);
eval create table t1 (c int) ENGINE=Spider COMMENT='read_only_mode "1", WRAPPER "mysql", srv "$srv",TABLE "t2"';
--error 12518
/* 6 */ insert into t1 values (42);
drop table t1, t2;
eval drop server $srv;
SET session spider_read_only_mode = @old_spider_read_only_mode;
--disable_query_log
--disable_result_log
--source ../../t/test_deinit.inc
--enable_result_log
--enable_query_log
......@@ -64,12 +64,6 @@ int spider_udf_set_copy_tables_param_default(
}
}
if (copy_tables->bulk_insert_interval == -1)
copy_tables->bulk_insert_interval = 10;
if (copy_tables->bulk_insert_rows == -1)
copy_tables->bulk_insert_rows = 100;
if (copy_tables->use_table_charset == -1)
copy_tables->use_table_charset = 1;
if (copy_tables->use_transaction == -1)
copy_tables->use_transaction = 1;
#ifndef WITHOUT_SPIDER_BG_SEARCH
......
......@@ -11559,7 +11559,7 @@ int spider_db_udf_copy_tables(
error_num = result->get_errno();
if (error_num == HA_ERR_END_OF_FILE)
{
if (roop_count < copy_tables->bulk_insert_rows)
if (roop_count < bulk_insert_rows)
{
end_of_file = TRUE;
if (roop_count)
......@@ -11583,8 +11583,6 @@ int spider_db_udf_copy_tables(
pthread_mutex_unlock(&tmp_conn->mta_conn_mutex);
goto error_db_query;
}
bulk_insert_rows = spider_param_udf_ct_bulk_insert_rows(
copy_tables->bulk_insert_rows);
if (
select_ct->append_key_order_str(key_info, 0, FALSE) ||
select_ct->append_limit(0, bulk_insert_rows) ||
......
......@@ -1451,25 +1451,10 @@ int spider_udf_set_direct_sql_param_default(
}
}
if (direct_sql->table_loop_mode == -1)
direct_sql->table_loop_mode = 0;
if (direct_sql->priority == -1)
direct_sql->priority = 1000000;
if (direct_sql->connect_timeout == -1)
direct_sql->connect_timeout = 6;
if (direct_sql->net_read_timeout == -1)
direct_sql->net_read_timeout = 600;
if (direct_sql->net_write_timeout == -1)
direct_sql->net_write_timeout = 600;
if (direct_sql->bulk_insert_rows == -1)
direct_sql->bulk_insert_rows = 3000;
if (direct_sql->connection_channel == -1)
direct_sql->connection_channel = 0;
#if MYSQL_VERSION_ID < 50500
#else
if (direct_sql->use_real_table == -1)
direct_sql->use_real_table = 0;
#endif
if (direct_sql->error_rw_mode == -1)
direct_sql->error_rw_mode = 0;
for (roop_count = 0; roop_count < direct_sql->table_count; roop_count++)
......
This diff is collapsed.
......@@ -3700,10 +3700,6 @@ int spider_set_connect_info_default(
#endif
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
if (share->use_hs_reads[roop_count] == -1)
share->use_hs_reads[roop_count] = 0;
if (share->use_hs_writes[roop_count] == -1)
share->use_hs_writes[roop_count] = 0;
if (share->hs_read_ports[roop_count] == -1)
{
share->hs_read_ports[roop_count] = 9998;
......@@ -3735,154 +3731,24 @@ int spider_set_connect_info_default(
share->hs_write_to_reads[roop_count] = 1;
}
#endif
if (share->use_handlers[roop_count] == -1)
share->use_handlers[roop_count] = 0;
if (share->connect_timeouts[roop_count] == -1)
share->connect_timeouts[roop_count] = 6;
if (share->net_read_timeouts[roop_count] == -1)
share->net_read_timeouts[roop_count] = 600;
if (share->net_write_timeouts[roop_count] == -1)
share->net_write_timeouts[roop_count] = 600;
if (share->access_balances[roop_count] == -1)
share->access_balances[roop_count] = 100;
if (share->bka_table_name_types[roop_count] == -1)
share->bka_table_name_types[roop_count] = 0;
}
#ifndef WITHOUT_SPIDER_BG_SEARCH
if (share->sts_bg_mode == -1)
share->sts_bg_mode = 2;
#endif
if (share->sts_interval == -1)
share->sts_interval = 10;
if (share->sts_mode == -1)
share->sts_mode = 1;
#ifdef WITH_PARTITION_STORAGE_ENGINE
if (share->sts_sync == -1)
share->sts_sync = 0;
#endif
if (share->store_last_sts == -1)
share->store_last_sts = 1;
if (share->load_sts_at_startup == -1)
share->load_sts_at_startup = 1;
#ifndef WITHOUT_SPIDER_BG_SEARCH
if (share->crd_bg_mode == -1)
share->crd_bg_mode = 2;
#endif
if (share->crd_interval == -1)
share->crd_interval = 51;
if (share->crd_mode == -1)
share->crd_mode = 1;
#ifdef WITH_PARTITION_STORAGE_ENGINE
if (share->crd_sync == -1)
share->crd_sync = 0;
#endif
if (share->store_last_crd == -1)
share->store_last_crd = 1;
if (share->load_crd_at_startup == -1)
share->load_crd_at_startup = 1;
if (share->crd_type == -1)
share->crd_type = 2;
if (share->crd_weight == -1)
share->crd_weight = 2;
if (share->internal_offset == -1)
share->internal_offset = 0;
if (share->internal_limit == -1)
share->internal_limit = 9223372036854775807LL;
if (share->split_read == -1)
share->split_read = 9223372036854775807LL;
if (share->semi_split_read == -1)
share->semi_split_read = 2;
if (share->semi_split_read_limit == -1)
share->semi_split_read_limit = 9223372036854775807LL;
if (share->init_sql_alloc_size == -1)
share->init_sql_alloc_size = 1024;
if (share->reset_sql_alloc == -1)
share->reset_sql_alloc = 1;
if (share->multi_split_read == -1)
share->multi_split_read = 100;
if (share->max_order == -1)
share->max_order = 32767;
if (share->semi_table_lock == -1)
share->semi_table_lock = 0;
if (share->semi_table_lock_conn == -1)
share->semi_table_lock_conn = 1;
if (share->selupd_lock_mode == -1)
share->selupd_lock_mode = 1;
if (share->query_cache == -1)
share->query_cache = 0;
if (share->query_cache_sync == -1)
share->query_cache_sync = 0;
if (share->bulk_size == -1)
share->bulk_size = 16000;
if (share->bulk_update_mode == -1)
share->bulk_update_mode = 0;
if (share->bulk_update_size == -1)
share->bulk_update_size = 16000;
if (share->internal_optimize == -1)
share->internal_optimize = 0;
if (share->internal_optimize_local == -1)
share->internal_optimize_local = 0;
if (share->scan_rate == -1)
share->scan_rate = 1;
if (share->read_rate == -1)
share->read_rate = 0.0002;
if (share->priority == -1)
share->priority = 1000000;
if (share->quick_mode == -1)
share->quick_mode = 3;
if (share->quick_page_size == -1)
share->quick_page_size = 1024;
if (share->quick_page_byte == -1)
share->quick_page_byte = 10485760;
if (share->low_mem_read == -1)
share->low_mem_read = 1;
if (share->table_count_mode == -1)
share->table_count_mode = 0;
if (share->select_column_mode == -1)
share->select_column_mode = 1;
#ifndef WITHOUT_SPIDER_BG_SEARCH
if (share->bgs_mode == -1)
share->bgs_mode = 0;
if (share->bgs_first_read == -1)
share->bgs_first_read = 2;
if (share->bgs_second_read == -1)
share->bgs_second_read = 100;
#endif
if (share->first_read == -1)
share->first_read = 0;
if (share->second_read == -1)
share->second_read = 0;
if (share->auto_increment_mode == -1)
share->auto_increment_mode = 0;
if (share->use_table_charset == -1)
share->use_table_charset = 1;
if (share->use_pushdown_udf == -1)
share->use_pushdown_udf = 1;
if (share->skip_default_condition == -1)
share->skip_default_condition = 0;
if (share->skip_parallel_search == -1)
share->skip_parallel_search = 0;
if (share->direct_dup_insert == -1)
share->direct_dup_insert = 0;
if (share->direct_order_limit == -1)
share->direct_order_limit = 9223372036854775807LL;
if (share->read_only_mode == -1)
share->read_only_mode = 0;
if (share->error_read_mode == -1)
share->error_read_mode = 0;
if (share->error_write_mode == -1)
share->error_write_mode = 0;
if (share->active_link_count == -1)
share->active_link_count = share->all_link_count;
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
if (share->hs_result_free_size == -1)
share->hs_result_free_size = 1048576;
#endif
#ifdef HA_CAN_BULK_ACCESS
if (share->bulk_access_free == -1)
share->bulk_access_free = 0;
#endif
#ifdef HA_CAN_FORCE_BULK_UPDATE
if (share->force_bulk_update == -1)
share->force_bulk_update = 0;
......@@ -3891,18 +3757,6 @@ int spider_set_connect_info_default(
if (share->force_bulk_delete == -1)
share->force_bulk_delete = 0;
#endif
if (share->casual_read == -1)
share->casual_read = 0;
if (share->delete_all_rows_type == -1)
{
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
share->delete_all_rows_type = 1;
#else
share->delete_all_rows_type = 0;
#endif
}
if (share->bka_mode == -1)
share->bka_mode = 1;
if (!share->bka_engine)
{
DBUG_PRINT("info",("spider create default bka_engine"));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment