Commit 0a857729 authored by Yuchen Pei's avatar Yuchen Pei

MDEV-34272 create server with odbc results in connection string

We expand the tgt_odbc_str fields in SPIDER_SHARE for ha support, and
add the corresponding field in spider_direct_sql.

We also update the messages in monitoring, as odbc SERVER will cause
the usual connection fields (specifically, the one for database) not
to be populated with corresponding SERVER fields.
parent 307a2de8
......@@ -455,7 +455,7 @@ SPIDER_CONN *spider_create_conn(
&tmp_driver,
(uint) (share->tgt_drivers_lengths[link_idx] + 1),
&tmp_odbc_conn_str,
(uint) (share->tgt_odbc_conn_str_length + 1),
(uint) (share->tgt_odbc_conn_strs_lengths[link_idx] + 1),
&need_mon, (uint) (sizeof(int)),
NullS))
) {
......@@ -534,9 +534,9 @@ SPIDER_CONN *spider_create_conn(
&conn->tgt_driver_length,
share->tgt_drivers_lengths[link_idx]);
spider_memcpy_or_null(&conn->tgt_odbc_conn_str, tmp_odbc_conn_str,
share->tgt_odbc_conn_str,
share->tgt_odbc_conn_strs[link_idx],
&conn->tgt_odbc_conn_str_length,
share->tgt_odbc_conn_str_length);
share->tgt_odbc_conn_strs_lengths[link_idx]);
conn->tgt_port = share->tgt_ports[link_idx];
conn->tgt_ssl_vsc = share->tgt_ssl_vscs[link_idx];
conn->dbton_id = share->sql_dbton_ids[link_idx];
......
......@@ -19,6 +19,7 @@
#include "mysql_version.h"
#include "spd_environ.h"
#include "sql_priv.h"
#include "create_options.h"
#include "probes_mysql.h"
#include "sql_class.h"
#include "sql_partition.h"
......@@ -236,7 +237,8 @@ int spider_udf_direct_sql_create_conn_key(
+ (direct_sql->tgt_default_group ? direct_sql->tgt_default_group_length + 2 : 0)
+ (direct_sql->tgt_dsn ? direct_sql->tgt_dsn_length + 2 : 0)
+ (direct_sql->tgt_filedsn ? direct_sql->tgt_filedsn_length + 2 : 0)
+ (direct_sql->tgt_driver ? direct_sql->tgt_driver_length + 2 : 0);
+ (direct_sql->tgt_driver ? direct_sql->tgt_driver_length + 2 : 0)
+ (direct_sql->tgt_odbc_conn_str ? direct_sql->tgt_odbc_conn_str_length + 2 : 0);
if (!(direct_sql->conn_key = (char *)
spider_malloc(spider_current_trx, SPD_MID_UDF_DIRECT_SQL_CREATE_CONN_KEY_1, direct_sql->conn_key_length + 1,
MYF(MY_WME | MY_ZEROFILL)))
......@@ -277,6 +279,7 @@ int spider_udf_direct_sql_create_conn_key(
spider_create_conn_key_add_one(&counter, &tmp_name, direct_sql->tgt_dsn);
spider_create_conn_key_add_one(&counter, &tmp_name, direct_sql->tgt_filedsn);
spider_create_conn_key_add_one(&counter, &tmp_name, direct_sql->tgt_driver);
spider_create_conn_key_add_one(&counter, &tmp_name, direct_sql->tgt_odbc_conn_str);
tmp_name++;
direct_sql->conn_key_hash_value = my_calc_hash(&spider_open_connections,
(uchar*) direct_sql->conn_key, direct_sql->conn_key_length);
......@@ -309,7 +312,7 @@ SPIDER_CONN *spider_udf_direct_sql_create_conn(
char *tmp_name, *tmp_host, *tmp_username, *tmp_password, *tmp_socket;
char *tmp_wrapper, *tmp_db, *tmp_ssl_ca, *tmp_ssl_capath, *tmp_ssl_cert;
char *tmp_ssl_cipher, *tmp_ssl_key, *tmp_default_file, *tmp_default_group;
char *tmp_dsn, *tmp_filedsn, *tmp_driver;
char *tmp_dsn, *tmp_filedsn, *tmp_driver, *tmp_odbc_conn_str;
int *need_mon;
bool tables_on_different_db_are_joinable = TRUE;
DBUG_ENTER("spider_udf_direct_sql_create_conn");
......@@ -350,6 +353,8 @@ SPIDER_CONN *spider_udf_direct_sql_create_conn(
(uint) (direct_sql->tgt_filedsn_length + 1),
&tmp_driver,
(uint) (direct_sql->tgt_driver_length + 1),
&tmp_odbc_conn_str,
(uint) (direct_sql->tgt_odbc_conn_str_length + 1),
&need_mon, (uint) (sizeof(int)),
NullS))
) {
......@@ -411,6 +416,9 @@ SPIDER_CONN *spider_udf_direct_sql_create_conn(
spider_maybe_memcpy_string(
&conn->tgt_driver, direct_sql->tgt_driver, tmp_driver,
&conn->tgt_driver_length, direct_sql->tgt_driver_length);
spider_maybe_memcpy_string(
&conn->tgt_odbc_conn_str, direct_sql->tgt_odbc_conn_str, tmp_odbc_conn_str,
&conn->tgt_odbc_conn_str_length, direct_sql->tgt_odbc_conn_str_length);
conn->tgt_ssl_vsc = direct_sql->tgt_ssl_vsc;
conn->dbton_id = direct_sql->dbton_id;
conn->conn_need_mon = need_mon;
......@@ -1284,6 +1292,10 @@ void spider_udf_free_direct_sql_alloc(
{
spider_free(spider_current_trx, direct_sql->tgt_driver, MYF(0));
}
if (direct_sql->tgt_odbc_conn_str)
{
spider_free(spider_current_trx, direct_sql->tgt_odbc_conn_str, MYF(0));
}
if (direct_sql->conn_key)
{
spider_free(spider_current_trx, direct_sql->conn_key, MYF(0));
......
......@@ -163,7 +163,7 @@ typedef start_new_trans *SPIDER_Open_tables_backup;
#define SPIDER_LINK_MON_DRAW_FEW_MON 1
#define SPIDER_LINK_MON_DRAW 2
#define SPIDER_TMP_SHARE_CHAR_PTR_COUNT 23
#define SPIDER_TMP_SHARE_CHAR_PTR_COUNT 24
#define SPIDER_TMP_SHARE_UINT_COUNT SPIDER_TMP_SHARE_CHAR_PTR_COUNT
#define SPIDER_TMP_SHARE_LONG_COUNT 19
#define SPIDER_TMP_SHARE_LONGLONG_COUNT 3
......@@ -432,6 +432,7 @@ enum spider_malloc_id {
SPD_MID_PING_TABLE_MON_FROM_TABLE_1,
SPD_MID_RELEASE_PING_TABLE_MON_LIST_1,
SPD_MID_TRX_ANOTHER_LOCK_TABLES_1,
SPD_MID_TRY_ODBC_CONNECTION_STRING_1,
SPD_MID_UDF_COPY_TABLES_CREATE_TABLE_LIST_1,
SPD_MID_UDF_DIRECT_SQL_CREATE_CONN_1,
SPD_MID_UDF_DIRECT_SQL_CREATE_CONN_2,
......@@ -1188,7 +1189,7 @@ typedef struct st_spider_share
char **tgt_dsns;
char **tgt_filedsns;
char **tgt_drivers;
char *tgt_odbc_conn_str;
char **tgt_odbc_conn_strs;
char **static_link_ids;
char **tgt_pk_names;
char **tgt_sequence_names;
......@@ -1231,7 +1232,7 @@ typedef struct st_spider_share
uint *tgt_dsns_lengths;
uint *tgt_filedsns_lengths;
uint *tgt_drivers_lengths;
uint tgt_odbc_conn_str_length;
uint *tgt_odbc_conn_strs_lengths;
uint *static_link_ids_lengths;
uint *tgt_pk_names_lengths;
uint *tgt_sequence_names_lengths;
......@@ -1280,6 +1281,7 @@ typedef struct st_spider_share
uint tgt_dsns_length;
uint tgt_filedsns_length;
uint tgt_drivers_length;
uint tgt_odbc_conn_strs_length;
uint static_link_ids_length;
uint tgt_pk_names_length;
uint tgt_sequence_names_length;
......@@ -1405,6 +1407,7 @@ typedef struct st_spider_direct_sql
char *tgt_dsn;
char *tgt_filedsn;
char *tgt_driver;
char *tgt_odbc_conn_str;
char *conn_key;
long tgt_port;
long tgt_ssl_vsc;
......@@ -1426,6 +1429,7 @@ typedef struct st_spider_direct_sql
uint tgt_dsn_length;
uint tgt_filedsn_length;
uint tgt_driver_length;
uint tgt_odbc_conn_str_length;
uint conn_key_length;
uint dbton_id;
my_hash_value_type conn_key_hash_value;
......
......@@ -1602,6 +1602,7 @@ int spider_ping_table_mon_from_table(
TABLE_SHARE *table_share = share->table_share;
char link_idx_str[SPIDER_CONNECT_INFO_MAX_LEN + 1];
int link_idx_str_length;
char *db_or_server;
uint sql_command = thd_sql_command(thd);
DBUG_ENTER("spider_ping_table_mon_from_table");
if (table_share->tmp_table != NO_TMP_TABLE)
......@@ -1674,6 +1675,9 @@ int spider_ping_table_mon_from_table(
goto end;
}
db_or_server= table_mon_list->share->tgt_dbs[0];
if (!db_or_server)
db_or_server= table_mon_list->share->server_names[0];
if (table_mon_list->mon_status == SPIDER_LINK_MON_NG)
{
DBUG_PRINT("info",
......@@ -1683,8 +1687,7 @@ int spider_ping_table_mon_from_table(
pthread_mutex_unlock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]);
error_num = ER_SPIDER_LINK_MON_NG_NUM;
my_printf_error(error_num,
ER_SPIDER_LINK_MON_NG_STR, MYF(0),
table_mon_list->share->tgt_dbs[0],
ER_SPIDER_LINK_MON_NG_STR, MYF(0), db_or_server,
table_mon_list->share->tgt_table_names[0]);
my_afree(buf);
goto end_with_free_table_mon_list;
......@@ -1722,8 +1725,7 @@ int spider_ping_table_mon_from_table(
"spider mon_table_result->result_status=SPIDER_LINK_MON_DRAW_FEW_MON 1"));
error_num = ER_SPIDER_LINK_MON_DRAW_FEW_MON_NUM;
my_printf_error(error_num,
ER_SPIDER_LINK_MON_DRAW_FEW_MON_STR, MYF(0),
table_mon_list->share->tgt_dbs[0],
ER_SPIDER_LINK_MON_DRAW_FEW_MON_STR, MYF(0), db_or_server,
table_mon_list->share->tgt_table_names[0]);
break;
}
......@@ -1772,7 +1774,7 @@ int spider_ping_table_mon_from_table(
error_num = ER_SPIDER_LINK_MON_OK_NUM;
my_printf_error(error_num,
ER_SPIDER_LINK_MON_OK_STR, MYF(0),
table_mon_list->share->tgt_dbs[0],
db_or_server,
table_mon_list->share->tgt_table_names[0]);
break;
}
......@@ -1781,7 +1783,7 @@ int spider_ping_table_mon_from_table(
error_num = ER_SPIDER_LINK_MON_NG_NUM;
my_printf_error(error_num,
ER_SPIDER_LINK_MON_NG_STR, MYF(0),
table_mon_list->share->tgt_dbs[0],
db_or_server,
table_mon_list->share->tgt_table_names[0]);
break;
}
......@@ -1791,14 +1793,14 @@ int spider_ping_table_mon_from_table(
error_num = ER_SPIDER_LINK_MON_DRAW_FEW_MON_NUM;
my_printf_error(error_num,
ER_SPIDER_LINK_MON_DRAW_FEW_MON_STR, MYF(0),
table_mon_list->share->tgt_dbs[0],
db_or_server,
table_mon_list->share->tgt_table_names[0]);
break;
}
error_num = ER_SPIDER_LINK_MON_DRAW_NUM;
my_printf_error(error_num,
ER_SPIDER_LINK_MON_DRAW_STR, MYF(0),
table_mon_list->share->tgt_dbs[0],
db_or_server,
table_mon_list->share->tgt_table_names[0]);
break;
}
......@@ -1825,29 +1827,25 @@ int spider_ping_table_mon_from_table(
case SPIDER_LINK_MON_OK:
error_num = ER_SPIDER_LINK_MON_OK_NUM;
my_printf_error(error_num,
ER_SPIDER_LINK_MON_OK_STR, MYF(0),
table_mon_list->share->tgt_dbs[0],
ER_SPIDER_LINK_MON_OK_STR, MYF(0), db_or_server,
table_mon_list->share->tgt_table_names[0]);
break;
case SPIDER_LINK_MON_NG:
error_num = ER_SPIDER_LINK_MON_NG_NUM;
my_printf_error(error_num,
ER_SPIDER_LINK_MON_NG_STR, MYF(0),
table_mon_list->share->tgt_dbs[0],
ER_SPIDER_LINK_MON_NG_STR, MYF(0), db_or_server,
table_mon_list->share->tgt_table_names[0]);
break;
case SPIDER_LINK_MON_DRAW_FEW_MON:
error_num = ER_SPIDER_LINK_MON_DRAW_FEW_MON_NUM;
my_printf_error(error_num,
ER_SPIDER_LINK_MON_DRAW_FEW_MON_STR, MYF(0),
table_mon_list->share->tgt_dbs[0],
ER_SPIDER_LINK_MON_DRAW_FEW_MON_STR, MYF(0), db_or_server,
table_mon_list->share->tgt_table_names[0]);
break;
default:
error_num = ER_SPIDER_LINK_MON_DRAW_NUM;
my_printf_error(error_num,
ER_SPIDER_LINK_MON_DRAW_STR, MYF(0),
table_mon_list->share->tgt_dbs[0],
ER_SPIDER_LINK_MON_DRAW_STR, MYF(0), db_or_server,
table_mon_list->share->tgt_table_names[0]);
break;
}
......
......@@ -860,8 +860,17 @@ int spider_free_share_alloc(
}
spider_free(spider_current_trx, share->tgt_drivers, MYF(0));
}
if (share->tgt_odbc_conn_str)
spider_free(spider_current_trx, share->tgt_odbc_conn_str, MYF(0));
if (share->tgt_odbc_conn_strs)
{
for (roop_count = 0; roop_count < (int) share->tgt_odbc_conn_strs_length;
roop_count++)
{
if (share->tgt_odbc_conn_strs[roop_count])
spider_free(spider_current_trx, share->tgt_odbc_conn_strs[roop_count],
MYF(0));
}
spider_free(spider_current_trx, share->tgt_odbc_conn_strs, MYF(0));
}
if (share->tgt_pk_names)
{
for (roop_count = 0; roop_count < (int) share->tgt_pk_names_length;
......@@ -1040,6 +1049,11 @@ void spider_free_tmp_share_alloc(
spider_free(spider_current_trx, share->tgt_drivers[0], MYF(0));
share->tgt_drivers[0] = NULL;
}
if (share->tgt_odbc_conn_strs && share->tgt_odbc_conn_strs[0])
{
spider_free(spider_current_trx, share->tgt_odbc_conn_strs[0], MYF(0));
share->tgt_odbc_conn_strs[0] = NULL;
}
if (share->tgt_pk_names && share->tgt_pk_names[0])
{
spider_free(spider_current_trx, share->tgt_pk_names[0], MYF(0));
......@@ -3322,6 +3336,14 @@ int spider_parse_connect_info(
&share->tgt_drivers_charlen,
share->all_link_count)))
goto error;
uint unused_charlen;
if ((error_num = spider_increase_string_list(
&share->tgt_odbc_conn_strs,
&share->tgt_odbc_conn_strs_lengths,
&share->tgt_odbc_conn_strs_length,
&unused_charlen,
share->all_link_count)))
goto error;
if ((error_num = spider_increase_string_list(
&share->tgt_pk_names,
&share->tgt_pk_names_lengths,
......@@ -4617,7 +4639,8 @@ int spider_create_conn_keys(
+ (share->tgt_default_groups[all_link_idx] ? share->tgt_default_groups_lengths[all_link_idx] + 2 : 0)
+ (share->tgt_dsns[all_link_idx] ? share->tgt_dsns_lengths[all_link_idx] + 2 : 0)
+ (share->tgt_filedsns[all_link_idx] ? share->tgt_filedsns_lengths[all_link_idx] + 2 : 0)
+ (share->tgt_drivers[all_link_idx] ? share->tgt_drivers_lengths[all_link_idx] + 2 : 0);
+ (share->tgt_drivers[all_link_idx] ? share->tgt_drivers_lengths[all_link_idx] + 2 : 0)
+ (share->tgt_odbc_conn_strs[all_link_idx] ? share->tgt_odbc_conn_strs_lengths[all_link_idx] + 2 : 0);
share->conn_keys_charlen += conn_keys_lengths[all_link_idx] + 1;
}
if (!(share->conn_keys = (char **)
......@@ -4686,6 +4709,7 @@ int spider_create_conn_keys(
spider_create_conn_key_add_one(&counter, &tmp_name, share->tgt_dsns[roop_count]);
spider_create_conn_key_add_one(&counter, &tmp_name, share->tgt_filedsns[roop_count]);
spider_create_conn_key_add_one(&counter, &tmp_name, share->tgt_drivers[roop_count]);
spider_create_conn_key_add_one(&counter, &tmp_name, share->tgt_odbc_conn_strs[roop_count]);
tmp_name++;
tmp_name++;
share->conn_keys_hash_value[roop_count] = my_calc_hash(
......@@ -7436,6 +7460,7 @@ void spider_set_tmp_share_pointer(
tmp_share->tgt_pk_names = &tmp_connect_info[18];
tmp_share->tgt_sequence_names = &tmp_connect_info[19];
tmp_share->static_link_ids = &tmp_connect_info[20];
tmp_share->tgt_odbc_conn_strs = &tmp_connect_info[23];
tmp_share->tgt_ports = &tmp_long[0];
tmp_share->tgt_ssl_vscs = &tmp_long[1];
tmp_share->link_statuses = &tmp_long[2];
......@@ -7476,6 +7501,7 @@ void spider_set_tmp_share_pointer(
tmp_share->tgt_pk_names_lengths = &tmp_connect_info_length[18];
tmp_share->tgt_sequence_names_lengths = &tmp_connect_info_length[19];
tmp_share->static_link_ids_lengths = &tmp_connect_info_length[20];
tmp_share->tgt_odbc_conn_strs_lengths = &tmp_connect_info_length[23];
tmp_share->server_names_length = 1;
tmp_share->tgt_table_names_length = 1;
tmp_share->tgt_dbs_length = 1;
......@@ -7494,6 +7520,7 @@ void spider_set_tmp_share_pointer(
tmp_share->tgt_dsns_length = 1;
tmp_share->tgt_filedsns_length = 1;
tmp_share->tgt_drivers_length = 1;
tmp_share->tgt_odbc_conn_strs_length = 1;
tmp_share->tgt_pk_names_length = 1;
tmp_share->tgt_sequence_names_length = 1;
tmp_share->static_link_ids_length = 1;
......
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