Commit 1070575a authored by Yuchen Pei's avatar Yuchen Pei

MDEV-33191 spider: fix dbton_id when iterating over links

There are two array fields in spider_share with similar names:

share->use_sql_dbton_ids that maps from i to the i-th dbton used by
share. Thus it should be used only when i iterates over all distinct
dbtons used by share.

share->sql_dbton_ids that maps from i to the dbton used by the i-th
link of the share. Thus it should be used only when i iterates over
all links of a share.

We correct instances where share->sql_dbton_ids should be used instead
of share->use_sql_dbton_ids.
parent f738cc98
...@@ -8392,7 +8392,7 @@ int ha_spider::ft_read_internal( ...@@ -8392,7 +8392,7 @@ int ha_spider::ft_read_internal(
} }
} else { } else {
#endif #endif
uint dbton_id = share->use_sql_dbton_ids[roop_count]; uint dbton_id = share->sql_dbton_ids[roop_count];
spider_db_handler *dbton_hdl = dbton_handler[dbton_id]; spider_db_handler *dbton_hdl = dbton_handler[dbton_id];
SPIDER_CONN *conn = conns[roop_count]; SPIDER_CONN *conn = conns[roop_count];
pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_assert_not_owner(&conn->mta_conn_mutex);
...@@ -13135,7 +13135,7 @@ int ha_spider::drop_tmp_tables() ...@@ -13135,7 +13135,7 @@ int ha_spider::drop_tmp_tables()
) { ) {
if (spider_bit_is_set(result_list.tmp_table_created, roop_count)) if (spider_bit_is_set(result_list.tmp_table_created, roop_count))
{ {
uint dbton_id = share->use_sql_dbton_ids[roop_count]; uint dbton_id = share->sql_dbton_ids[roop_count];
spider_db_handler *dbton_hdl = dbton_handler[dbton_id]; spider_db_handler *dbton_hdl = dbton_handler[dbton_id];
SPIDER_CONN *conn = conns[roop_count]; SPIDER_CONN *conn = conns[roop_count];
pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_assert_not_owner(&conn->mta_conn_mutex);
......
INSTALL SONAME 'ha_spider';
set spider_same_server_link=on;
CREATE TABLE t2(c INT);
CREATE TABLE t1(c INT) ENGINE=Spider COMMENT='socket "$SOCKET", user "root", table "t2 t3"';
ALTER TABLE t1 ENGINE=Spider;
TRUNCATE TABLE t1;
ERROR 42S02: Table 'test.t3' doesn't exist
drop table t1, t2;
Warnings:
Warning 1620 Plugin is busy and will be uninstalled on shutdown
INSTALL SONAME 'ha_spider';
set spider_same_server_link=on;
CREATE TABLE t2(c INT);
--let $SOCKET=`SELECT @@global.socket`
evalp CREATE TABLE t1(c INT) ENGINE=Spider COMMENT='socket "$SOCKET", user "root", table "t2 t3"';
ALTER TABLE t1 ENGINE=Spider;
--error ER_NO_SUCH_TABLE
TRUNCATE TABLE t1;
drop table t1, t2;
--disable_query_log
--source ../../include/clean_up_spider.inc
...@@ -8215,7 +8215,7 @@ int spider_db_delete_all_rows( ...@@ -8215,7 +8215,7 @@ int spider_db_delete_all_rows(
spider->conn_link_idx, roop_count, share->link_count, spider->conn_link_idx, roop_count, share->link_count,
SPIDER_LINK_STATUS_RECOVERY) SPIDER_LINK_STATUS_RECOVERY)
) { ) {
uint dbton_id = share->use_sql_dbton_ids[roop_count]; uint dbton_id = share->sql_dbton_ids[roop_count];
spider_db_handler *dbton_hdl = spider->dbton_handler[dbton_id]; spider_db_handler *dbton_hdl = spider->dbton_handler[dbton_id];
conn = spider->conns[roop_count]; conn = spider->conns[roop_count];
pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_assert_not_owner(&conn->mta_conn_mutex);
......
...@@ -1836,6 +1836,12 @@ enum spider_db_access_type ...@@ -1836,6 +1836,12 @@ enum spider_db_access_type
SPIDER_DB_ACCESS_TYPE_NOSQL SPIDER_DB_ACCESS_TYPE_NOSQL
}; };
/*
Type of singletons based on the type of the remote database.
All such singletons are stored in the array `spider_dbton', see
`spider_db_init()'.
*/
typedef struct st_spider_dbton typedef struct st_spider_dbton
{ {
uint dbton_id; uint dbton_id;
......
...@@ -1358,6 +1358,7 @@ typedef struct st_spider_share ...@@ -1358,6 +1358,7 @@ typedef struct st_spider_share
uint *hs_read_conn_keys_lengths; uint *hs_read_conn_keys_lengths;
uint *hs_write_conn_keys_lengths; uint *hs_write_conn_keys_lengths;
#endif #endif
/* The index in `spider_dbton' of each data node link. */
uint *sql_dbton_ids; uint *sql_dbton_ids;
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
uint *hs_dbton_ids; uint *hs_dbton_ids;
...@@ -1447,14 +1448,23 @@ typedef struct st_spider_share ...@@ -1447,14 +1448,23 @@ typedef struct st_spider_share
uchar dbton_bitmap[spider_bitmap_size(SPIDER_DBTON_SIZE)]; uchar dbton_bitmap[spider_bitmap_size(SPIDER_DBTON_SIZE)];
spider_db_share *dbton_share[SPIDER_DBTON_SIZE]; spider_db_share *dbton_share[SPIDER_DBTON_SIZE];
uint use_dbton_count; uint use_dbton_count;
/* Actual size is `use_dbton_count'. Values are the indices of item
in `spider_dbton'. */
uint use_dbton_ids[SPIDER_DBTON_SIZE]; uint use_dbton_ids[SPIDER_DBTON_SIZE];
/* Inverse map of `use_dbton_ids'. */
uint dbton_id_to_seq[SPIDER_DBTON_SIZE]; uint dbton_id_to_seq[SPIDER_DBTON_SIZE];
uint use_sql_dbton_count; uint use_sql_dbton_count;
/* Actual size is `use_sql_dbton_count'. Values are the indices of
item in `spider_dbton'. */
uint use_sql_dbton_ids[SPIDER_DBTON_SIZE]; uint use_sql_dbton_ids[SPIDER_DBTON_SIZE];
/* Inverse map of `use_sql_dbton_ids'. */
uint sql_dbton_id_to_seq[SPIDER_DBTON_SIZE]; uint sql_dbton_id_to_seq[SPIDER_DBTON_SIZE];
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
uint use_hs_dbton_count; uint use_hs_dbton_count;
/* Actual size is `use_hs_dbton_count'. Values are the indices of
item in `spider_dbton'. */
uint use_hs_dbton_ids[SPIDER_DBTON_SIZE]; uint use_hs_dbton_ids[SPIDER_DBTON_SIZE];
/* Inverse map of `use_hs_dbton_ids'. */
uint hs_dbton_id_to_seq[SPIDER_DBTON_SIZE]; uint hs_dbton_id_to_seq[SPIDER_DBTON_SIZE];
#endif #endif
......
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