Commit 96760d3a authored by Yuchen Pei's avatar Yuchen Pei

MDEV-31787 MDEV-26151 Add a test exercising non-0 spider_casual_read

Also:
- clean up spider_check_and_get_casual_read_conn() and
  spider_check_and_set_autocommit()
- remove a couple of commented out code blocks
parent d59334da
MDEV-26151 MDEV-31787
for master_1
for child2
for child3
set @old_spider_bgs_mode= @@spider_bgs_mode;
set session spider_bgs_mode=1;
CREATE SERVER $srv FOREIGN DATA WRAPPER MYSQL OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');
create table td (a int, PRIMARY KEY (a));
create table ts (a int, PRIMARY KEY (a)) ENGINE=Spider COMMENT='WRAPPER "mysql", srv "srv_mdev_26151",TABLE "td", casual_read "3"';
insert into td values (11), (42);
select max(a) from ts;
max(a)
42
drop table td, ts;
create table td (a int, PRIMARY KEY (a));
create table ts (a int, PRIMARY KEY (a)) ENGINE=Spider COMMENT='WRAPPER "mysql", srv "srv_mdev_26151",TABLE "td", casual_read "1"';
insert into td values (11), (42);
select max(a) from ts;
max(a)
42
select min(a) from ts;
min(a)
11
drop table td, ts;
drop server srv_mdev_26151;
set session spider_bgs_mode=@old_spider_bgs_mode;
for master_1
for child2
for child3
end of test
--echo
--echo MDEV-26151 MDEV-31787
--echo
# This test exercises the code path where a nonzero casual_read takes
# effect.
--disable_query_log
--disable_result_log
--source ../../t/test_init.inc
--enable_result_log
--enable_query_log
--let $srv=srv_mdev_26151
set @old_spider_bgs_mode= @@spider_bgs_mode;
set session spider_bgs_mode=1;
evalp CREATE SERVER $srv FOREIGN DATA WRAPPER MYSQL OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');
# casual_read != 0 && casual_read != 1
create table td (a int, PRIMARY KEY (a));
eval create table ts (a int, PRIMARY KEY (a)) ENGINE=Spider COMMENT='WRAPPER "mysql", srv "$srv",TABLE "td", casual_read "3"';
insert into td values (11), (42);
select max(a) from ts;
drop table td, ts;
create table td (a int, PRIMARY KEY (a));
# casual_read = 1
eval create table ts (a int, PRIMARY KEY (a)) ENGINE=Spider COMMENT='WRAPPER "mysql", srv "$srv",TABLE "td", casual_read "1"';
insert into td values (11), (42);
select max(a) from ts;
select min(a) from ts;
drop table td, ts;
eval drop server $srv;
set session spider_bgs_mode=@old_spider_bgs_mode;
--disable_query_log
--disable_result_log
--source ../../t/test_deinit.inc
--enable_result_log
--enable_query_log
--echo
--echo end of test
--echo
......@@ -1260,6 +1260,30 @@ int spider_free_conn(
DBUG_RETURN(0);
}
/**
May get or create a connection spawning a background thread
For each link (data node, formally representable as the tuple
(spider, link_idx)), there is an associated casual read value
(`spider->result_list.casual_read[link_idx]').
If the CRV is 0, do nothing. Otherwise, An casual read id
(`conn->casual_read_current_id`) is associated with the link and
query id. The CRI starts from 2, and is used only when CRV is 1, to
update the CRV (see below). The updated CRV is then used to
construct the connection key used for get or create a connection
that spawns a background thread to execute queries.
If the CRV is 1, it is assigned CRI. The latter is then incremented
by 1. The CRI will only go up to 63, before "wrapping" back to 2.
If 2 <= CRV <= 63, it is left alone.
Note that this function relies on the assumption that the CRV is
reset (e.g. using `spider_param_casual_read()') between consecutive
calls of this function for the CRV == 1 case to auto-increment as
expected.
*/
int spider_check_and_get_casual_read_conn(
THD *thd,
ha_spider *spider,
......@@ -1267,41 +1291,35 @@ int spider_check_and_get_casual_read_conn(
) {
int error_num;
DBUG_ENTER("spider_check_and_get_casual_read_conn");
if (spider->result_list.casual_read[link_idx])
if (!spider->result_list.casual_read[link_idx])
DBUG_RETURN(0);
SPIDER_CONN *conn = spider->conns[link_idx];
if (conn->casual_read_query_id != thd->query_id)
{
SPIDER_CONN *conn = spider->conns[link_idx];
if (conn->casual_read_query_id != thd->query_id)
{
conn->casual_read_query_id = thd->query_id;
conn->casual_read_query_id = thd->query_id;
conn->casual_read_current_id = 2;
}
if (spider->result_list.casual_read[link_idx] == 1)
{
spider->result_list.casual_read[link_idx] = conn->casual_read_current_id;
++conn->casual_read_current_id;
if (conn->casual_read_current_id > 63)
conn->casual_read_current_id = 2;
}
if (spider->result_list.casual_read[link_idx] == 1)
{
spider->result_list.casual_read[link_idx] = conn->casual_read_current_id;
++conn->casual_read_current_id;
if (conn->casual_read_current_id > 63)
{
conn->casual_read_current_id = 2;
}
}
char first_byte_bak = *spider->conn_keys[link_idx];
*spider->conn_keys[link_idx] =
'0' + spider->result_list.casual_read[link_idx];
if (
!(spider->conns[link_idx] =
spider_get_conn(spider->share, link_idx,
spider->conn_keys[link_idx], spider->trx,
spider, FALSE, TRUE, SPIDER_CONN_KIND_MYSQL,
&error_num))
) {
*spider->conn_keys[link_idx] = first_byte_bak;
DBUG_RETURN(error_num);
}
}
char first_byte_bak = *spider->conn_keys[link_idx];
*spider->conn_keys[link_idx] =
'0' + spider->result_list.casual_read[link_idx];
if (!(spider->conns[link_idx]= spider_get_conn(
spider->share, link_idx, spider->conn_keys[link_idx],
spider->trx, spider, FALSE, TRUE, SPIDER_CONN_KIND_MYSQL,
&error_num)))
{
*spider->conn_keys[link_idx] = first_byte_bak;
spider->conns[link_idx]->casual_read_base_conn = conn;
conn = spider->conns[link_idx];
spider_check_and_set_autocommit(thd, conn, NULL);
DBUG_RETURN(error_num);
}
*spider->conn_keys[link_idx] = first_byte_bak;
spider->conns[link_idx]->casual_read_base_conn = conn;
spider_check_and_set_autocommit(thd, spider->conns[link_idx], NULL);
DBUG_RETURN(0);
}
......@@ -1837,6 +1855,12 @@ int spider_set_conn_bg_param(
DBUG_RETURN(0);
}
/**
Creates a background thread on `conn' to run `spider_bg_conn_action()'
Does not create when `conn' is NULL or a bg thread has already been
created for `conn'.
*/
int spider_create_conn_thread(
SPIDER_CONN *conn
) {
......
......@@ -1589,27 +1589,9 @@ int spider_check_and_set_autocommit(
SPIDER_CONN *conn,
int *need_mon
) {
bool autocommit;
DBUG_ENTER("spider_check_and_set_autocommit");
autocommit = !thd_test_options(thd, OPTION_NOT_AUTOCOMMIT);
if (autocommit)
{
spider_conn_queue_autocommit(conn, TRUE);
} else {
spider_conn_queue_autocommit(conn, FALSE);
}
/*
if (autocommit && conn->autocommit != 1)
{
spider_conn_queue_autocommit(conn, TRUE);
conn->autocommit = 1;
} else if (!autocommit && conn->autocommit != 0)
{
spider_conn_queue_autocommit(conn, FALSE);
conn->autocommit = 0;
}
*/
spider_conn_queue_autocommit(
conn, !thd_test_options(thd, OPTION_NOT_AUTOCOMMIT));
DBUG_RETURN(0);
}
......@@ -1631,17 +1613,6 @@ int spider_check_and_set_sql_log_off(
spider_conn_queue_sql_log_off(conn, FALSE);
}
}
/*
if (internal_sql_log_off && conn->sql_log_off != 1)
{
spider_conn_queue_sql_log_off(conn, TRUE);
conn->sql_log_off = 1;
} else if (!internal_sql_log_off && conn->sql_log_off != 0)
{
spider_conn_queue_sql_log_off(conn, FALSE);
conn->sql_log_off = 0;
}
*/
DBUG_RETURN(0);
}
......
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