Commit 4e599c74 authored by Kentoku's avatar Kentoku Committed by Sergei Golubchik

MDEV-18313 Supports 'wrapper mariadb' for connection information

parent 470c1b8d
......@@ -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
)
......
--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
--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 %';
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
!include include/default_mysqld.cnf
!include ../my_1_1.cnf
!include ../my_2_1.cnf
--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
......@@ -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);
}
......@@ -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));
......@@ -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),
......
/* 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;
}
......@@ -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
......@@ -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(
......@@ -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;
......@@ -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;
......@@ -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(
......@@ -1264,6 +1270,7 @@ 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;
......@@ -1271,7 +1278,8 @@ class spider_db_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(
......@@ -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(
......
This diff is collapsed.
......@@ -13,11 +13,11 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
class spider_db_mysql_util: public spider_db_util
class spider_db_mbase_util: public spider_db_util
{
public:
spider_db_mysql_util();
~spider_db_mysql_util();
spider_db_mbase_util();
virtual ~spider_db_mbase_util();
int append_name(
spider_string *str,
const char *name,
......@@ -174,7 +174,21 @@ class spider_db_mysql_util: public spider_db_util
#endif
};
class spider_db_mysql_row: public spider_db_row
class spider_db_mysql_util: public spider_db_mbase_util
{
public:
spider_db_mysql_util();
~spider_db_mysql_util();
};
class spider_db_mariadb_util: public spider_db_mbase_util
{
public:
spider_db_mariadb_util();
~spider_db_mariadb_util();
};
class spider_db_mbase_row: public spider_db_row
{
public:
MYSQL_ROW row;
......@@ -184,8 +198,10 @@ class spider_db_mysql_row: public spider_db_row
uint field_count;
uint record_size;
bool cloned;
spider_db_mysql_row();
~spider_db_mysql_row();
spider_db_mbase_row(
uint dbton_id
);
virtual ~spider_db_mbase_row();
int store_to_field(
Field *field,
CHARSET_INFO *access_charset
......@@ -214,15 +230,31 @@ class spider_db_mysql_row: public spider_db_row
uint get_byte_size();
};
class spider_db_mysql_result: public spider_db_result
class spider_db_mysql_row: public spider_db_mbase_row
{
public:
spider_db_mysql_row();
~spider_db_mysql_row();
};
class spider_db_mariadb_row: public spider_db_mbase_row
{
public:
spider_db_mariadb_row();
~spider_db_mariadb_row();
};
class spider_db_mbase_result: public spider_db_result
{
public:
MYSQL_RES *db_result;
spider_db_mysql_row row;
spider_db_mbase_row row;
MYSQL_ROW_OFFSET first_row;
int store_error_num;
spider_db_mysql_result(SPIDER_DB_CONN *in_db_conn);
~spider_db_mysql_result();
spider_db_mbase_result(
SPIDER_DB_CONN *in_db_conn
);
virtual ~spider_db_mbase_result();
bool has_result();
void free_result();
SPIDER_DB_ROW *current_row();
......@@ -289,9 +321,29 @@ class spider_db_mysql_result: public spider_db_result
#endif
};
class spider_db_mysql: public spider_db_conn
class spider_db_mysql_result: public spider_db_mbase_result
{
public:
spider_db_mysql_result(
SPIDER_DB_CONN *in_db_conn
);
~spider_db_mysql_result();
};
class spider_db_mariadb_result: public spider_db_mbase_result
{
public:
spider_db_mariadb_result(
SPIDER_DB_CONN *in_db_conn
);
~spider_db_mariadb_result();
};
class spider_db_mbase: public spider_db_conn
{
int stored_error;
protected:
int stored_error;
spider_db_mbase_util *spider_db_mbase_utility;
public:
MYSQL *db_conn;
HASH lock_table_hash;
......@@ -306,10 +358,11 @@ class spider_db_mysql: public spider_db_conn
const char *handler_open_array_func_name;
const char *handler_open_array_file_name;
ulong handler_open_array_line_no;
spider_db_mysql(
SPIDER_CONN *conn
spider_db_mbase(
SPIDER_CONN *conn,
spider_db_mbase_util *spider_db_mbase_utility
);
~spider_db_mysql();
virtual ~spider_db_mbase();
int init();
bool is_connected();
void bg_connect();
......@@ -524,8 +577,28 @@ class spider_db_mysql: public spider_db_conn
);
};
class spider_mysql_share: public spider_db_share
class spider_db_mysql: public spider_db_mbase
{
public:
spider_db_mysql(
SPIDER_CONN *conn
);
~spider_db_mysql();
};
class spider_db_mariadb: public spider_db_mbase
{
public:
spider_db_mariadb(
SPIDER_CONN *conn
);
~spider_db_mariadb();
};
class spider_mbase_share: public spider_db_share
{
protected:
spider_db_mbase_util *spider_db_mbase_utility;
public:
spider_string *table_select;
int table_select_pos;
......@@ -547,10 +620,12 @@ class spider_mysql_share: public spider_db_share
bool same_db_table_name;
int first_all_link_idx;
spider_mysql_share(
st_spider_share *share
spider_mbase_share(
st_spider_share *share,
uint dbton_id,
spider_db_mbase_util *spider_db_mbase_utility
);
~spider_mysql_share();
virtual ~spider_mbase_share();
int init();
uint get_column_name_length(
uint field_index
......@@ -585,7 +660,7 @@ class spider_mysql_share: public spider_db_share
spider_string *str
);
#endif
private:
protected:
int create_table_names_str();
void free_table_names_str();
int create_column_name_str();
......@@ -603,8 +678,28 @@ class spider_mysql_share: public spider_db_share
);
};
class spider_mysql_handler: public spider_db_handler
class spider_mysql_share: public spider_mbase_share
{
public:
spider_mysql_share(
st_spider_share *share
);
~spider_mysql_share();
};
class spider_mariadb_share: public spider_mbase_share
{
public:
spider_mariadb_share(
st_spider_share *share
);
~spider_mariadb_share();
};
class spider_mbase_handler: public spider_db_handler
{
protected:
spider_db_mbase_util *spider_db_mbase_utility;
spider_string sql;
spider_string sql_part;
spider_string sql_part2;
......@@ -614,7 +709,7 @@ class spider_mysql_handler: public spider_db_handler
int limit_pos;
public:
int table_name_pos;
private:
protected:
int ha_read_pos;
int ha_next_pos;
int ha_where_pos;
......@@ -647,14 +742,15 @@ class spider_mysql_handler: public spider_db_handler
SPIDER_INT_HLD *union_table_name_pos_first;
SPIDER_INT_HLD *union_table_name_pos_current;
public:
spider_mysql_share *mysql_share;
spider_mbase_share *mysql_share;
SPIDER_LINK_FOR_HASH *link_for_hash;
uchar *minimum_select_bitmap;
spider_mysql_handler(
spider_mbase_handler(
ha_spider *spider,
spider_mysql_share *share
spider_mbase_share *share,
spider_db_mbase_util *spider_db_mbase_utility
);
~spider_mysql_handler();
virtual ~spider_mbase_handler();
int init();
int append_index_hint(
spider_string *str,
......@@ -1498,16 +1594,36 @@ class spider_mysql_handler: public spider_db_handler
#endif
};
class spider_mysql_copy_table: public spider_db_copy_table
class spider_mysql_handler: public spider_mbase_handler
{
public:
spider_mysql_handler(
ha_spider *spider,
spider_mbase_share *share
);
~spider_mysql_handler();
};
class spider_mariadb_handler: public spider_mbase_handler
{
public:
spider_mysql_share *mysql_share;
spider_mariadb_handler(
ha_spider *spider,
spider_mbase_share *share
);
~spider_mariadb_handler();
};
class spider_mbase_copy_table: public spider_db_copy_table
{
public:
spider_mbase_share *mysql_share;
spider_string sql;
uint pos;
spider_mysql_copy_table(
spider_mysql_share *db_share
spider_mbase_copy_table(
spider_mbase_share *db_share
);
~spider_mysql_copy_table();
virtual ~spider_mbase_copy_table();
int init();
void set_sql_charset(
CHARSET_INFO *cs
......@@ -1578,3 +1694,21 @@ class spider_mysql_copy_table: public spider_db_copy_table
spider_db_copy_table *source_ct
);
};
class spider_mysql_copy_table: public spider_mbase_copy_table
{
public:
spider_mysql_copy_table(
spider_mbase_share *db_share
);
~spider_mysql_copy_table();
};
class spider_mariadb_copy_table: public spider_mbase_copy_table
{
public:
spider_mariadb_copy_table(
spider_mbase_share *db_share
);
~spider_mariadb_copy_table();
};
......@@ -512,7 +512,7 @@ SPIDER_DB_ROW *spider_db_oracle_row::clone()
spider_db_oracle_row *clone_row;
DBUG_ENTER("spider_db_oracle_row::clone");
DBUG_PRINT("info",("spider this=%p", this));
if (!(clone_row = new spider_db_oracle_row()))
if (!(clone_row = new spider_db_oracle_row(dbton_id)))
{
DBUG_RETURN(NULL);
}
......@@ -772,9 +772,9 @@ int spider_db_oracle_row::fetch()
}
spider_db_oracle_result::spider_db_oracle_result(SPIDER_DB_CONN *in_db_conn) :
spider_db_result(in_db_conn, spider_dbton_oracle.dbton_id),
spider_db_result(in_db_conn),
db_conn(NULL), stmtp(NULL), field_count(0), access_charset(NULL),
fetched(FALSE)
fetched(FALSE), row(in_db_conn->dbton_id)
{
DBUG_ENTER("spider_db_oracle_result::spider_db_oracle_result");
DBUG_PRINT("info",("spider this=%p", this));
......@@ -4365,7 +4365,8 @@ int spider_db_oracle_util::append_having(
spider_oracle_share::spider_oracle_share(
st_spider_share *share
) : spider_db_share(
share
share,
spider_dbton_oracle.dbton_id
),
table_select(NULL),
table_select_pos(0),
......
......@@ -128,6 +128,7 @@ extern long spider_conn_mutex_id;
handlerton *spider_hton_ptr;
SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE];
extern SPIDER_DBTON spider_dbton_mysql;
extern SPIDER_DBTON spider_dbton_mariadb;
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
extern SPIDER_DBTON spider_dbton_handlersocket;
#endif
......@@ -7362,15 +7363,22 @@ int spider_db_init(
#endif
spider_dbton_mysql.dbton_id = dbton_id;
spider_dbton_mysql.db_util->dbton_id = dbton_id;
spider_dbton[dbton_id] = spider_dbton_mysql;
++dbton_id;
spider_dbton_mariadb.dbton_id = dbton_id;
spider_dbton_mariadb.db_util->dbton_id = dbton_id;
spider_dbton[dbton_id] = spider_dbton_mariadb;
++dbton_id;
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
spider_dbton_handlersocket.dbton_id = dbton_id;
spider_dbton_handlersocket.db_util->dbton_id = dbton_id;
spider_dbton[dbton_id] = spider_dbton_handlersocket;
++dbton_id;
#endif
#ifdef HAVE_ORACLE_OCI
spider_dbton_oracle.dbton_id = dbton_id;
spider_dbton_oracle.db_util->dbton_id = dbton_id;
spider_dbton[dbton_id] = spider_dbton_oracle;
++dbton_id;
#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