Commit fb4434ee authored by Yuchen Pei's avatar Yuchen Pei

MDEV-32157 MDEV-28856 Spider: Tests, documentation, small fixes and cleanups

Removed some redundant hint related string literals from
spd_db_conn.cc

Clean up SPIDER_PARAM_*_[CHAR]LEN[S]

Adding tests covering monitoring_kind=2. What it does is that it reads
from mysql.spider_link_mon_servers with matching db_name, table_name,
link_id, and does not do anything about that...

How monitoring_* can be useful: in the deprecated spider high
availability feature, when one remote fails, spider will try another
remote, which apparently makes use of these table parameters.

A test covering the query_cache_sync table param. Some further tests
on some spider table params.

Wrapper should be case insensitive.

Code documentation on spider priority binary tree.

Add an assertion that static_key_cardinality is always -1. All tests
pass still
parent 4d2fff63
...@@ -6934,6 +6934,10 @@ ha_rows ha_spider::records_in_range( ...@@ -6934,6 +6934,10 @@ ha_rows ha_spider::records_in_range(
dbton_id = share->sql_dbton_ids[search_link_idx]; dbton_id = share->sql_dbton_ids[search_link_idx];
dbton_hdl = dbton_handler[dbton_id]; dbton_hdl = dbton_handler[dbton_id];
crd_mode = dbton_hdl->crd_mode_exchange(crd_mode); crd_mode = dbton_hdl->crd_mode_exchange(crd_mode);
/* This assertion simply demonstrates that the
static_key_cardinality field is unused. It will be deprecated
(MDEV-28861) and removed (MDEV-31146). */
DBUG_ASSERT(share->static_key_cardinality[inx] == -1);
if (crd_mode == 1 || crd_mode == 2) if (crd_mode == 1 || crd_mode == 2)
{ {
DBUG_PRINT("info", ("spider static_key_cardinality[%u]=%lld", inx, DBUG_PRINT("info", ("spider static_key_cardinality[%u]=%lld", inx,
......
#
# MDEV-28856 Spider: Implement more engine-defined options
#
for master_1
for child2
for child3
CREATE SERVER srv FOREIGN DATA WRAPPER mysql
OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');
# testing monitoring_*
INSERT INTO mysql.spider_link_mon_servers
(db_name, table_name, link_id, sid, server) VALUES
('test', 't1', '0', 1, 'srv');
create table t1 (c int) ENGINE=Spider
COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", monitoring_kind "2"';
/* 1 */ insert into t1 values (42);
ERROR HY000: Table 'test.t2' get a problem
/* 2 */ insert into t1 values (42);
ERROR HY000: All links of 'test.t1' are failed
create table t2 (c int);
/* 3 */ insert into t1 values (42);
ERROR HY000: All links of 'test.t1' are failed
drop table t1, t2;
create table t1 (c int) ENGINE=Spider
COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", monitoring_bg_kind "2",
monitoring_bg_interval "500000"';
/* 4 */ insert into t1 values (42);
ERROR 42S02: Table 'test.t2' doesn't exist
drop table t1;
# testing query_cache_sync
create table t1 (c int) ENGINE=Spider
COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", query_cache_sync "3"';
create table t2 (c int);
/* 5 */ insert into t1 values (42);
select sql_cache * from t1;
c
42
select sql_no_cache * from t1;
c
42
drop table t1, t2;
# testing tgt_pk_names
create table t2 (c int);
create table t1 (c int, primary key (c)) ENGINE=Spider
COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"';
/* 6 */ insert ignore into t1 values (42), (42);
select * from t1;
c
42
42
drop table t1, t2;
create table t2 (c int, primary key (c));
create table t1 (c int) ENGINE=Spider
COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"';
/* 7 */ insert ignore into t1 values (42), (42);
Warnings:
Warning 1022 Can't write; duplicate key in table 't1'
select * from t1;
c
42
drop table t1, t2;
create table t2 (c int, primary key (c));
create table t1 (c int, primary key (c)) ENGINE=Spider
COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"';
/* 8 */ insert ignore into t1 values (42), (42);
Warnings:
Warning 1062 Duplicate entry '42' for key 'PRIMARY'
select * from t1;
c
42
drop table t1, t2;
create table t2 (c int, primary key (c));
create table t1 (c int, primary key (c)) ENGINE=Spider
COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", pk_name "c"';
/* 9 */ insert ignore into t1 values (42), (42);
Warnings:
Warning 1022 Can't write; duplicate key in table 't1'
select * from t1;
c
42
drop table t1, t2;
create table t2 (c int, unique key (c));
create table t1 (c int, primary key (c)) ENGINE=Spider
COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", pk_name "c"';
/* 9.1 */ insert ignore into t1 values (42), (42);
Warnings:
Warning 1062 Duplicate entry '42' for key 'PRIMARY'
select * from t1;
c
42
drop table t1, t2;
create table t2 (c int, unique key (c));
create table t1 (c int, key (c)) ENGINE=Spider
COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", pk_name "f"';
/* 10 */ insert ignore into t1 values (42), (42);
Warnings:
Warning 1062 Duplicate entry '42' for key 'c'
select * from t1;
c
42
drop table t1, t2;
create table t2 (c int, primary key (c));
create table t1 (c int, key (c)) ENGINE=Spider
COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", pk_name "blah"';
/* 11 */ insert ignore into t1 values (42), (42);
Warnings:
Warning 1022 Can't write; duplicate key in table 't1'
select * from t1;
c
42
drop table t1, t2;
create table t2 (c int, d int, unique key (c), unique key (d));
create table t1 (c int, d int, key (c), key (d)) ENGINE=Spider
COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", pk_name "blah"';
/* 12 */ insert ignore into t1 values (42, 43), (43, 43);
Warnings:
Warning 1062 Duplicate entry '43' for key 'd'
select * from t1;
c d
42 43
drop table t1, t2;
# Testing index hint
create table t2 (c int, d int, primary key (c), key (d));
show create table t2;
Table Create Table
t2 CREATE TABLE `t2` (
`c` int(11) NOT NULL,
`d` int(11) DEFAULT NULL,
PRIMARY KEY (`c`),
KEY `d` (`d`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
create table t1 (c int, d int, primary key (c), key (d)) ENGINE=Spider
COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", idx000 "f d"';
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`c` int(11) NOT NULL,
`d` int(11) DEFAULT NULL,
PRIMARY KEY (`c`),
KEY `d` (`d`)
) ENGINE=SPIDER DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", idx000 "f d"'
/* 13 */ insert into t1 values (42, 23), (37, 93);
select max(d) from t1;
max(d)
93
drop table t1, t2;
create table t2 (c int, d int, e int, primary key (c), key (d), unique key (e));
show create table t2;
Table Create Table
t2 CREATE TABLE `t2` (
`c` int(11) NOT NULL,
`d` int(11) DEFAULT NULL,
`e` int(11) DEFAULT NULL,
PRIMARY KEY (`c`),
UNIQUE KEY `e` (`e`),
KEY `d` (`d`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
create table t1 (c int, d int, e int, primary key (c), key (d), unique key (e)) ENGINE=Spider
COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", idx000 "f PRIMARY", idx001 "u d", idx002 "ig e"';
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`c` int(11) NOT NULL,
`d` int(11) DEFAULT NULL,
`e` int(11) DEFAULT NULL,
PRIMARY KEY (`c`),
UNIQUE KEY `e` (`e`),
KEY `d` (`d`)
) ENGINE=SPIDER DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", idx000 "f PRIMARY", idx001 "u d", idx002 "ig e"'
/* 14 */ insert into t1 values (42, 23, 89), (37, 93, 47);
select max(d) from t1;
max(d)
93
drop table t1, t2;
drop server srv;
for master_1
for child2
for child3
#
# end of test mdev_28856
#
--echo #
--echo # MDEV-28856 Spider: Implement more engine-defined options
--echo #
--disable_query_log
--disable_result_log
--source ../../t/test_init.inc
--enable_result_log
--enable_query_log
# This test covers some table params under consideration for inclusion
# in the engine-defined options to be implemented in MDEV-28856.
evalp CREATE SERVER srv FOREIGN DATA WRAPPER mysql
OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');
--echo # testing monitoring_*
INSERT INTO mysql.spider_link_mon_servers
(db_name, table_name, link_id, sid, server) VALUES
('test', 't1', '0', 1, 'srv');
create table t1 (c int) ENGINE=Spider
COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", monitoring_kind "2"';
--error 12511
/* 1 */ insert into t1 values (42);
--error 12514
/* 2 */ insert into t1 values (42);
create table t2 (c int);
# Even though the table is available now, we still get "all links
# failed" error
--error 12514
/* 3 */ insert into t1 values (42);
drop table t1, t2;
create table t1 (c int) ENGINE=Spider
COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", monitoring_bg_kind "2",
monitoring_bg_interval "500000"';
# The monitoring thread was killed before it could ping the remote
# table, so the error is not 12511 or 12514
--error ER_NO_SUCH_TABLE
/* 4 */ insert into t1 values (42);
drop table t1;
--echo # testing query_cache_sync
create table t1 (c int) ENGINE=Spider
COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", query_cache_sync "3"';
create table t2 (c int);
/* 5 */ insert into t1 values (42);
select sql_cache * from t1;
select sql_no_cache * from t1;
drop table t1, t2;
--echo # testing tgt_pk_names
# can insert duplicates...
create table t2 (c int);
create table t1 (c int, primary key (c)) ENGINE=Spider
COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"';
/* 6 */ insert ignore into t1 values (42), (42);
select * from t1;
drop table t1, t2;
# pk_names not used because no key declared in t1, 1022
create table t2 (c int, primary key (c));
create table t1 (c int) ENGINE=Spider
COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"';
/* 7 */ insert ignore into t1 values (42), (42);
select * from t1;
drop table t1, t2;
# pk_name is the default "PRIMARY", 1062
create table t2 (c int, primary key (c));
create table t1 (c int, primary key (c)) ENGINE=Spider
COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"';
/* 8 */ insert ignore into t1 values (42), (42);
select * from t1;
drop table t1, t2;
# key name c does not match PRIMARY, 1022
create table t2 (c int, primary key (c));
create table t1 (c int, primary key (c)) ENGINE=Spider
COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", pk_name "c"';
/* 9 */ insert ignore into t1 values (42), (42);
select * from t1;
drop table t1, t2;
# local primary key name c matches remote unique key name c, 1062 but
# warning says PRIMARY instead of c, because key->name is PRIMARY
# instead of c
create table t2 (c int, unique key (c));
create table t1 (c int, primary key (c)) ENGINE=Spider
COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", pk_name "c"';
/* 9.1 */ insert ignore into t1 values (42), (42);
select * from t1;
drop table t1, t2;
# key name f does not match t2 key name, but it is not used any way
# because there's no primary key, 1062
create table t2 (c int, unique key (c));
create table t1 (c int, key (c)) ENGINE=Spider
COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", pk_name "f"';
/* 10 */ insert ignore into t1 values (42), (42);
select * from t1;
drop table t1, t2;
# key name blah does not match t2 error key name PRIMARY, and the
# non-primary key-route does not return PRIMARY, 1022
create table t2 (c int, primary key (c));
create table t1 (c int, key (c)) ENGINE=Spider
COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", pk_name "blah"';
/* 11 */ insert ignore into t1 values (42), (42);
select * from t1;
drop table t1, t2;
# key name blah does not match t2 key name, but still 1062, because we
# go through the non-primary key route
create table t2 (c int, d int, unique key (c), unique key (d));
create table t1 (c int, d int, key (c), key (d)) ENGINE=Spider
COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", pk_name "blah"';
/* 12 */ insert ignore into t1 values (42, 43), (43, 43);
select * from t1;
drop table t1, t2;
--echo # Testing index hint
create table t2 (c int, d int, primary key (c), key (d));
show create table t2;
create table t1 (c int, d int, primary key (c), key (d)) ENGINE=Spider
COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", idx000 "f d"';
show create table t1;
/* 13 */ insert into t1 values (42, 23), (37, 93);
select max(d) from t1;
drop table t1, t2;
# multiple indices
create table t2 (c int, d int, e int, primary key (c), key (d), unique key (e));
show create table t2;
create table t1 (c int, d int, e int, primary key (c), key (d), unique key (e)) ENGINE=Spider
COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", idx000 "f PRIMARY", idx001 "u d", idx002 "ig e"';
show create table t1;
/* 14 */ insert into t1 values (42, 23, 89), (37, 93, 47);
select max(d) from t1;
drop table t1, t2;
drop server srv;
--disable_query_log
--disable_result_log
--source ../../t/test_deinit.inc
--enable_result_log
--enable_query_log
--echo #
--echo # end of test mdev_28856
--echo #
...@@ -1552,6 +1552,11 @@ void spider_conn_set_timeout_from_direct_sql( ...@@ -1552,6 +1552,11 @@ void spider_conn_set_timeout_from_direct_sql(
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
/**
Insert a connection to a binary tree ordered by priority
Starting from `top', find the correct spot for `conn' and insert it.
*/
void spider_tree_insert( void spider_tree_insert(
SPIDER_CONN *top, SPIDER_CONN *top,
SPIDER_CONN *conn SPIDER_CONN *conn
...@@ -1589,6 +1594,7 @@ void spider_tree_insert( ...@@ -1589,6 +1594,7 @@ void spider_tree_insert(
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
/* Returns the connection with the smallest priority in a tree */
SPIDER_CONN *spider_tree_first( SPIDER_CONN *spider_tree_first(
SPIDER_CONN *top SPIDER_CONN *top
) { ) {
...@@ -1604,6 +1610,7 @@ SPIDER_CONN *spider_tree_first( ...@@ -1604,6 +1610,7 @@ SPIDER_CONN *spider_tree_first(
DBUG_RETURN(current); DBUG_RETURN(current);
} }
/* Returns the connection with the biggest priority in a tree */
SPIDER_CONN *spider_tree_last( SPIDER_CONN *spider_tree_last(
SPIDER_CONN *top SPIDER_CONN *top
) { ) {
...@@ -1619,6 +1626,12 @@ SPIDER_CONN *spider_tree_last( ...@@ -1619,6 +1626,12 @@ SPIDER_CONN *spider_tree_last(
DBUG_RETURN(current); DBUG_RETURN(current);
} }
/*
Returns the next connection
Find the connection in the tree with the smallest priority that is
bigger than that of the current connection.
*/
SPIDER_CONN *spider_tree_next( SPIDER_CONN *spider_tree_next(
SPIDER_CONN *current SPIDER_CONN *current
) { ) {
......
...@@ -71,7 +71,7 @@ int spider_udf_set_copy_tables_param_default( ...@@ -71,7 +71,7 @@ int spider_udf_set_copy_tables_param_default(
DBUG_RETURN(0); DBUG_RETURN(0);
} }
#define SPIDER_PARAM_STR_LEN(name) name ## _length #define SPIDER_PARAM_LEN(name) name ## _length
#define SPIDER_PARAM_STR(title_name, param_name) \ #define SPIDER_PARAM_STR(title_name, param_name) \
if (!strncasecmp(parse.start_title, title_name, title_length)) \ if (!strncasecmp(parse.start_title, title_name, title_length)) \
{ \ { \
...@@ -80,8 +80,7 @@ int spider_udf_set_copy_tables_param_default( ...@@ -80,8 +80,7 @@ int spider_udf_set_copy_tables_param_default(
{ \ { \
if ((copy_tables->param_name = spider_create_string(parse.start_value, \ if ((copy_tables->param_name = spider_create_string(parse.start_value, \
value_length))) \ value_length))) \
copy_tables->SPIDER_PARAM_STR_LEN(param_name) = \ copy_tables->SPIDER_PARAM_LEN(param_name) = strlen(copy_tables->param_name); \
strlen(copy_tables->param_name); \
else { \ else { \
error_num= parse.fail(true); \ error_num= parse.fail(true); \
goto error; \ goto error; \
......
...@@ -51,12 +51,6 @@ extern SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE]; ...@@ -51,12 +51,6 @@ extern SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE];
#define SPIDER_SQL_COALESCE_LEN (sizeof(SPIDER_SQL_COALESCE_STR) - 1) #define SPIDER_SQL_COALESCE_LEN (sizeof(SPIDER_SQL_COALESCE_STR) - 1)
#define SPIDER_SQL_HEX_STR "0x" #define SPIDER_SQL_HEX_STR "0x"
#define SPIDER_SQL_HEX_LEN (sizeof(SPIDER_SQL_HEX_STR) - 1) #define SPIDER_SQL_HEX_LEN (sizeof(SPIDER_SQL_HEX_STR) - 1)
#define SPIDER_SQL_SQL_FORCE_IDX_STR " force index("
#define SPIDER_SQL_SQL_FORCE_IDX_LEN (sizeof(SPIDER_SQL_SQL_FORCE_IDX_STR) - 1)
#define SPIDER_SQL_SQL_USE_IDX_STR " use index("
#define SPIDER_SQL_SQL_USE_IDX_LEN (sizeof(SPIDER_SQL_SQL_USE_IDX_STR) - 1)
#define SPIDER_SQL_SQL_IGNORE_IDX_STR " ignore index("
#define SPIDER_SQL_SQL_IGNORE_IDX_LEN (sizeof(SPIDER_SQL_SQL_IGNORE_IDX_STR) - 1)
#define SPIDER_SQL_SET_NAMES_STR "set names " #define SPIDER_SQL_SET_NAMES_STR "set names "
#define SPIDER_SQL_SET_NAMES_LEN sizeof(SPIDER_SQL_SET_NAMES_STR) - 1 #define SPIDER_SQL_SET_NAMES_LEN sizeof(SPIDER_SQL_SET_NAMES_STR) - 1
...@@ -1484,34 +1478,37 @@ int spider_db_append_key_hint( ...@@ -1484,34 +1478,37 @@ int spider_db_append_key_hint(
if (hint_str_len >= 2 && if (hint_str_len >= 2 &&
(hint_str[0] == 'f' || hint_str[0] == 'F') && hint_str[1] == ' ' (hint_str[0] == 'f' || hint_str[0] == 'F') && hint_str[1] == ' '
) { ) {
if (str->reserve(hint_str_len - 2 + if (str->reserve(
SPIDER_SQL_SQL_FORCE_IDX_LEN + SPIDER_SQL_CLOSE_PAREN_LEN)) hint_str_len - 2 + SPIDER_SQL_INDEX_FORCE_LEN +
SPIDER_SQL_OPEN_PAREN_LEN + SPIDER_SQL_CLOSE_PAREN_LEN))
DBUG_RETURN(HA_ERR_OUT_OF_MEM); DBUG_RETURN(HA_ERR_OUT_OF_MEM);
hint_str += 2; hint_str += 2;
str->q_append(SPIDER_SQL_SQL_FORCE_IDX_STR, SPIDER_SQL_SQL_FORCE_IDX_LEN); str->q_append(SPIDER_SQL_INDEX_FORCE_STR, SPIDER_SQL_INDEX_FORCE_LEN);
str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN);
str->q_append(hint_str, hint_str_len - 2); str->q_append(hint_str, hint_str_len - 2);
str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN);
} else if (hint_str_len >= 2 && } else if (hint_str_len >= 2 &&
(hint_str[0] == 'u' || hint_str[0] == 'U') && hint_str[1] == ' ' (hint_str[0] == 'u' || hint_str[0] == 'U') && hint_str[1] == ' '
) { ) {
if (str->reserve(hint_str_len - 2 + if (str->reserve(
SPIDER_SQL_SQL_USE_IDX_LEN + SPIDER_SQL_CLOSE_PAREN_LEN)) hint_str_len - 2 + SPIDER_SQL_INDEX_USE_LEN +
DBUG_RETURN(HA_ERR_OUT_OF_MEM); SPIDER_SQL_OPEN_PAREN_LEN + SPIDER_SQL_CLOSE_PAREN_LEN))
hint_str += 2; hint_str += 2;
str->q_append(SPIDER_SQL_SQL_USE_IDX_STR, SPIDER_SQL_SQL_USE_IDX_LEN); str->q_append(SPIDER_SQL_INDEX_USE_STR, SPIDER_SQL_INDEX_USE_LEN);
str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN);
str->q_append(hint_str, hint_str_len - 2); str->q_append(hint_str, hint_str_len - 2);
str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN);
} else if (hint_str_len >= 3 && } else if (hint_str_len >= 3 &&
(hint_str[0] == 'i' || hint_str[0] == 'I') && (hint_str[0] == 'i' || hint_str[0] == 'I') &&
(hint_str[1] == 'g' || hint_str[1] == 'G') && hint_str[2] == ' ' (hint_str[1] == 'g' || hint_str[1] == 'G') && hint_str[2] == ' '
) { ) {
if (str->reserve(hint_str_len - 3 + if (str->reserve(
SPIDER_SQL_SQL_IGNORE_IDX_LEN + SPIDER_SQL_CLOSE_PAREN_LEN)) hint_str_len - 3 + SPIDER_SQL_INDEX_IGNORE_LEN +
DBUG_RETURN(HA_ERR_OUT_OF_MEM); SPIDER_SQL_OPEN_PAREN_LEN + SPIDER_SQL_CLOSE_PAREN_LEN))
hint_str += 3; hint_str += 3;
str->q_append( str->q_append(SPIDER_SQL_INDEX_IGNORE_STR, SPIDER_SQL_INDEX_IGNORE_LEN);
SPIDER_SQL_SQL_IGNORE_IDX_STR, SPIDER_SQL_SQL_IGNORE_IDX_LEN); str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN);
str->q_append(hint_str, hint_str_len - 3); str->q_append(hint_str, hint_str_len - 2);
str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN);
} else if (str->reserve(hint_str_len + SPIDER_SQL_SPACE_LEN)) } else if (str->reserve(hint_str_len + SPIDER_SQL_SPACE_LEN))
DBUG_RETURN(HA_ERR_OUT_OF_MEM); DBUG_RETURN(HA_ERR_OUT_OF_MEM);
......
...@@ -814,7 +814,7 @@ int spider_udf_direct_sql_get_server( ...@@ -814,7 +814,7 @@ int spider_udf_direct_sql_get_server(
DBUG_RETURN(error_num); DBUG_RETURN(error_num);
} }
#define SPIDER_PARAM_STR_LEN(name) name ## _length #define SPIDER_PARAM_LEN(name) name ## _length
#define SPIDER_PARAM_STR(title_name, param_name) \ #define SPIDER_PARAM_STR(title_name, param_name) \
if (!strncasecmp(parse.start_title, title_name, title_length)) \ if (!strncasecmp(parse.start_title, title_name, title_length)) \
{ \ { \
...@@ -823,7 +823,7 @@ int spider_udf_direct_sql_get_server( ...@@ -823,7 +823,7 @@ int spider_udf_direct_sql_get_server(
{ \ { \
if ((direct_sql->param_name = spider_create_string(parse.start_value, \ if ((direct_sql->param_name = spider_create_string(parse.start_value, \
value_length))) \ value_length))) \
direct_sql->SPIDER_PARAM_STR_LEN(param_name) = strlen(direct_sql->param_name); \ direct_sql->SPIDER_PARAM_LEN(param_name) = strlen(direct_sql->param_name); \
else { \ else { \
error_num= parse.fail(true); \ error_num= parse.fail(true); \
goto error; \ goto error; \
......
...@@ -364,9 +364,18 @@ typedef struct st_spider_conn ...@@ -364,9 +364,18 @@ typedef struct st_spider_conn
THD *thd; THD *thd;
void *another_ha_first; void *another_ha_first;
void *another_ha_last; void *another_ha_last;
/* Exactly one of p_small and p_big is not null */
/* The parent node in the binary tree ordered by priority with a
smaller or equal priority */
st_spider_conn *p_small; st_spider_conn *p_small;
/* The parent node in the binary tree ordered by priority with a
bigger priority */
st_spider_conn *p_big; st_spider_conn *p_big;
/* The child node in the binary tree ordered by priority with a
smaller priority */
st_spider_conn *c_small; st_spider_conn *c_small;
/* The child node in the binary tree ordered by priority with a
bigger or equal priority */
st_spider_conn *c_big; st_spider_conn *c_big;
longlong priority; longlong priority;
bool server_lost; bool server_lost;
......
...@@ -1595,7 +1595,9 @@ static int spider_set_ll_value( ...@@ -1595,7 +1595,9 @@ static int spider_set_ll_value(
DBUG_RETURN(error_num); DBUG_RETURN(error_num);
} }
#define SPIDER_PARAM_STR_LEN(name) name ## _length #define SPIDER_PARAM_LEN(name) name ## _length
#define SPIDER_PARAM_LENS(name) name ## _lengths
#define SPIDER_PARAM_CHARLEN(name) name ## _charlen
#define SPIDER_PARAM_STR(title_name, param_name) \ #define SPIDER_PARAM_STR(title_name, param_name) \
if (!strncasecmp(parse.start_title, title_name, title_length)) \ if (!strncasecmp(parse.start_title, title_name, title_length)) \
{ \ { \
...@@ -1604,7 +1606,7 @@ static int spider_set_ll_value( ...@@ -1604,7 +1606,7 @@ static int spider_set_ll_value(
{ \ { \
if ((share->param_name = spider_create_string(parse.start_value, \ if ((share->param_name = spider_create_string(parse.start_value, \
value_length))) \ value_length))) \
share->SPIDER_PARAM_STR_LEN(param_name) = strlen(share->param_name); \ share->SPIDER_PARAM_LEN(param_name) = strlen(share->param_name); \
else { \ else { \
error_num= parse.fail(true); \ error_num= parse.fail(true); \
goto error; \ goto error; \
...@@ -1613,8 +1615,6 @@ static int spider_set_ll_value( ...@@ -1613,8 +1615,6 @@ static int spider_set_ll_value(
} \ } \
break; \ break; \
} }
#define SPIDER_PARAM_STR_LENS(name) name ## _lengths
#define SPIDER_PARAM_STR_CHARLEN(name) name ## _charlen
#define SPIDER_PARAM_STR_LIST(title_name, param_name) \ #define SPIDER_PARAM_STR_LIST(title_name, param_name) \
SPIDER_PARAM_STR_LIST_CHECK(title_name, param_name, FALSE) SPIDER_PARAM_STR_LIST_CHECK(title_name, param_name, FALSE)
#define SPIDER_PARAM_STR_LIST_CHECK(title_name, param_name, already_set) \ #define SPIDER_PARAM_STR_LIST_CHECK(title_name, param_name, already_set) \
...@@ -1628,16 +1628,16 @@ static int spider_set_ll_value( ...@@ -1628,16 +1628,16 @@ static int spider_set_ll_value(
} \ } \
if (!share->param_name) \ if (!share->param_name) \
{ \ { \
share->SPIDER_PARAM_STR_CHARLEN(param_name)= value_length; \ share->SPIDER_PARAM_CHARLEN(param_name)= value_length; \
if ((error_num= spider_create_string_list( \ if ((error_num= spider_create_string_list( \
&share->param_name, \ &share->param_name, \
&share->SPIDER_PARAM_STR_LENS(param_name), \ &share->SPIDER_PARAM_LENS(param_name), \
&share->SPIDER_PARAM_STR_LEN(param_name), \ &share->SPIDER_PARAM_LEN(param_name), \
parse.start_value, \ parse.start_value, \
share->SPIDER_PARAM_STR_CHARLEN(param_name)))) \ share->SPIDER_PARAM_CHARLEN(param_name)))) \
goto error; \ goto error; \
THD *thd= current_thd; \ THD *thd= current_thd; \
if (share->SPIDER_PARAM_STR_LEN(param_name) > 1 && create_table) \ if (share->SPIDER_PARAM_LEN(param_name) > 1 && create_table) \
{ \ { \
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, \ push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, \
HA_ERR_UNSUPPORTED, \ HA_ERR_UNSUPPORTED, \
...@@ -1703,7 +1703,6 @@ static int spider_set_ll_value( ...@@ -1703,7 +1703,6 @@ static int spider_set_ll_value(
} \ } \
break; \ break; \
} }
#define SPIDER_PARAM_LONG_LEN(name) name ## _length
#define SPIDER_PARAM_LONG_LIST_WITH_MAX(title_name, param_name, \ #define SPIDER_PARAM_LONG_LIST_WITH_MAX(title_name, param_name, \
min_val, max_val) \ min_val, max_val) \
if (!strncasecmp(parse.start_title, title_name, title_length)) \ if (!strncasecmp(parse.start_title, title_name, title_length)) \
...@@ -1713,7 +1712,7 @@ static int spider_set_ll_value( ...@@ -1713,7 +1712,7 @@ static int spider_set_ll_value(
{ \ { \
if ((error_num = spider_create_long_list( \ if ((error_num = spider_create_long_list( \
&share->param_name, \ &share->param_name, \
&share->SPIDER_PARAM_LONG_LEN(param_name), \ &share->SPIDER_PARAM_LEN(param_name), \
parse.start_value, \ parse.start_value, \
value_length, \ value_length, \
min_val, max_val))) \ min_val, max_val))) \
...@@ -1721,7 +1720,6 @@ static int spider_set_ll_value( ...@@ -1721,7 +1720,6 @@ static int spider_set_ll_value(
} \ } \
break; \ break; \
} }
#define SPIDER_PARAM_LONGLONG_LEN(name) name ## _length
#define SPIDER_PARAM_LONGLONG_LIST_WITH_MAX(title_name, param_name, \ #define SPIDER_PARAM_LONGLONG_LIST_WITH_MAX(title_name, param_name, \
min_val, max_val) \ min_val, max_val) \
if (!strncasecmp(parse.start_title, title_name, title_length)) \ if (!strncasecmp(parse.start_title, title_name, title_length)) \
...@@ -1731,7 +1729,7 @@ static int spider_set_ll_value( ...@@ -1731,7 +1729,7 @@ static int spider_set_ll_value(
{ \ { \
if ((error_num = spider_create_longlong_list( \ if ((error_num = spider_create_longlong_list( \
&share->param_name, \ &share->param_name, \
&share->SPIDER_PARAM_LONGLONG_LEN(param_name), \ &share->SPIDER_PARAM_LEN(param_name), \
parse.start_value, \ parse.start_value, \
value_length, \ value_length, \
min_val, max_val))) \ min_val, max_val))) \
...@@ -1808,21 +1806,25 @@ static int spider_set_ll_value( ...@@ -1808,21 +1806,25 @@ static int spider_set_ll_value(
/* /*
Set a given engine-defined option, which holds a string list, to the Set a given engine-defined option, which holds a string list, to the
corresponding attribute of SPIDER_SHARE. corresponding attribute of SPIDER_SHARE.
*/ */
#define SPIDER_OPTION_STR_LIST(title_name, option_name, param_name) \ #define SPIDER_OPTION_STR_LIST(title_name, option_name, param_name) \
if (option_struct && option_struct->option_name) \ if (option_struct && option_struct->option_name) \
{ \ { \
DBUG_PRINT("info", ("spider " title_name " start overwrite")); \ DBUG_PRINT("info", ("spider " title_name " start overwrite")); \
share->SPIDER_PARAM_STR_CHARLEN(param_name)= \ share->SPIDER_PARAM_CHARLEN(param_name)= \
strlen(option_struct->option_name); \ strlen(option_struct->option_name); \
if ((error_num= spider_create_string_list( \ if ((error_num= spider_create_string_list( \
&share->param_name, &share->SPIDER_PARAM_STR_LENS(param_name), \ &share->param_name, &share->SPIDER_PARAM_LENS(param_name), \
&share->SPIDER_PARAM_STR_LEN(param_name), \ &share->SPIDER_PARAM_LEN(param_name), \
option_struct->option_name, \ option_struct->option_name, \
share->SPIDER_PARAM_STR_CHARLEN(param_name)))) \ share->SPIDER_PARAM_CHARLEN(param_name)))) \
goto error; \ goto error; \
} }
/**
Assign -1 to some `SPIDER_SHARE' numeric fields, to indicate they
have not been specified by the user yet.
*/
static void spider_minus_1(SPIDER_SHARE *share, TABLE_SHARE *table_share) static void spider_minus_1(SPIDER_SHARE *share, TABLE_SHARE *table_share)
{ {
share->sts_bg_mode = -1; share->sts_bg_mode = -1;
...@@ -2160,6 +2162,8 @@ int spider_parse_connect_info( ...@@ -2160,6 +2162,8 @@ int spider_parse_connect_info(
("spider s->normalized_path=%s", table_share->normalized_path.str)); ("spider s->normalized_path=%s", table_share->normalized_path.str));
spider_get_partition_info(share->table_name, share->table_name_length, spider_get_partition_info(share->table_name, share->table_name_length,
table_share, part_info, &part_elem, &sub_elem); table_share, part_info, &part_elem, &sub_elem);
/* Find the correct table options, depending on if we are parsing a
table, a partition, or a sub-partition. */
if (part_info) if (part_info)
if (part_info->is_sub_partitioned()) if (part_info->is_sub_partitioned())
option_struct= sub_elem->option_struct; option_struct= sub_elem->option_struct;
...@@ -2176,6 +2180,7 @@ int spider_parse_connect_info( ...@@ -2176,6 +2180,7 @@ int spider_parse_connect_info(
connect_string = NULL; connect_string = NULL;
} }
/* Get the correct connect info for the current level. */
int error_num_1 = spider_get_connect_info(i, part_elem, sub_elem, int error_num_1 = spider_get_connect_info(i, part_elem, sub_elem,
table_share, connect_string); table_share, connect_string);
if (error_num_1 == 1) if (error_num_1 == 1)
...@@ -3168,7 +3173,7 @@ int spider_parse_connect_info( ...@@ -3168,7 +3173,7 @@ int spider_parse_connect_info(
{ {
if ( if (
spider_dbton[roop_count2].wrapper && spider_dbton[roop_count2].wrapper &&
!strcmp(share->tgt_wrappers[roop_count], !strcasecmp(share->tgt_wrappers[roop_count],
spider_dbton[roop_count2].wrapper) spider_dbton[roop_count2].wrapper)
) { ) {
break; break;
...@@ -4002,7 +4007,7 @@ int spider_create_conn_keys( ...@@ -4002,7 +4007,7 @@ int spider_create_conn_keys(
spider_dbton[dbton_idx].wrapper : "NULL")); spider_dbton[dbton_idx].wrapper : "NULL"));
if ( if (
spider_dbton[dbton_idx].wrapper && spider_dbton[dbton_idx].wrapper &&
!strcmp(share->tgt_wrappers[all_link_idx], !strcasecmp(share->tgt_wrappers[all_link_idx],
spider_dbton[dbton_idx].wrapper) spider_dbton[dbton_idx].wrapper)
) { ) {
spider_set_bit(share->dbton_bitmap, dbton_idx); spider_set_bit(share->dbton_bitmap, dbton_idx);
......
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