Commit 18d3f63a authored by Yuchen Pei's avatar Yuchen Pei

MDEV-32627 Spider: use CONNECTION string in SQLDriverConnect

This is the CS part of the implementation of MENT-2070.
parent fea36b19
...@@ -237,7 +237,7 @@ set session spider_suppress_comment_ignored_warning=0; ...@@ -237,7 +237,7 @@ set session spider_suppress_comment_ignored_warning=0;
CREATE TABLE tbl_a (a INT) ENGINE=Spider DEFAULT CHARSET=utf8 CREATE TABLE tbl_a (a INT) ENGINE=Spider DEFAULT CHARSET=utf8
REMOTE_TABLE=t CONNECTION="srv s_2_1"; REMOTE_TABLE=t CONNECTION="srv s_2_1";
Warnings: Warnings:
Warning 12529 The table or partition COMMENT or CONNECTION string 'srv s_2_1' is not used as connection info because spider_ignore_comment is 1 or at least one table option has been specified Warning 12529 The table or partition COMMENT or CONNECTION string 'srv s_2_1' is not parsed for table params because spider_ignore_comment is 1 or at least one table option has been specified
drop table tbl_a; drop table tbl_a;
CREATE TABLE tbl_a ( CREATE TABLE tbl_a (
a INT, a INT,
...@@ -411,7 +411,7 @@ PARTITION p2 VALUES LESS THAN MAXVALUE REMOTE_SERVER="s_2_2" ...@@ -411,7 +411,7 @@ PARTITION p2 VALUES LESS THAN MAXVALUE REMOTE_SERVER="s_2_2"
Warnings: Warnings:
Warning 138 Spider table params in COMMENT or CONNECTION strings have been deprecated and will be removed in a future release. Please use table options instead. Warning 138 Spider table params in COMMENT or CONNECTION strings have been deprecated and will be removed in a future release. Please use table options instead.
Warning 138 Spider table params in COMMENT or CONNECTION strings have been deprecated and will be removed in a future release. Please use table options instead. Warning 138 Spider table params in COMMENT or CONNECTION strings have been deprecated and will be removed in a future release. Please use table options instead.
Warning 12529 The table or partition COMMENT or CONNECTION string 'tbl "tbl_a"' is not used as connection info because spider_ignore_comment is 1 or at least one table option has been specified Warning 12529 The table or partition COMMENT or CONNECTION string 'tbl "tbl_a"' is not parsed for table params because spider_ignore_comment is 1 or at least one table option has been specified
INSERT INTO tbl_a VALUES (1, "aaa"), (2, "bbb"), (3, "ccc"), (4, "ddd"); INSERT INTO tbl_a VALUES (1, "aaa"), (2, "bbb"), (3, "ccc"), (4, "ddd");
ERROR HY000: Remote table 'auto_test_remote2.tbl_a#P#p2' is not found ERROR HY000: Remote table 'auto_test_remote2.tbl_a#P#p2' is not found
DROP TABLE tbl_a; DROP TABLE tbl_a;
...@@ -427,9 +427,9 @@ PARTITION p1 VALUES LESS THAN (3) COMMENT='srv "s_2_1"', ...@@ -427,9 +427,9 @@ PARTITION p1 VALUES LESS THAN (3) COMMENT='srv "s_2_1"',
PARTITION p2 VALUES LESS THAN MAXVALUE REMOTE_SERVER="s_2_2" PARTITION p2 VALUES LESS THAN MAXVALUE REMOTE_SERVER="s_2_2"
); );
Warnings: Warnings:
Warning 12529 The table or partition COMMENT or CONNECTION string 'srv "s_2_1"' is not used as connection info because spider_ignore_comment is 1 or at least one table option has been specified Warning 12529 The table or partition COMMENT or CONNECTION string 'srv "s_2_1"' is not parsed for table params because spider_ignore_comment is 1 or at least one table option has been specified
Warning 12529 The table or partition COMMENT or CONNECTION string 'tbl "tbl_a"' is not used as connection info because spider_ignore_comment is 1 or at least one table option has been specified Warning 12529 The table or partition COMMENT or CONNECTION string 'tbl "tbl_a"' is not parsed for table params because spider_ignore_comment is 1 or at least one table option has been specified
Warning 12529 The table or partition COMMENT or CONNECTION string 'tbl "tbl_a"' is not used as connection info because spider_ignore_comment is 1 or at least one table option has been specified Warning 12529 The table or partition COMMENT or CONNECTION string 'tbl "tbl_a"' is not parsed for table params because spider_ignore_comment is 1 or at least one table option has been specified
INSERT INTO tbl_a VALUES (1, "aaa"), (2, "bbb"), (3, "ccc"), (4, "ddd"); INSERT INTO tbl_a VALUES (1, "aaa"), (2, "bbb"), (3, "ccc"), (4, "ddd");
ERROR HY000: Unable to connect to foreign data source: localhost ERROR HY000: Unable to connect to foreign data source: localhost
DROP TABLE tbl_a; DROP TABLE tbl_a;
...@@ -447,10 +447,10 @@ PARTITION p1 VALUES LESS THAN (3) COMMENT='srv "s_2_2"', ...@@ -447,10 +447,10 @@ PARTITION p1 VALUES LESS THAN (3) COMMENT='srv "s_2_2"',
PARTITION p2 VALUES LESS THAN MAXVALUE REMOTE_SERVER="s_2_2" PARTITION p2 VALUES LESS THAN MAXVALUE REMOTE_SERVER="s_2_2"
); );
Warnings: Warnings:
Warning 12529 The table or partition COMMENT or CONNECTION string 'srv "s_2_2"' is not used as connection info because spider_ignore_comment is 1 or at least one table option has been specified Warning 12529 The table or partition COMMENT or CONNECTION string 'srv "s_2_2"' is not parsed for table params because spider_ignore_comment is 1 or at least one table option has been specified
INSERT INTO tbl_a VALUES (1, "aaa"), (2, "bbb"), (3, "ccc"), (4, "ddd"); INSERT INTO tbl_a VALUES (1, "aaa"), (2, "bbb"), (3, "ccc"), (4, "ddd");
Warnings: Warnings:
Warning 12529 The table or partition COMMENT or CONNECTION string 'srv "s_2_2"' is not used as connection info because spider_ignore_comment is 1 or at least one table option has been specified Warning 12529 The table or partition COMMENT or CONNECTION string 'srv "s_2_2"' is not parsed for table params because spider_ignore_comment is 1 or at least one table option has been specified
connection child2_1; connection child2_1;
SELECT * FROM tbl_a; SELECT * FROM tbl_a;
a b a b
...@@ -477,7 +477,7 @@ PARTITION p1 VALUES LESS THAN (3) COMMENT='srv "s_2_2" read_only_mode "0"', ...@@ -477,7 +477,7 @@ PARTITION p1 VALUES LESS THAN (3) COMMENT='srv "s_2_2" read_only_mode "0"',
PARTITION p2 VALUES LESS THAN MAXVALUE REMOTE_SERVER="s_2_2" READ_ONLY=NO PARTITION p2 VALUES LESS THAN MAXVALUE REMOTE_SERVER="s_2_2" READ_ONLY=NO
); );
Warnings: Warnings:
Warning 12529 The table or partition COMMENT or CONNECTION string 'srv "s_2_2" read_only_mode "0"' is not used as connection info because spider_ignore_comment is 1 or at least one table option has been specified Warning 12529 The table or partition COMMENT or CONNECTION string 'srv "s_2_2" read_only_mode "0"' is not parsed for table params because spider_ignore_comment is 1 or at least one table option has been specified
INSERT INTO tbl_a VALUES (1, "aaa"), (2, "bbb"); INSERT INTO tbl_a VALUES (1, "aaa"), (2, "bbb");
ERROR HY000: Table 'auto_test_local.tbl_a' is read only ERROR HY000: Table 'auto_test_local.tbl_a' is read only
INSERT INTO tbl_a VALUES (3, "ccc"), (4, "ddd"); INSERT INTO tbl_a VALUES (3, "ccc"), (4, "ddd");
...@@ -500,7 +500,7 @@ PRIMARY KEY(a) ...@@ -500,7 +500,7 @@ PRIMARY KEY(a)
) ENGINE=Spider DEFAULT CHARSET=utf8 ) ENGINE=Spider DEFAULT CHARSET=utf8
REMOTE_SERVER="s_2_1" COMMENT='tbl "tbl_b"' REMOTE_TABLE="tbl_a"; REMOTE_SERVER="s_2_1" COMMENT='tbl "tbl_b"' REMOTE_TABLE="tbl_a";
Warnings: Warnings:
Warning 12529 The table or partition COMMENT or CONNECTION string 'tbl "tbl_b"' is not used as connection info because spider_ignore_comment is 1 or at least one table option has been specified Warning 12529 The table or partition COMMENT or CONNECTION string 'tbl "tbl_b"' is not parsed for table params because spider_ignore_comment is 1 or at least one table option has been specified
select table_name, server, tgt_table_name from mysql.spider_tables; select table_name, server, tgt_table_name from mysql.spider_tables;
table_name server tgt_table_name table_name server tgt_table_name
tbl_a s_2_1 tbl_a tbl_a s_2_1 tbl_a
......
...@@ -402,7 +402,7 @@ SPIDER_CONN *spider_create_conn( ...@@ -402,7 +402,7 @@ SPIDER_CONN *spider_create_conn(
char *tmp_name, *tmp_host, *tmp_username, *tmp_password, *tmp_socket; char *tmp_name, *tmp_host, *tmp_username, *tmp_password, *tmp_socket;
char *tmp_wrapper, *tmp_db, *tmp_ssl_ca, *tmp_ssl_capath, *tmp_ssl_cert; char *tmp_wrapper, *tmp_db, *tmp_ssl_ca, *tmp_ssl_capath, *tmp_ssl_cert;
char *tmp_ssl_cipher, *tmp_ssl_key, *tmp_default_file, *tmp_default_group; char *tmp_ssl_cipher, *tmp_ssl_key, *tmp_default_file, *tmp_default_group;
char *tmp_dsn, *tmp_filedsn, *tmp_driver; char *tmp_dsn, *tmp_filedsn, *tmp_driver, *tmp_odbc_conn_str;
DBUG_ENTER("spider_create_conn"); DBUG_ENTER("spider_create_conn");
if (unlikely(!UTC)) if (unlikely(!UTC))
...@@ -454,6 +454,8 @@ SPIDER_CONN *spider_create_conn( ...@@ -454,6 +454,8 @@ SPIDER_CONN *spider_create_conn(
(uint) (share->tgt_filedsns_lengths[link_idx] + 1), (uint) (share->tgt_filedsns_lengths[link_idx] + 1),
&tmp_driver, &tmp_driver,
(uint) (share->tgt_drivers_lengths[link_idx] + 1), (uint) (share->tgt_drivers_lengths[link_idx] + 1),
&tmp_odbc_conn_str,
(uint) (share->tgt_odbc_conn_str_length + 1),
&need_mon, (uint) (sizeof(int)), &need_mon, (uint) (sizeof(int)),
NullS)) NullS))
) { ) {
...@@ -529,6 +531,10 @@ SPIDER_CONN *spider_create_conn( ...@@ -529,6 +531,10 @@ SPIDER_CONN *spider_create_conn(
spider_memcpy_or_null(&conn->tgt_driver, tmp_driver, share->tgt_drivers[link_idx], spider_memcpy_or_null(&conn->tgt_driver, tmp_driver, share->tgt_drivers[link_idx],
&conn->tgt_driver_length, &conn->tgt_driver_length,
share->tgt_drivers_lengths[link_idx]); share->tgt_drivers_lengths[link_idx]);
spider_memcpy_or_null(&conn->tgt_odbc_conn_str, tmp_odbc_conn_str,
share->tgt_odbc_conn_str,
&conn->tgt_odbc_conn_str_length,
share->tgt_odbc_conn_str_length);
conn->tgt_port = share->tgt_ports[link_idx]; conn->tgt_port = share->tgt_ports[link_idx];
conn->tgt_ssl_vsc = share->tgt_ssl_vscs[link_idx]; conn->tgt_ssl_vsc = share->tgt_ssl_vscs[link_idx];
conn->dbton_id = share->sql_dbton_ids[link_idx]; conn->dbton_id = share->sql_dbton_ids[link_idx];
......
...@@ -73,7 +73,7 @@ ...@@ -73,7 +73,7 @@
#define ER_SPIDER_INVALID_TABLE_OPTION_NUM 12528 #define ER_SPIDER_INVALID_TABLE_OPTION_NUM 12528
#define ER_SPIDER_INVALID_TABLE_OPTION_STR "The table option %s=%s is invalid" #define ER_SPIDER_INVALID_TABLE_OPTION_STR "The table option %s=%s is invalid"
#define ER_SPIDER_COMMENT_CONNECTION_IGNORED_BY_TABLE_OPTIONS_NUM 12529 #define ER_SPIDER_COMMENT_CONNECTION_IGNORED_BY_TABLE_OPTIONS_NUM 12529
#define ER_SPIDER_COMMENT_CONNECTION_IGNORED_BY_TABLE_OPTIONS_STR "The table or partition COMMENT or CONNECTION string '%s' is not used as connection info because spider_ignore_comment is 1 or at least one table option has been specified" #define ER_SPIDER_COMMENT_CONNECTION_IGNORED_BY_TABLE_OPTIONS_STR "The table or partition COMMENT or CONNECTION string '%s' is not parsed for table params because spider_ignore_comment is 1 or at least one table option has been specified"
#define ER_SPIDER_CANT_USE_BOTH_INNER_XA_AND_SNAPSHOT_NUM 12601 #define ER_SPIDER_CANT_USE_BOTH_INNER_XA_AND_SNAPSHOT_NUM 12601
#define ER_SPIDER_CANT_USE_BOTH_INNER_XA_AND_SNAPSHOT_STR "Can't use both spider_use_consistent_snapshot = 1 and spider_internal_xa = 1" #define ER_SPIDER_CANT_USE_BOTH_INNER_XA_AND_SNAPSHOT_STR "Can't use both spider_use_consistent_snapshot = 1 and spider_internal_xa = 1"
......
...@@ -678,6 +678,7 @@ typedef struct st_spider_conn ...@@ -678,6 +678,7 @@ typedef struct st_spider_conn
char *tgt_dsn; char *tgt_dsn;
char *tgt_filedsn; char *tgt_filedsn;
char *tgt_driver; char *tgt_driver;
char *tgt_odbc_conn_str;
long tgt_port; long tgt_port;
long tgt_ssl_vsc; long tgt_ssl_vsc;
...@@ -697,6 +698,7 @@ typedef struct st_spider_conn ...@@ -697,6 +698,7 @@ typedef struct st_spider_conn
uint tgt_dsn_length; uint tgt_dsn_length;
uint tgt_filedsn_length; uint tgt_filedsn_length;
uint tgt_driver_length; uint tgt_driver_length;
uint tgt_odbc_conn_str_length;
uint dbton_id; uint dbton_id;
volatile volatile
...@@ -1195,6 +1197,7 @@ typedef struct st_spider_share ...@@ -1195,6 +1197,7 @@ typedef struct st_spider_share
char **tgt_dsns; char **tgt_dsns;
char **tgt_filedsns; char **tgt_filedsns;
char **tgt_drivers; char **tgt_drivers;
char *tgt_odbc_conn_str;
char **static_link_ids; char **static_link_ids;
char **tgt_pk_names; char **tgt_pk_names;
char **tgt_sequence_names; char **tgt_sequence_names;
...@@ -1237,6 +1240,7 @@ typedef struct st_spider_share ...@@ -1237,6 +1240,7 @@ typedef struct st_spider_share
uint *tgt_dsns_lengths; uint *tgt_dsns_lengths;
uint *tgt_filedsns_lengths; uint *tgt_filedsns_lengths;
uint *tgt_drivers_lengths; uint *tgt_drivers_lengths;
uint tgt_odbc_conn_str_length;
uint *static_link_ids_lengths; uint *static_link_ids_lengths;
uint *tgt_pk_names_lengths; uint *tgt_pk_names_lengths;
uint *tgt_sequence_names_lengths; uint *tgt_sequence_names_lengths;
......
...@@ -860,6 +860,8 @@ int spider_free_share_alloc( ...@@ -860,6 +860,8 @@ int spider_free_share_alloc(
} }
spider_free(spider_current_trx, share->tgt_drivers, MYF(0)); spider_free(spider_current_trx, share->tgt_drivers, MYF(0));
} }
if (share->tgt_odbc_conn_str)
spider_free(spider_current_trx, share->tgt_odbc_conn_str, MYF(0));
if (share->tgt_pk_names) if (share->tgt_pk_names)
{ {
for (roop_count = 0; roop_count < (int) share->tgt_pk_names_length; for (roop_count = 0; roop_count < (int) share->tgt_pk_names_length;
...@@ -2483,9 +2485,6 @@ int st_spider_param_string_parse::fail(bool restore_delim) ...@@ -2483,9 +2485,6 @@ int st_spider_param_string_parse::fail(bool restore_delim)
/* /*
Parse connection information specified by COMMENT, CONNECT, or engine-defined Parse connection information specified by COMMENT, CONNECT, or engine-defined
options. options.
TODO: Deprecate the connection specification by COMMENT and CONNECT,
and then solely utilize engine-defined options.
*/ */
int spider_parse_connect_info( int spider_parse_connect_info(
SPIDER_SHARE *share, SPIDER_SHARE *share,
...@@ -2512,6 +2511,7 @@ int spider_parse_connect_info( ...@@ -2512,6 +2511,7 @@ int spider_parse_connect_info(
DBUG_PRINT("info",("spider s->path=%s", table_share->path.str)); DBUG_PRINT("info",("spider s->path=%s", table_share->path.str));
DBUG_PRINT("info", DBUG_PRINT("info",
("spider s->normalized_path=%s", table_share->normalized_path.str)); ("spider s->normalized_path=%s", table_share->normalized_path.str));
parse.error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM;
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 /* Find the correct table options, depending on if we are parsing a
...@@ -2600,8 +2600,11 @@ int spider_parse_connect_info( ...@@ -2600,8 +2600,11 @@ int spider_parse_connect_info(
goto error_alloc_conn_string; goto error_alloc_conn_string;
} }
DBUG_ASSERT(error_num_1 == 0); DBUG_ASSERT(error_num_1 == 0);
/* If the connect string is explicitly ignored for parsing, or if /*
any option is specified, skip the parsing. */ If the COMMENT or CONNECTION string is explicitly ignored for
table param parsing, or if any option is specified, skip the
parsing.
*/
if (spider_param_ignore_comments(current_thd) || option_specified) if (spider_param_ignore_comments(current_thd) || option_specified)
{ {
if (!spider_param_suppress_comment_ignored_warning(current_thd)) if (!spider_param_suppress_comment_ignored_warning(current_thd))
...@@ -2621,7 +2624,6 @@ int spider_parse_connect_info( ...@@ -2621,7 +2624,6 @@ int spider_parse_connect_info(
"and will be removed in a future release. " "and will be removed in a future release. "
"Please use table options instead."); "Please use table options instead.");
start_param = connect_string; start_param = connect_string;
parse.error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM;
while (*start_param != '\0') while (*start_param != '\0')
{ {
if (parse.locate_param_def(start_param)) if (parse.locate_param_def(start_param))
......
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