Skip to content

Commit

Permalink
Add information_schema.spider_wrapper_protocols for knowing available…
Browse files Browse the repository at this point in the history
… wrappers of Spider
  • Loading branch information
Kentoku committed Jun 11, 2020
1 parent c9f262e commit 0af1b0b
Show file tree
Hide file tree
Showing 11 changed files with 262 additions and 12 deletions.
1 change: 1 addition & 0 deletions storage/spider/mysql-test/spider/include/deinit_spider.inc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ DROP FUNCTION spider_copy_tables;
DROP FUNCTION spider_ping_table;
DROP FUNCTION spider_bg_direct_sql;
DROP FUNCTION spider_direct_sql;
UNINSTALL PLUGIN spider_wrapper_protocols;
UNINSTALL PLUGIN spider_alloc_mem;
UNINSTALL PLUGIN spider;
DROP TABLE IF EXISTS mysql.spider_xa;
Expand Down
22 changes: 22 additions & 0 deletions storage/spider/mysql-test/spider/r/spider_wrapper_protocols.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
for master_1
for child2
child2_1
child2_2
child2_3
for child3
child3_1
child3_2
child3_3
connection master_1;
SELECT * FROM information_schema.spider_wrapper_protocols;
for master_1
for child2
child2_1
child2_2
child2_3
for child3
child3_1
child3_2
child3_3

end of test
16 changes: 16 additions & 0 deletions storage/spider/mysql-test/spider/t/spider_wrapper_protocols.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--disable_warnings
--disable_query_log
--disable_result_log
--source test_init.inc
--enable_query_log

--connection master_1
SELECT * FROM information_schema.spider_wrapper_protocols;

--disable_query_log
--source test_deinit.inc
--enable_result_log
--enable_query_log
--enable_warnings
--echo
--echo end of test
5 changes: 4 additions & 1 deletion storage/spider/spd_db_handlersocket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ SPIDER_DBTON spider_dbton_handlersocket = {
NULL,
spider_handlersocket_create_conn,
spider_handlersocket_support_direct_join,
&spider_db_handlersocket_utility
&spider_db_handlersocket_utility,
"For communicating using the handlersocket protocol",
"0.1.0",
SPIDER_MATURITY_BETA
};

#ifndef HANDLERSOCKET_MYSQL_UTIL
Expand Down
20 changes: 20 additions & 0 deletions storage/spider/spd_db_include.h
Original file line number Diff line number Diff line change
Expand Up @@ -1923,6 +1923,23 @@ enum spider_db_access_type
SPIDER_DB_ACCESS_TYPE_NOSQL
};

#define SPIDER_MATURITY_UNKNOWN 0
#define SPIDER_MATURITY_EXPERIMENTAL 1
#define SPIDER_MATURITY_ALPHA 2
#define SPIDER_MATURITY_BETA 3
#define SPIDER_MATURITY_GAMMA 4
#define SPIDER_MATURITY_STABLE 5

static const LEX_CSTRING maturity_name[] =
{
{ STRING_WITH_LEN("Unknown") },
{ STRING_WITH_LEN("Experimental") },
{ STRING_WITH_LEN("Alpha") },
{ STRING_WITH_LEN("Beta") },
{ STRING_WITH_LEN("Gamma") },
{ STRING_WITH_LEN("Stable") }
};

typedef struct st_spider_dbton
{
uint dbton_id;
Expand All @@ -1938,6 +1955,9 @@ typedef struct st_spider_dbton
SPIDER_DB_CONN *(*create_db_conn)(SPIDER_CONN *conn);
bool (*support_direct_join)();
spider_db_util *db_util;
const char *descr;
const char *version_info;
unsigned int maturity;
} SPIDER_DBTON;

typedef struct st_spider_position
Expand Down
10 changes: 8 additions & 2 deletions storage/spider/spd_db_mysql.cc
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,10 @@ SPIDER_DBTON spider_dbton_mysql = {
spider_mysql_create_copy_table,
spider_mysql_create_conn,
spider_mysql_support_direct_join,
&spider_db_mysql_utility
&spider_db_mysql_utility,
"For communicating to MySQL using native protocol",
"3.4.0",
SPIDER_MATURITY_STABLE
};

SPIDER_DBTON spider_dbton_mariadb = {
Expand All @@ -343,7 +346,10 @@ SPIDER_DBTON spider_dbton_mariadb = {
spider_mariadb_create_copy_table,
spider_mariadb_create_conn,
spider_mariadb_support_direct_join,
&spider_db_mariadb_utility
&spider_db_mariadb_utility,
"For communicating to MariaDB using native protocol",
"3.4.0",
SPIDER_MATURITY_STABLE
};

spider_db_mbase_row::spider_db_mbase_row(
Expand Down
5 changes: 4 additions & 1 deletion storage/spider/spd_db_oracle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,10 @@ SPIDER_DBTON spider_dbton_oracle = {
spider_oracle_create_copy_table,
spider_oracle_create_conn,
spider_oracle_support_direct_join,
&spider_db_oracle_utility
&spider_db_oracle_utility,
"For communicating Oracle using native protocol",
"1.0.0",
SPIDER_MATURITY_BETA
};

spider_db_oracle_row::spider_db_oracle_row() :
Expand Down
8 changes: 6 additions & 2 deletions storage/spider/spd_environ.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Copyright (C) 2008-2019 Kentoku Shiba
Copyright (C) 2017-2019 MariaDB corp
/* Copyright (C) 2008-2020 Kentoku Shiba
Copyright (C) 2017-2020 MariaDB corp
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
Expand Down Expand Up @@ -54,4 +54,8 @@
#define SPIDER_LIKE_FUNC_HAS_GET_NEGATED
#define HA_HAS_CHECKSUM_EXTENDED
#endif

#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100500
#define SPIDER_I_S_USE_SHOW_FOR_COLUMN
#endif
#endif /* SPD_ENVIRON_INCLUDED */
150 changes: 148 additions & 2 deletions storage/spider/spd_i_s.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* Copyright (C) 2012-2018 Kentoku Shiba
/* Copyright (C) 2012-2020 Kentoku Shiba
Copyright (C) 2020 MariaDB corp
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
Expand Down Expand Up @@ -45,7 +46,7 @@ static struct st_mysql_storage_engine spider_i_s_info =
{ MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION };

namespace Show {

#ifdef SPIDER_I_S_USE_SHOW_FOR_COLUMN
static ST_FIELD_INFO spider_i_s_alloc_mem_fields_info[] =
{
Column("ID", ULong(10), NOT_NULL, "id"),
Expand All @@ -58,6 +59,27 @@ static ST_FIELD_INFO spider_i_s_alloc_mem_fields_info[] =
Column("FREE_MEM_COUNT", ULonglong(20), NULLABLE, "free_mem_count"),
CEnd()
};
#else
static ST_FIELD_INFO spider_i_s_alloc_mem_fields_info[] =
{
{"ID", 10, MYSQL_TYPE_LONG, 0, MY_I_S_UNSIGNED, "id", SKIP_OPEN_TABLE},
{"FUNC_NAME", 64, MYSQL_TYPE_STRING, 0,
MY_I_S_MAYBE_NULL, "func_name", SKIP_OPEN_TABLE},
{"FILE_NAME", 64, MYSQL_TYPE_STRING, 0,
MY_I_S_MAYBE_NULL, "file_name", SKIP_OPEN_TABLE},
{"LINE_NO", 10, MYSQL_TYPE_LONG, 0,
MY_I_S_UNSIGNED | MY_I_S_MAYBE_NULL, "line_no", SKIP_OPEN_TABLE},
{"TOTAL_ALLOC_MEM", 20, MYSQL_TYPE_LONGLONG, 0,
MY_I_S_UNSIGNED | MY_I_S_MAYBE_NULL, "total_alloc_mem", SKIP_OPEN_TABLE},
{"CURRENT_ALLOC_MEM", 20, MYSQL_TYPE_LONGLONG, 0,
MY_I_S_MAYBE_NULL, "current_alloc_mem", SKIP_OPEN_TABLE},
{"ALLOC_MEM_COUNT", 20, MYSQL_TYPE_LONGLONG, 0,
MY_I_S_UNSIGNED | MY_I_S_MAYBE_NULL, "alloc_mem_count", SKIP_OPEN_TABLE},
{"FREE_MEM_COUNT", 20, MYSQL_TYPE_LONGLONG, 0,
MY_I_S_UNSIGNED | MY_I_S_MAYBE_NULL, "free_mem_count", SKIP_OPEN_TABLE},
{NULL, 0, MYSQL_TYPE_STRING, 0, 0, NULL, 0}
};
#endif
} // namespace Show

static int spider_i_s_alloc_mem_fill_table(
Expand Down Expand Up @@ -163,3 +185,127 @@ struct st_maria_plugin spider_i_s_alloc_mem_maria =
MariaDB_PLUGIN_MATURITY_STABLE,
};
#endif

extern SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE];

namespace Show {
#ifdef SPIDER_I_S_USE_SHOW_FOR_COLUMN
static ST_FIELD_INFO spider_i_s_wrapper_protocols_fields_info[] =
{
Column("WRAPPER_NAME", Varchar(NAME_CHAR_LEN), NOT_NULL, ""),
Column("WRAPPER_VERSION", Varchar(20), NOT_NULL, ""),
Column("WRAPPER_DESCRIPTION", Longtext(65535), NULLABLE, ""),
Column("WRAPPER_MATURITY", Varchar(12), NOT_NULL, ""),
CEnd()
};
#else
static ST_FIELD_INFO spider_i_s_wrapper_protocols_fields_info[] =
{
{"WRAPPER_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
{"WRAPPER_VERSION", 20, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
{"WRAPPER_DESCRIPTION", 65535, MYSQL_TYPE_STRING, 0, 1, 0, SKIP_OPEN_TABLE},
{"WRAPPER_MATURITY", 12, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
{0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0}
};
#endif
} // namespace Show

static int spider_i_s_wrapper_protocols_fill_table(
THD *thd,
TABLE_LIST *tables,
COND *cond
) {
uint roop_count;
SPIDER_DBTON *dbton;
TABLE *table = tables->table;
DBUG_ENTER("spider_i_s_wrapper_protocols_fill_table");
for (roop_count = 0; roop_count < SPIDER_DBTON_SIZE; roop_count++)
{
dbton = &spider_dbton[roop_count];
if (!dbton->wrapper)
{
continue;
}
table->field[0]->store(dbton->wrapper,
strlen(dbton->wrapper), system_charset_info);
table->field[1]->store(dbton->version_info,
strlen(dbton->version_info), system_charset_info);
if (dbton->descr)
{
table->field[2]->set_notnull();
table->field[2]->store(dbton->descr,
strlen(dbton->descr), system_charset_info);
} else {
table->field[2]->set_null();
}
if (dbton->maturity <= SPIDER_MATURITY_STABLE)
{
table->field[3]->store(maturity_name[dbton->maturity].str,
maturity_name[dbton->maturity].length, system_charset_info);
} else {
table->field[3]->store(maturity_name[0].str,
maturity_name[0].length, system_charset_info);
}
if (schema_table_store_record(thd, table))
{
DBUG_RETURN(1);
}
}
DBUG_RETURN(0);
}

static int spider_i_s_wrapper_protocols_init(
void *p
) {
ST_SCHEMA_TABLE *schema = (ST_SCHEMA_TABLE *) p;
DBUG_ENTER("spider_i_s_wrapper_protocols_init");
schema->fields_info = Show::spider_i_s_wrapper_protocols_fields_info;
schema->fill_table = spider_i_s_wrapper_protocols_fill_table;
schema->idx_field1 = 0;
DBUG_RETURN(0);
}

static int spider_i_s_wrapper_protocols_deinit(
void *p
) {
DBUG_ENTER("spider_i_s_wrapper_protocols_deinit");
DBUG_RETURN(0);
}

struct st_mysql_plugin spider_i_s_wrapper_protocols =
{
MYSQL_INFORMATION_SCHEMA_PLUGIN,
&spider_i_s_info,
"SPIDER_WRAPPER_PROTOCOLS",
"Kentoku Shiba, MariaDB Corp",
"Available wrapper protocols of Spider",
PLUGIN_LICENSE_GPL,
spider_i_s_wrapper_protocols_init,
spider_i_s_wrapper_protocols_deinit,
0x0001,
NULL,
NULL,
NULL,
#if MYSQL_VERSION_ID >= 50600
0,
#endif
};

#ifdef MARIADB_BASE_VERSION
struct st_maria_plugin spider_i_s_wrapper_protocols_maria =
{
MYSQL_INFORMATION_SCHEMA_PLUGIN,
&spider_i_s_info,
"SPIDER_WRAPPER_PROTOCOLS",
"Kentoku Shiba, MariaDB Corp",
"Available wrapper protocols of Spider",
PLUGIN_LICENSE_GPL,
spider_i_s_wrapper_protocols_init,
spider_i_s_wrapper_protocols_deinit,
0x0100,
NULL,
NULL,
"1.0",
MariaDB_PLUGIN_MATURITY_STABLE,
};
#endif
29 changes: 27 additions & 2 deletions storage/spider/spd_init_query.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Copyright (C) 2010-2019 Kentoku Shiba
Copyright (C) 2019 MariaDB corp
/* Copyright (C) 2010-2020 Kentoku Shiba
Copyright (C) 2019-2020 MariaDB corp
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
Expand Down Expand Up @@ -686,6 +686,31 @@ static LEX_STRING spider_init_queries[] = {
" install plugin spider_alloc_mem soname 'ha_spider.dll';"
" end if;"
" end if;"
/*
Install spider_wrapper_protocols plugin
*/
" set @have_spider_i_s_wrapper_protocols_plugin := 0;"
" select @have_spider_i_s_wrapper_protocols_plugin := 1"
" from INFORMATION_SCHEMA.plugins"
" where PLUGIN_NAME = 'SPIDER_WRAPPER_PROTOCOLS';"
" set @have_spider_wrapper_protocols_plugin := 0;"
" select @have_spider_wrapper_protocols_plugin := 1 from mysql.plugin"
" where name = 'spider_wrapper_protocols';"
" if @have_spider_i_s_wrapper_protocols_plugin = 0 then"
" if @have_spider_wrapper_protocols_plugin = 1 then"
" /*"
" spider_wrapper_protocols plugin is present in mysql.plugin but not in"
" information_schema.plugins. Remove spider_wrapper_protocols plugin entry"
" in mysql.plugin first."
" */"
" delete from mysql.plugin where name = 'spider_wrapper_protocols';"
" end if;"
" if @win_plugin = 0 then "
" install plugin spider_wrapper_protocols soname 'ha_spider.so';"
" else"
" install plugin spider_wrapper_protocols soname 'ha_spider.dll';"
" end if;"
" end if;"
" set @have_spider_direct_sql_udf := 0;"
" select @have_spider_direct_sql_udf := 1 from mysql.func"
" where name = 'spider_direct_sql';"
Expand Down
8 changes: 6 additions & 2 deletions storage/spider/spd_param.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@
#include "spd_trx.h"

extern struct st_mysql_plugin spider_i_s_alloc_mem;
extern struct st_mysql_plugin spider_i_s_wrapper_protocols;
#ifdef MARIADB_BASE_VERSION
extern struct st_maria_plugin spider_i_s_alloc_mem_maria;
extern struct st_maria_plugin spider_i_s_wrapper_protocols_maria;
#endif

extern volatile ulonglong spider_mon_table_cache_version;
Expand Down Expand Up @@ -3652,7 +3654,8 @@ mysql_declare_plugin(spider)
0,
#endif
},
spider_i_s_alloc_mem
spider_i_s_alloc_mem,
spider_i_s_wrapper_protocols
mysql_declare_plugin_end;

#ifdef MARIADB_BASE_VERSION
Expand All @@ -3672,6 +3675,7 @@ maria_declare_plugin(spider)
SPIDER_DETAIL_VERSION,
MariaDB_PLUGIN_MATURITY_BETA
},
spider_i_s_alloc_mem_maria
spider_i_s_alloc_mem_maria,
spider_i_s_wrapper_protocols_maria
maria_declare_plugin_end;
#endif

0 comments on commit 0af1b0b

Please sign in to comment.