You've already forked mariadb-connector-c
mirror of
https://github.com/mariadb-corporation/mariadb-connector-c.git
synced 2025-08-08 14:02:17 +03:00
- Fixed several aurora plugin crashes (after reconnect)
- moved mysql->reconnect to mysql->options.reconnect
This commit is contained in:
@@ -35,11 +35,11 @@ static int test_conc75(MYSQL *my)
|
||||
int rc;
|
||||
MYSQL *mysql;
|
||||
int i;
|
||||
my_bool reconnect= 1;
|
||||
|
||||
mysql= mysql_init(NULL);
|
||||
|
||||
|
||||
mysql->reconnect= 1;
|
||||
mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect);
|
||||
mysql_real_connect(mysql, hostname, username, password, schema, port, socketname, 0| CLIENT_MULTI_RESULTS | CLIENT_REMEMBER_OPTIONS);
|
||||
|
||||
rc= mysql_query(mysql, "DROP TABLE IF EXISTS a");
|
||||
@@ -55,7 +55,7 @@ static int test_conc75(MYSQL *my)
|
||||
{
|
||||
ulong thread_id= mysql_thread_id(mysql);
|
||||
/* force reconnect */
|
||||
mysql->reconnect= 1;
|
||||
mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect);
|
||||
diag("killing connection");
|
||||
mysql_kill(my, thread_id);
|
||||
sleep(2);
|
||||
@@ -700,6 +700,7 @@ static int test_reconnect_maxpackage(MYSQL *my)
|
||||
MYSQL_RES *res;
|
||||
MYSQL_ROW row;
|
||||
char *query;
|
||||
my_bool reconnect= 1;
|
||||
|
||||
SKIP_CONNECTION_HANDLER;
|
||||
mysql= mysql_init(NULL);
|
||||
@@ -707,7 +708,7 @@ static int test_reconnect_maxpackage(MYSQL *my)
|
||||
FAIL_IF(!mysql_real_connect(mysql, hostname, username, password, schema,
|
||||
port, socketname,
|
||||
CLIENT_MULTI_STATEMENTS | CLIENT_MULTI_RESULTS), mysql_error(mysql));
|
||||
mysql->reconnect= 1;
|
||||
mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect);
|
||||
|
||||
rc= mysql_query(mysql, "SELECT @@max_allowed_packet");
|
||||
check_mysql_rc(rc, mysql);
|
||||
@@ -753,12 +754,13 @@ static int test_compressed(MYSQL *my)
|
||||
int rc;
|
||||
MYSQL *mysql= mysql_init(NULL);
|
||||
MYSQL_RES *res;
|
||||
my_bool reconnect= 1;
|
||||
|
||||
mysql_options(mysql, MYSQL_OPT_COMPRESS, (void *)1);
|
||||
FAIL_IF(!mysql_real_connect(mysql, hostname, username, password, schema,
|
||||
port, socketname,
|
||||
CLIENT_MULTI_STATEMENTS | CLIENT_MULTI_RESULTS), mysql_error(mysql));
|
||||
mysql->reconnect= 1;
|
||||
mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect);
|
||||
|
||||
rc= mysql_query(mysql, "SHOW VARIABLES");
|
||||
check_mysql_rc(rc, mysql);
|
||||
|
@@ -455,16 +455,21 @@ static int test_opt_reconnect(MYSQL *mysql)
|
||||
{
|
||||
my_bool my_true= TRUE;
|
||||
int rc;
|
||||
my_bool reconnect;
|
||||
|
||||
printf("true: %d\n", TRUE);
|
||||
|
||||
mysql= mysql_init(NULL);
|
||||
FAIL_IF(!mysql, "not enough memory");
|
||||
|
||||
FAIL_UNLESS(mysql->reconnect == 0, "reconnect != 0");
|
||||
mysql_get_option(mysql, MYSQL_OPT_RECONNECT, &reconnect);
|
||||
FAIL_UNLESS(reconnect == 0, "reconnect != 0");
|
||||
|
||||
rc= mysql_options(mysql, MYSQL_OPT_RECONNECT, &my_true);
|
||||
check_mysql_rc(rc, mysql);
|
||||
|
||||
FAIL_UNLESS(mysql->reconnect == 1, "reconnect != 1");
|
||||
mysql_get_option(mysql, MYSQL_OPT_RECONNECT, &reconnect);
|
||||
FAIL_UNLESS(reconnect == 1, "reconnect != 1");
|
||||
|
||||
if (!(mysql_real_connect(mysql, hostname, username,
|
||||
password, schema, port,
|
||||
@@ -475,14 +480,16 @@ static int test_opt_reconnect(MYSQL *mysql)
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
FAIL_UNLESS(mysql->reconnect == 1, "reconnect != 1");
|
||||
mysql_get_option(mysql, MYSQL_OPT_RECONNECT, &reconnect);
|
||||
FAIL_UNLESS(reconnect == 1, "reconnect != 1");
|
||||
|
||||
mysql_close(mysql);
|
||||
|
||||
mysql= mysql_init(NULL);
|
||||
FAIL_IF(!mysql, "not enough memory");
|
||||
|
||||
FAIL_UNLESS(mysql->reconnect == 0, "reconnect != 0");
|
||||
mysql_get_option(mysql, MYSQL_OPT_RECONNECT, &reconnect);
|
||||
FAIL_UNLESS(reconnect == 0, "reconnect != 0");
|
||||
|
||||
if (!(mysql_real_connect(mysql, hostname, username,
|
||||
password, schema, port,
|
||||
@@ -493,7 +500,8 @@ static int test_opt_reconnect(MYSQL *mysql)
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
FAIL_UNLESS(mysql->reconnect == 0, "reconnect != 0");
|
||||
mysql_get_option(mysql, MYSQL_OPT_RECONNECT, &reconnect);
|
||||
FAIL_UNLESS(reconnect == 0, "reconnect != 0");
|
||||
|
||||
mysql_close(mysql);
|
||||
return OK;
|
||||
@@ -538,16 +546,19 @@ static int test_reconnect(MYSQL *mysql)
|
||||
my_bool my_true= TRUE;
|
||||
MYSQL *mysql1;
|
||||
int rc;
|
||||
my_bool reconnect;
|
||||
|
||||
mysql1= mysql_init(NULL);
|
||||
FAIL_IF(!mysql1, "not enough memory");
|
||||
|
||||
FAIL_UNLESS(mysql1->reconnect == 0, "reconnect != 0");
|
||||
mysql_get_option(mysql1, MYSQL_OPT_RECONNECT, &reconnect);
|
||||
FAIL_UNLESS(reconnect == 0, "reconnect != 0");
|
||||
|
||||
rc= mysql_options(mysql1, MYSQL_OPT_RECONNECT, &my_true);
|
||||
check_mysql_rc(rc, mysql1);
|
||||
|
||||
FAIL_UNLESS(mysql1->reconnect == 1, "reconnect != 1");
|
||||
mysql_get_option(mysql1, MYSQL_OPT_RECONNECT, &reconnect);
|
||||
FAIL_UNLESS(reconnect == 1, "reconnect != 1");
|
||||
|
||||
if (!(mysql_real_connect(mysql1, hostname, username,
|
||||
password, schema, port,
|
||||
@@ -558,7 +569,8 @@ static int test_reconnect(MYSQL *mysql)
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
FAIL_UNLESS(mysql1->reconnect == 1, "reconnect != 1");
|
||||
mysql_get_option(mysql1, MYSQL_OPT_RECONNECT, &reconnect);
|
||||
FAIL_UNLESS(reconnect == 1, "reconnect != 1");
|
||||
|
||||
diag("Thread_id before kill: %lu", mysql_thread_id(mysql1));
|
||||
mysql_kill(mysql, mysql_thread_id(mysql1));
|
||||
@@ -570,7 +582,8 @@ static int test_reconnect(MYSQL *mysql)
|
||||
check_mysql_rc(rc, mysql1);
|
||||
diag("Thread_id after kill: %lu", mysql_thread_id(mysql1));
|
||||
|
||||
FAIL_UNLESS(mysql1->reconnect == 1, "reconnect != 1");
|
||||
mysql_get_option(mysql1, MYSQL_OPT_RECONNECT, &reconnect);
|
||||
FAIL_UNLESS(reconnect == 1, "reconnect != 1");
|
||||
mysql_close(mysql1);
|
||||
return OK;
|
||||
}
|
||||
@@ -647,8 +660,10 @@ int test_connection_timeout(MYSQL *my)
|
||||
static int test_conc118(MYSQL *mysql)
|
||||
{
|
||||
int rc;
|
||||
my_bool reconnect= 1;
|
||||
|
||||
mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect);
|
||||
|
||||
mysql->reconnect= 1;
|
||||
mysql->options.unused_1= 1;
|
||||
|
||||
rc= mysql_kill(mysql, mysql_thread_id(mysql));
|
||||
@@ -745,9 +760,10 @@ static int test_bind_address(MYSQL *my)
|
||||
static int test_get_options(MYSQL *my)
|
||||
{
|
||||
MYSQL *mysql= mysql_init(NULL);
|
||||
int options_int[]= {MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_LOCAL_INFILE,
|
||||
MYSQL_OPT_RECONNECT, MYSQL_OPT_PROTOCOL, MYSQL_OPT_READ_TIMEOUT, MYSQL_OPT_WRITE_TIMEOUT, 0};
|
||||
my_bool options_bool[]= {MYSQL_OPT_COMPRESS, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_SECURE_AUTH,
|
||||
int options_int[]= {MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_OPT_LOCAL_INFILE,
|
||||
MYSQL_OPT_PROTOCOL, MYSQL_OPT_READ_TIMEOUT, MYSQL_OPT_WRITE_TIMEOUT, 0};
|
||||
my_bool options_bool[]= {MYSQL_OPT_RECONNECT, MYSQL_REPORT_DATA_TRUNCATION,
|
||||
MYSQL_OPT_COMPRESS, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_SECURE_AUTH,
|
||||
#ifdef _WIN32
|
||||
MYSQL_OPT_NAMED_PIPE,
|
||||
#endif
|
||||
|
@@ -957,6 +957,7 @@ static int test_conc_114(MYSQL *mysql)
|
||||
/* run with valgrind */
|
||||
static int test_conc117(MYSQL *mysql)
|
||||
{
|
||||
my_bool reconnect= 1;
|
||||
MYSQL *my= mysql_init(NULL);
|
||||
FAIL_IF(!mysql_real_connect(my, hostname, username, password, schema,
|
||||
port, socketname, 0), mysql_error(my));
|
||||
@@ -964,7 +965,7 @@ static int test_conc117(MYSQL *mysql)
|
||||
mysql_kill(my, mysql_thread_id(my));
|
||||
sleep(5);
|
||||
|
||||
my->reconnect= 1;
|
||||
mysql_options(my, MYSQL_OPT_RECONNECT, &reconnect);
|
||||
|
||||
mysql_query(my, "SET @a:=1");
|
||||
mysql_close(my);
|
||||
|
@@ -374,7 +374,6 @@ int check_variable(MYSQL *mysql, char *variable, char *value)
|
||||
*/
|
||||
MYSQL *test_connect(struct my_tests_st *test) {
|
||||
MYSQL *mysql;
|
||||
char query[255];
|
||||
int i= 0;
|
||||
int timeout= 10;
|
||||
int truncation_report= 1;
|
||||
@@ -401,7 +400,7 @@ MYSQL *test_connect(struct my_tests_st *test) {
|
||||
}
|
||||
}
|
||||
if (!(mysql_real_connect(mysql, hostname, username, password,
|
||||
NULL, port, socketname, (test) ? test->connect_flags:0)))
|
||||
schema, port, socketname, (test) ? test->connect_flags:0)))
|
||||
{
|
||||
diag("Couldn't establish connection to server %s. Error (%d): %s",
|
||||
hostname, mysql_errno(mysql), mysql_error(mysql));
|
||||
@@ -409,24 +408,6 @@ MYSQL *test_connect(struct my_tests_st *test) {
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
/* change database or create if it doesn't exist */
|
||||
if (mysql_select_db(mysql, schema)) {
|
||||
diag("Error number: %d", mysql_errno(mysql));
|
||||
|
||||
if(mysql_errno(mysql) == 1049) {
|
||||
sprintf(query, "CREATE DATABASE %s", schema);
|
||||
if (mysql_query(mysql, query)) {
|
||||
diag("Can't create database %s", schema);
|
||||
mysql_close(mysql);
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
diag("Error (%d): %s", mysql_errno(mysql), mysql_error(mysql));
|
||||
mysql_close(mysql);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return(mysql);
|
||||
}
|
||||
|
||||
@@ -526,6 +507,7 @@ void run_tests(struct my_tests_st *test) {
|
||||
}
|
||||
}
|
||||
if (mysql_default) {
|
||||
diag("close default");
|
||||
mysql_close(mysql_default);
|
||||
}
|
||||
mysql_server_end();
|
||||
|
@@ -52,12 +52,13 @@ static int test_conc83(MYSQL *my)
|
||||
MYSQL_STMT *stmt;
|
||||
int rc;
|
||||
MYSQL *mysql= mysql_init(NULL);
|
||||
my_bool reconnect= 1;
|
||||
|
||||
char *query= "SELECT 1,2,3 FROM DUAL";
|
||||
|
||||
stmt= mysql_stmt_init(mysql);
|
||||
|
||||
mysql->reconnect= 1;
|
||||
mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect);
|
||||
FAIL_IF(!(mysql_real_connect(mysql, hostname, username, password,
|
||||
schema, port, socketname, 0)), "mysql_real_connect failed");
|
||||
|
||||
@@ -4544,9 +4545,9 @@ static int test_stmt_close(MYSQL *mysql)
|
||||
unsigned int count;
|
||||
int rc;
|
||||
char query[MAX_TEST_QUERY_LENGTH];
|
||||
my_bool reconnect= 1;
|
||||
|
||||
|
||||
mysql->reconnect= 1;
|
||||
mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect);
|
||||
|
||||
/* set AUTOCOMMIT to ON*/
|
||||
mysql_autocommit(mysql, TRUE);
|
||||
@@ -4644,9 +4645,8 @@ static int test_new_date(MYSQL *mysql)
|
||||
MYSQL_BIND bind[1];
|
||||
int rc;
|
||||
char buffer[50];
|
||||
|
||||
|
||||
mysql->reconnect= 1;
|
||||
my_bool reconnect= 1;
|
||||
mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect);
|
||||
|
||||
/* set AUTOCOMMIT to ON*/
|
||||
mysql_autocommit(mysql, TRUE);
|
||||
|
@@ -932,6 +932,7 @@ select 1;\
|
||||
DROP TABLE IF EXISTS test_multi_tab";
|
||||
uint count, exp_value;
|
||||
uint rows[]= {0, 0, 2, 1, 3, 2, 2, 1, 1, 0, 0, 1, 0};
|
||||
my_bool reconnect= 1;
|
||||
|
||||
/*
|
||||
First test that we get an error for multi statements
|
||||
@@ -950,7 +951,7 @@ DROP TABLE IF EXISTS test_multi_tab";
|
||||
mysql_close(mysql);
|
||||
mysql= mysql_local;
|
||||
|
||||
mysql_local->reconnect= 1;
|
||||
mysql_options(mysql_local, MYSQL_OPT_RECONNECT, &reconnect);
|
||||
|
||||
rc= mysql_query(mysql_local, query);
|
||||
check_mysql_rc(rc, mysql);
|
||||
|
@@ -4,12 +4,20 @@
|
||||
#include "my_test.h"
|
||||
#include "ma_pvio.h"
|
||||
|
||||
static int aurora1(MYSQL *mysql)
|
||||
static int aurora1(MYSQL *my)
|
||||
{
|
||||
int rc;
|
||||
my_bool read_only= 1;
|
||||
const char *primary, *schema;
|
||||
const char *primary, *my_schema;
|
||||
MYSQL_RES *res;
|
||||
MYSQL *mysql= mysql_init(NULL);
|
||||
|
||||
if (!mysql_real_connect(mysql, hostname, username, password, schema, port, NULL, 0))
|
||||
{
|
||||
diag("Error: %s", mysql_error(mysql));
|
||||
mysql_close(mysql);
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1");
|
||||
check_mysql_rc(rc, mysql);
|
||||
@@ -38,8 +46,10 @@ static int aurora1(MYSQL *mysql)
|
||||
diag("Num_rows: %d", mysql_num_rows(res));
|
||||
mysql_free_result(res);
|
||||
|
||||
mariadb_get_infov(mysql, MARIADB_CONNECTION_SCHEMA, &schema);
|
||||
diag("db: %s", schema);
|
||||
mariadb_get_infov(mysql, MARIADB_CONNECTION_SCHEMA, &my_schema);
|
||||
diag("db: %s", my_schema);
|
||||
|
||||
mysql_close(mysql);
|
||||
|
||||
return OK;
|
||||
}
|
||||
@@ -58,16 +68,86 @@ static int test_wrong_user(MYSQL *my)
|
||||
return OK;
|
||||
}
|
||||
|
||||
static int test_reconnect(MYSQL *my)
|
||||
{
|
||||
MYSQL *mysql= mysql_init(NULL);
|
||||
MYSQL_RES *res;
|
||||
my_bool read_only= 1;
|
||||
int rc;
|
||||
my_bool reconnect= 1;
|
||||
const char *aurora_host;
|
||||
|
||||
mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect);
|
||||
|
||||
if (!mysql_real_connect(mysql, hostname, username, password, schema, port, NULL, 0))
|
||||
{
|
||||
diag("Error: %s", mysql_error(mysql));
|
||||
mysql_close(mysql);
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
mariadb_get_infov(mysql, MARIADB_CONNECTION_HOST, &aurora_host);
|
||||
diag("host: %s", aurora_host);
|
||||
|
||||
rc= mysql_query(mysql, "DROP TABLE IF EXISTS tx01");
|
||||
check_mysql_rc(rc, mysql);
|
||||
rc= mysql_query(mysql, "CREATE TABLE tx01 (a int)");
|
||||
check_mysql_rc(rc, mysql);
|
||||
|
||||
/* we force cluster restart and promoting new primary:
|
||||
* we wait for 50 seconds - however there is no guarantee that
|
||||
* cluster was restarted already - so this test might fail */
|
||||
system("/usr/local/aws/bin/aws rds failover-db-cluster --db-cluster-identifier instance-1-cluster");
|
||||
|
||||
sleep(50);
|
||||
diag("Q1");
|
||||
rc= mysql_query(mysql, "INSERT INTO tx01 VALUES (1)");
|
||||
if (!rc)
|
||||
diag("error expected!");
|
||||
diag("Error: %s", mysql_error(mysql));
|
||||
|
||||
diag("Q2");
|
||||
rc= mysql_query(mysql, "INSERT INTO tx01 VALUES (1)");
|
||||
if (rc)
|
||||
{
|
||||
diag("no error expected!");
|
||||
diag("Error: %s", mysql_error(mysql));
|
||||
diag("host: %s", mysql->host);
|
||||
}
|
||||
else
|
||||
{
|
||||
mariadb_get_infov(mysql, MARIADB_CONNECTION_HOST, &aurora_host);
|
||||
diag("host: %s", aurora_host);
|
||||
}
|
||||
|
||||
mysql_options(mysql, MARIADB_OPT_CONNECTION_READ_ONLY, &read_only);
|
||||
|
||||
rc= mysql_query(mysql, "SELECT * from tx01");
|
||||
check_mysql_rc(rc, mysql);
|
||||
|
||||
if ((res= mysql_store_result(mysql)))
|
||||
{
|
||||
diag("num_rows: %d", mysql_num_rows(res));
|
||||
mysql_free_result(res);
|
||||
}
|
||||
|
||||
mariadb_get_infov(mysql, MARIADB_CONNECTION_HOST, &aurora_host);
|
||||
diag("host: %s", aurora_host);
|
||||
|
||||
mysql_close(mysql);
|
||||
return OK;
|
||||
}
|
||||
|
||||
struct my_tests_st my_tests[] = {
|
||||
{"aurora1", aurora1, TEST_CONNECTION_NEW, 0, NULL, NULL},
|
||||
{"aurora1", aurora1, TEST_CONNECTION_NONE, 0, NULL, NULL},
|
||||
{"test_wrong_user", test_wrong_user, TEST_CONNECTION_NONE, 0, NULL, NULL},
|
||||
{"test_reconnect", test_reconnect, TEST_CONNECTION_NONE, 0, NULL, NULL},
|
||||
{NULL, NULL, 0, 0, NULL, NULL}
|
||||
};
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
mysql_library_init(0,0,NULL);
|
||||
|
||||
if (argc > 1)
|
||||
|
Reference in New Issue
Block a user