Skip to content

Commit

Permalink
MDEV-18313 Supports 'wrapper mariadb' for connection information
Browse files Browse the repository at this point in the history
  • Loading branch information
Kentoku authored and vuvova committed Jan 31, 2019
1 parent 470c1b8 commit 4e599c7
Show file tree
Hide file tree
Showing 13 changed files with 1,616 additions and 932 deletions.
2 changes: 1 addition & 1 deletion storage/spider/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ SET(SPIDER_SOURCES
spd_table.cc spd_direct_sql.cc spd_udf.cc spd_ping_table.cc
spd_copy_tables.cc spd_i_s.cc spd_malloc.cc ha_spider.cc spd_udf.def
spd_db_mysql.cc spd_db_handlersocket.cc spd_db_oracle.cc
spd_group_by_handler.cc
spd_group_by_handler.cc spd_db_include.cc
hs_client/config.cpp hs_client/escape.cpp hs_client/fatal.cpp
hs_client/hstcpcli.cpp hs_client/socket.cpp hs_client/string_util.cpp
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP
--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP
--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP
--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP
--disable_warnings
--disable_query_log
--disable_result_log
--source ../t/test_deinit.inc
--enable_result_log
--enable_query_log
--enable_warnings
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--disable_warnings
--disable_query_log
--disable_result_log
--source ../t/test_init.inc
--enable_result_log
--enable_query_log
--enable_warnings
--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1
let $MASTER_1_COMMENT_2_1=
COMMENT='table "tbl_a", srv "s_2_1", wrapper "mariadb"';
--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES
let $CHILD2_1_DROP_TABLES=
DROP TABLE IF EXISTS tbl_a;
--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES
let $CHILD2_1_CREATE_TABLES=
CREATE TABLE tbl_a (
pkey int NOT NULL,
PRIMARY KEY (pkey)
) $CHILD2_1_ENGINE $CHILD2_1_CHARSET;
--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES
let $CHILD2_1_SELECT_TABLES=
SELECT pkey FROM tbl_a ORDER BY pkey;
let $CHILD2_1_SELECT_ARGUMENT1=
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %';
78 changes: 78 additions & 0 deletions storage/spider/mysql-test/spider/bugfix/r/wrapper_mariadb.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
for master_1
for child2
child2_1
child2_2
child2_3
for child3

this test is for MDEV-18313

drop and create databases
connection master_1;
CREATE DATABASE auto_test_local;
USE auto_test_local;
connection child2_1;
SET @old_log_output = @@global.log_output;
SET GLOBAL log_output = 'TABLE,FILE';
CREATE DATABASE auto_test_remote;
USE auto_test_remote;

create table and insert
connection child2_1;
CHILD2_1_CREATE_TABLES
TRUNCATE TABLE mysql.general_log;
connection master_1;
CREATE TABLE tbl_a (
pkey int NOT NULL,
PRIMARY KEY (pkey)
) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1
INSERT INTO tbl_a (pkey) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);

select test
connection child2_1;
TRUNCATE TABLE mysql.general_log;
connection master_1;
SELECT * FROM tbl_a ORDER BY pkey;
pkey
0
1
2
3
4
5
6
7
8
9
connection child2_1;
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %';
argument
select t0.`pkey` `pkey` from `auto_test_remote`.`tbl_a` t0 order by `pkey`
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'
SELECT pkey FROM tbl_a ORDER BY pkey;
pkey
0
1
2
3
4
5
6
7
8
9

deinit
connection master_1;
DROP DATABASE IF EXISTS auto_test_local;
connection child2_1;
DROP DATABASE IF EXISTS auto_test_remote;
SET GLOBAL log_output = @old_log_output;
for master_1
for child2
child2_1
child2_2
child2_3
for child3

end of test
3 changes: 3 additions & 0 deletions storage/spider/mysql-test/spider/bugfix/t/wrapper_mariadb.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
!include include/default_mysqld.cnf
!include ../my_1_1.cnf
!include ../my_2_1.cnf
69 changes: 69 additions & 0 deletions storage/spider/mysql-test/spider/bugfix/t/wrapper_mariadb.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
--source ../include/wrapper_mariadb_init.inc
--echo
--echo this test is for MDEV-18313
--echo
--echo drop and create databases

--connection master_1
--disable_warnings
CREATE DATABASE auto_test_local;
USE auto_test_local;

--connection child2_1
SET @old_log_output = @@global.log_output;
SET GLOBAL log_output = 'TABLE,FILE';
CREATE DATABASE auto_test_remote;
USE auto_test_remote;
--enable_warnings

--echo
--echo create table and insert

--connection child2_1
--disable_query_log
echo CHILD2_1_CREATE_TABLES;
eval $CHILD2_1_CREATE_TABLES;
--enable_query_log
TRUNCATE TABLE mysql.general_log;

--connection master_1
--disable_query_log
echo CREATE TABLE tbl_a (
pkey int NOT NULL,
PRIMARY KEY (pkey)
) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1;
eval CREATE TABLE tbl_a (
pkey int NOT NULL,
PRIMARY KEY (pkey)
) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1;
--enable_query_log
INSERT INTO tbl_a (pkey) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);

--echo
--echo select test

--connection child2_1
TRUNCATE TABLE mysql.general_log;

--connection master_1
SELECT * FROM tbl_a ORDER BY pkey;

--connection child2_1
eval $CHILD2_1_SELECT_ARGUMENT1;
eval $CHILD2_1_SELECT_TABLES;

--echo
--echo deinit
--disable_warnings

--connection master_1
DROP DATABASE IF EXISTS auto_test_local;

--connection child2_1
DROP DATABASE IF EXISTS auto_test_remote;
SET GLOBAL log_output = @old_log_output;

--enable_warnings
--source ../include/wrapper_mariadb_deinit.inc
--echo
--echo end of test
7 changes: 4 additions & 3 deletions storage/spider/spd_db_handlersocket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ SPIDER_DB_ROW *spider_db_handlersocket_row::clone()
uint i;
DBUG_ENTER("spider_db_handlersocket_row::clone");
DBUG_PRINT("info",("spider this=%p", this));
if (!(clone_row = new spider_db_handlersocket_row()))
if (!(clone_row = new spider_db_handlersocket_row(dbton_id)))
{
DBUG_RETURN(NULL);
}
Expand Down Expand Up @@ -603,7 +603,7 @@ bool spider_db_handlersocket_result_buffer::check_size(

spider_db_handlersocket_result::spider_db_handlersocket_result(
SPIDER_DB_CONN *in_db_conn
) : spider_db_result(in_db_conn, spider_dbton_handlersocket.dbton_id)
) : spider_db_result(in_db_conn), row(in_db_conn->dbton_id)
{
DBUG_ENTER("spider_db_handlersocket_result::spider_db_handlersocket_result");
DBUG_PRINT("info",("spider this=%p", this));
Expand Down Expand Up @@ -3953,7 +3953,8 @@ int spider_db_handlersocket_util::append_having(
spider_handlersocket_share::spider_handlersocket_share(
st_spider_share *share
) : spider_db_share(
share
share,
spider_dbton_handlersocket.dbton_id
),
table_names_str(NULL),
db_names_str(NULL),
Expand Down
51 changes: 51 additions & 0 deletions storage/spider/spd_db_include.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* Copyright (C) 2018-2019 Kentoku Shiba
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */

#define MYSQL_SERVER 1
#include <my_global.h>
#include "mysql_version.h"
#include "spd_environ.h"
#if MYSQL_VERSION_ID < 50500
#include "mysql_priv.h"
#include <mysql/plugin.h>
#else
#include "sql_priv.h"
#include "probes_mysql.h"
#include "sql_class.h"
#endif
#include "sql_common.h"
#include <mysql.h>
#include <errmsg.h>
#include "spd_err.h"
#include "spd_db_include.h"
#include "spd_include.h"

spider_db_result::spider_db_result(
SPIDER_DB_CONN *in_db_conn
) : db_conn(in_db_conn), dbton_id(in_db_conn->dbton_id)
{
DBUG_ENTER("spider_db_result::spider_db_result");
DBUG_PRINT("info",("spider this=%p", this));
DBUG_VOID_RETURN;
}

spider_db_conn::spider_db_conn(
SPIDER_CONN *in_conn
) : conn(in_conn), dbton_id(in_conn->dbton_id)
{
DBUG_ENTER("spider_db_conn::spider_db_conn");
DBUG_PRINT("info",("spider this=%p", this));
DBUG_VOID_RETURN;
}
23 changes: 16 additions & 7 deletions storage/spider/spd_db_include.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define SPIDER_DBTON_SIZE 15

#define SPIDER_DB_WRAPPER_MYSQL "mysql"
#define SPIDER_DB_WRAPPER_MARIADB "mariadb"

#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100204
#define PLUGIN_VAR_CAN_MEMALLOC
Expand Down Expand Up @@ -795,6 +796,7 @@ struct st_spider_db_request_key
class spider_db_util
{
public:
uint dbton_id;
spider_db_util() {}
virtual ~spider_db_util() {}
virtual int append_name(
Expand Down Expand Up @@ -961,8 +963,7 @@ class spider_db_result
SPIDER_DB_CONN *db_conn;
public:
uint dbton_id;
spider_db_result(SPIDER_DB_CONN *in_db_conn, uint in_dbton_id) :
db_conn(in_db_conn), dbton_id(in_dbton_id) {}
spider_db_result(SPIDER_DB_CONN *in_db_conn);
virtual ~spider_db_result() {}
virtual bool has_result() = 0;
virtual void free_result() = 0;
Expand Down Expand Up @@ -1028,9 +1029,10 @@ class spider_db_conn
protected:
SPIDER_CONN *conn;
public:
uint dbton_id;
spider_db_conn(
SPIDER_CONN *conn
) : conn(conn) {}
SPIDER_CONN *in_conn
);
virtual ~spider_db_conn() {}
virtual int init() = 0;
virtual bool is_connected() = 0;
Expand Down Expand Up @@ -1229,8 +1231,12 @@ class spider_db_share
const char *mem_calc_file_name;
ulong mem_calc_line_no;
public:
uint dbton_id;
st_spider_share *spider_share;
spider_db_share(st_spider_share *share) : spider_share(share) {}
spider_db_share(
st_spider_share *share,
uint dbton_id
) : dbton_id(dbton_id), spider_share(share) {}
virtual ~spider_db_share() {}
virtual int init() = 0;
virtual uint get_column_name_length(
Expand Down Expand Up @@ -1264,14 +1270,16 @@ class spider_db_handler
const char *mem_calc_file_name;
ulong mem_calc_line_no;
public:
uint dbton_id;
ha_spider *spider;
spider_db_share *db_share;
int first_link_idx;
#ifdef SPIDER_HAS_GROUP_BY_HANDLER
SPIDER_LINK_IDX_CHAIN *link_idx_chain;
#endif
spider_db_handler(ha_spider *spider, spider_db_share *db_share) :
spider(spider), db_share(db_share), first_link_idx(-1) {}
dbton_id(db_share->dbton_id), spider(spider), db_share(db_share),
first_link_idx(-1) {}
virtual ~spider_db_handler() {}
virtual int init() = 0;
virtual int append_index_hint(
Expand Down Expand Up @@ -1750,9 +1758,10 @@ class spider_db_handler
class spider_db_copy_table
{
public:
uint dbton_id;
spider_db_share *db_share;
spider_db_copy_table(spider_db_share *db_share) :
db_share(db_share) {}
dbton_id(db_share->dbton_id), db_share(db_share) {}
virtual ~spider_db_copy_table() {}
virtual int init() = 0;
virtual void set_sql_charset(
Expand Down
Loading

0 comments on commit 4e599c7

Please sign in to comment.