Skip to content

Commit 4e599c7

Browse files
Kentokuvuvova
authored andcommitted
MDEV-18313 Supports 'wrapper mariadb' for connection information
1 parent 470c1b8 commit 4e599c7

13 files changed

+1616
-932
lines changed

storage/spider/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ SET(SPIDER_SOURCES
1818
spd_table.cc spd_direct_sql.cc spd_udf.cc spd_ping_table.cc
1919
spd_copy_tables.cc spd_i_s.cc spd_malloc.cc ha_spider.cc spd_udf.def
2020
spd_db_mysql.cc spd_db_handlersocket.cc spd_db_oracle.cc
21-
spd_group_by_handler.cc
21+
spd_group_by_handler.cc spd_db_include.cc
2222
hs_client/config.cpp hs_client/escape.cpp hs_client/fatal.cpp
2323
hs_client/hstcpcli.cpp hs_client/socket.cpp hs_client/string_util.cpp
2424
)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP
2+
--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP
3+
--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP
4+
--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP
5+
--disable_warnings
6+
--disable_query_log
7+
--disable_result_log
8+
--source ../t/test_deinit.inc
9+
--enable_result_log
10+
--enable_query_log
11+
--enable_warnings
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--disable_warnings
2+
--disable_query_log
3+
--disable_result_log
4+
--source ../t/test_init.inc
5+
--enable_result_log
6+
--enable_query_log
7+
--enable_warnings
8+
--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1
9+
let $MASTER_1_COMMENT_2_1=
10+
COMMENT='table "tbl_a", srv "s_2_1", wrapper "mariadb"';
11+
--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES
12+
let $CHILD2_1_DROP_TABLES=
13+
DROP TABLE IF EXISTS tbl_a;
14+
--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES
15+
let $CHILD2_1_CREATE_TABLES=
16+
CREATE TABLE tbl_a (
17+
pkey int NOT NULL,
18+
PRIMARY KEY (pkey)
19+
) $CHILD2_1_ENGINE $CHILD2_1_CHARSET;
20+
--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES
21+
let $CHILD2_1_SELECT_TABLES=
22+
SELECT pkey FROM tbl_a ORDER BY pkey;
23+
let $CHILD2_1_SELECT_ARGUMENT1=
24+
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %';
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
for master_1
2+
for child2
3+
child2_1
4+
child2_2
5+
child2_3
6+
for child3
7+
8+
this test is for MDEV-18313
9+
10+
drop and create databases
11+
connection master_1;
12+
CREATE DATABASE auto_test_local;
13+
USE auto_test_local;
14+
connection child2_1;
15+
SET @old_log_output = @@global.log_output;
16+
SET GLOBAL log_output = 'TABLE,FILE';
17+
CREATE DATABASE auto_test_remote;
18+
USE auto_test_remote;
19+
20+
create table and insert
21+
connection child2_1;
22+
CHILD2_1_CREATE_TABLES
23+
TRUNCATE TABLE mysql.general_log;
24+
connection master_1;
25+
CREATE TABLE tbl_a (
26+
pkey int NOT NULL,
27+
PRIMARY KEY (pkey)
28+
) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1
29+
INSERT INTO tbl_a (pkey) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
30+
31+
select test
32+
connection child2_1;
33+
TRUNCATE TABLE mysql.general_log;
34+
connection master_1;
35+
SELECT * FROM tbl_a ORDER BY pkey;
36+
pkey
37+
0
38+
1
39+
2
40+
3
41+
4
42+
5
43+
6
44+
7
45+
8
46+
9
47+
connection child2_1;
48+
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %';
49+
argument
50+
select t0.`pkey` `pkey` from `auto_test_remote`.`tbl_a` t0 order by `pkey`
51+
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'
52+
SELECT pkey FROM tbl_a ORDER BY pkey;
53+
pkey
54+
0
55+
1
56+
2
57+
3
58+
4
59+
5
60+
6
61+
7
62+
8
63+
9
64+
65+
deinit
66+
connection master_1;
67+
DROP DATABASE IF EXISTS auto_test_local;
68+
connection child2_1;
69+
DROP DATABASE IF EXISTS auto_test_remote;
70+
SET GLOBAL log_output = @old_log_output;
71+
for master_1
72+
for child2
73+
child2_1
74+
child2_2
75+
child2_3
76+
for child3
77+
78+
end of test
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
!include include/default_mysqld.cnf
2+
!include ../my_1_1.cnf
3+
!include ../my_2_1.cnf
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
--source ../include/wrapper_mariadb_init.inc
2+
--echo
3+
--echo this test is for MDEV-18313
4+
--echo
5+
--echo drop and create databases
6+
7+
--connection master_1
8+
--disable_warnings
9+
CREATE DATABASE auto_test_local;
10+
USE auto_test_local;
11+
12+
--connection child2_1
13+
SET @old_log_output = @@global.log_output;
14+
SET GLOBAL log_output = 'TABLE,FILE';
15+
CREATE DATABASE auto_test_remote;
16+
USE auto_test_remote;
17+
--enable_warnings
18+
19+
--echo
20+
--echo create table and insert
21+
22+
--connection child2_1
23+
--disable_query_log
24+
echo CHILD2_1_CREATE_TABLES;
25+
eval $CHILD2_1_CREATE_TABLES;
26+
--enable_query_log
27+
TRUNCATE TABLE mysql.general_log;
28+
29+
--connection master_1
30+
--disable_query_log
31+
echo CREATE TABLE tbl_a (
32+
pkey int NOT NULL,
33+
PRIMARY KEY (pkey)
34+
) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1;
35+
eval CREATE TABLE tbl_a (
36+
pkey int NOT NULL,
37+
PRIMARY KEY (pkey)
38+
) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1;
39+
--enable_query_log
40+
INSERT INTO tbl_a (pkey) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
41+
42+
--echo
43+
--echo select test
44+
45+
--connection child2_1
46+
TRUNCATE TABLE mysql.general_log;
47+
48+
--connection master_1
49+
SELECT * FROM tbl_a ORDER BY pkey;
50+
51+
--connection child2_1
52+
eval $CHILD2_1_SELECT_ARGUMENT1;
53+
eval $CHILD2_1_SELECT_TABLES;
54+
55+
--echo
56+
--echo deinit
57+
--disable_warnings
58+
59+
--connection master_1
60+
DROP DATABASE IF EXISTS auto_test_local;
61+
62+
--connection child2_1
63+
DROP DATABASE IF EXISTS auto_test_remote;
64+
SET GLOBAL log_output = @old_log_output;
65+
66+
--enable_warnings
67+
--source ../include/wrapper_mariadb_deinit.inc
68+
--echo
69+
--echo end of test

storage/spider/spd_db_handlersocket.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ SPIDER_DB_ROW *spider_db_handlersocket_row::clone()
500500
uint i;
501501
DBUG_ENTER("spider_db_handlersocket_row::clone");
502502
DBUG_PRINT("info",("spider this=%p", this));
503-
if (!(clone_row = new spider_db_handlersocket_row()))
503+
if (!(clone_row = new spider_db_handlersocket_row(dbton_id)))
504504
{
505505
DBUG_RETURN(NULL);
506506
}
@@ -603,7 +603,7 @@ bool spider_db_handlersocket_result_buffer::check_size(
603603

604604
spider_db_handlersocket_result::spider_db_handlersocket_result(
605605
SPIDER_DB_CONN *in_db_conn
606-
) : spider_db_result(in_db_conn, spider_dbton_handlersocket.dbton_id)
606+
) : spider_db_result(in_db_conn), row(in_db_conn->dbton_id)
607607
{
608608
DBUG_ENTER("spider_db_handlersocket_result::spider_db_handlersocket_result");
609609
DBUG_PRINT("info",("spider this=%p", this));
@@ -3953,7 +3953,8 @@ int spider_db_handlersocket_util::append_having(
39533953
spider_handlersocket_share::spider_handlersocket_share(
39543954
st_spider_share *share
39553955
) : spider_db_share(
3956-
share
3956+
share,
3957+
spider_dbton_handlersocket.dbton_id
39573958
),
39583959
table_names_str(NULL),
39593960
db_names_str(NULL),

storage/spider/spd_db_include.cc

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* Copyright (C) 2018-2019 Kentoku Shiba
2+
3+
This program is free software; you can redistribute it and/or modify
4+
it under the terms of the GNU General Public License as published by
5+
the Free Software Foundation; version 2 of the License.
6+
7+
This program is distributed in the hope that it will be useful,
8+
but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
GNU General Public License for more details.
11+
12+
You should have received a copy of the GNU General Public License
13+
along with this program; if not, write to the Free Software
14+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
15+
16+
#define MYSQL_SERVER 1
17+
#include <my_global.h>
18+
#include "mysql_version.h"
19+
#include "spd_environ.h"
20+
#if MYSQL_VERSION_ID < 50500
21+
#include "mysql_priv.h"
22+
#include <mysql/plugin.h>
23+
#else
24+
#include "sql_priv.h"
25+
#include "probes_mysql.h"
26+
#include "sql_class.h"
27+
#endif
28+
#include "sql_common.h"
29+
#include <mysql.h>
30+
#include <errmsg.h>
31+
#include "spd_err.h"
32+
#include "spd_db_include.h"
33+
#include "spd_include.h"
34+
35+
spider_db_result::spider_db_result(
36+
SPIDER_DB_CONN *in_db_conn
37+
) : db_conn(in_db_conn), dbton_id(in_db_conn->dbton_id)
38+
{
39+
DBUG_ENTER("spider_db_result::spider_db_result");
40+
DBUG_PRINT("info",("spider this=%p", this));
41+
DBUG_VOID_RETURN;
42+
}
43+
44+
spider_db_conn::spider_db_conn(
45+
SPIDER_CONN *in_conn
46+
) : conn(in_conn), dbton_id(in_conn->dbton_id)
47+
{
48+
DBUG_ENTER("spider_db_conn::spider_db_conn");
49+
DBUG_PRINT("info",("spider this=%p", this));
50+
DBUG_VOID_RETURN;
51+
}

storage/spider/spd_db_include.h

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#define SPIDER_DBTON_SIZE 15
2222

2323
#define SPIDER_DB_WRAPPER_MYSQL "mysql"
24+
#define SPIDER_DB_WRAPPER_MARIADB "mariadb"
2425

2526
#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100204
2627
#define PLUGIN_VAR_CAN_MEMALLOC
@@ -795,6 +796,7 @@ struct st_spider_db_request_key
795796
class spider_db_util
796797
{
797798
public:
799+
uint dbton_id;
798800
spider_db_util() {}
799801
virtual ~spider_db_util() {}
800802
virtual int append_name(
@@ -961,8 +963,7 @@ class spider_db_result
961963
SPIDER_DB_CONN *db_conn;
962964
public:
963965
uint dbton_id;
964-
spider_db_result(SPIDER_DB_CONN *in_db_conn, uint in_dbton_id) :
965-
db_conn(in_db_conn), dbton_id(in_dbton_id) {}
966+
spider_db_result(SPIDER_DB_CONN *in_db_conn);
966967
virtual ~spider_db_result() {}
967968
virtual bool has_result() = 0;
968969
virtual void free_result() = 0;
@@ -1028,9 +1029,10 @@ class spider_db_conn
10281029
protected:
10291030
SPIDER_CONN *conn;
10301031
public:
1032+
uint dbton_id;
10311033
spider_db_conn(
1032-
SPIDER_CONN *conn
1033-
) : conn(conn) {}
1034+
SPIDER_CONN *in_conn
1035+
);
10341036
virtual ~spider_db_conn() {}
10351037
virtual int init() = 0;
10361038
virtual bool is_connected() = 0;
@@ -1229,8 +1231,12 @@ class spider_db_share
12291231
const char *mem_calc_file_name;
12301232
ulong mem_calc_line_no;
12311233
public:
1234+
uint dbton_id;
12321235
st_spider_share *spider_share;
1233-
spider_db_share(st_spider_share *share) : spider_share(share) {}
1236+
spider_db_share(
1237+
st_spider_share *share,
1238+
uint dbton_id
1239+
) : dbton_id(dbton_id), spider_share(share) {}
12341240
virtual ~spider_db_share() {}
12351241
virtual int init() = 0;
12361242
virtual uint get_column_name_length(
@@ -1264,14 +1270,16 @@ class spider_db_handler
12641270
const char *mem_calc_file_name;
12651271
ulong mem_calc_line_no;
12661272
public:
1273+
uint dbton_id;
12671274
ha_spider *spider;
12681275
spider_db_share *db_share;
12691276
int first_link_idx;
12701277
#ifdef SPIDER_HAS_GROUP_BY_HANDLER
12711278
SPIDER_LINK_IDX_CHAIN *link_idx_chain;
12721279
#endif
12731280
spider_db_handler(ha_spider *spider, spider_db_share *db_share) :
1274-
spider(spider), db_share(db_share), first_link_idx(-1) {}
1281+
dbton_id(db_share->dbton_id), spider(spider), db_share(db_share),
1282+
first_link_idx(-1) {}
12751283
virtual ~spider_db_handler() {}
12761284
virtual int init() = 0;
12771285
virtual int append_index_hint(
@@ -1750,9 +1758,10 @@ class spider_db_handler
17501758
class spider_db_copy_table
17511759
{
17521760
public:
1761+
uint dbton_id;
17531762
spider_db_share *db_share;
17541763
spider_db_copy_table(spider_db_share *db_share) :
1755-
db_share(db_share) {}
1764+
dbton_id(db_share->dbton_id), db_share(db_share) {}
17561765
virtual ~spider_db_copy_table() {}
17571766
virtual int init() = 0;
17581767
virtual void set_sql_charset(

0 commit comments

Comments
 (0)