use inludes from our deps intead of system

v2.6.0-more-makefile-fixes
Miro Stauder 3 years ago
parent c92a93b69b
commit c78819bda9

@ -1,9 +1,9 @@
#ifndef __CLASS_PROXYSQL_ADMIN_H
#define __CLASS_PROXYSQL_ADMIN_H
#include <prometheus/exposer.h>
#include <prometheus/counter.h>
#include <prometheus/gauge.h>
#include "prometheus/exposer.h"
#include "prometheus/counter.h"
#include "prometheus/gauge.h"
#include "query_processor.h"
#include "proxy_defines.h"

@ -5,7 +5,7 @@
#define CLUSTER_SYNC_INTERFACES_MYSQL "('mysql-interfaces')"
#include <memory>
#include <prometheus/registry.h>
#include "prometheus/registry.h"
#include "configfile.hpp"
#include "proxy_defines.h"

@ -4,8 +4,8 @@
#include <string>
#include <stdio.h>
#include <mysql.h>
#include <mysql/mysqld_error.h>
#include "mysql.h"
#include "mysql/mysqld_error.h"
#include "proxysql_utils.h"
#include "tap.h"

@ -6,8 +6,8 @@
#include <vector>
#include <tuple>
#include <mysql.h>
#include <mysql/mysqld_error.h>
#include "mysql.h"
#include "mysql/mysqld_error.h"
#include "tap.h"
#include "command_line.h"

@ -6,8 +6,8 @@
#include <vector>
#include <tuple>
#include <mysql.h>
#include <mysql/mysqld_error.h>
#include "mysql.h"
#include "mysql/mysqld_error.h"
#include "tap.h"
#include "command_line.h"

@ -6,8 +6,8 @@
#include <vector>
#include <tuple>
#include <mysql.h>
#include <mysql/mysqld_error.h>
#include "mysql.h"
#include "mysql/mysqld_error.h"
#include "tap.h"
#include "command_line.h"

@ -6,8 +6,8 @@
#include <vector>
#include <tuple>
#include <mysql.h>
#include <mysql/mysqld_error.h>
#include "mysql.h"
#include "mysql/mysqld_error.h"
#include "tap.h"
#include "command_line.h"

@ -6,8 +6,8 @@
#include <vector>
#include <tuple>
#include <mysql.h>
#include <mysql/mysqld_error.h>
#include "mysql.h"
#include "mysql/mysqld_error.h"
#include "tap.h"
#include "command_line.h"

@ -6,8 +6,8 @@
#include <vector>
#include <tuple>
#include <mysql.h>
#include <mysql/mysqld_error.h>
#include "mysql.h"
#include "mysql/mysqld_error.h"
#include "tap.h"
#include "command_line.h"

@ -4,7 +4,7 @@
#include <unistd.h>
#include <string>
#include <mysql.h>
#include "mysql.h"
#include "tap.h"
#include "command_line.h"

@ -6,8 +6,8 @@
#include <vector>
#include <tuple>
#include <mysql.h>
#include <mysql/mysqld_error.h>
#include "mysql.h"
#include "mysql/mysqld_error.h"
#include "tap.h"
#include "command_line.h"

@ -3,7 +3,7 @@
#include <stdio.h>
#include <cstring>
#include <unistd.h>
#include <mysql.h>
#include "mysql.h"
#include "tap.h"
#include "command_line.h"

@ -3,7 +3,7 @@
#include <stdio.h>
#include <cstring>
#include <unistd.h>
#include <mysql.h>
#include "mysql.h"
#include "tap.h"
#include "command_line.h"

@ -3,7 +3,7 @@
#include <stdio.h>
#include <cstring>
#include <unistd.h>
#include <mysql.h>
#include "mysql.h"
#include "tap.h"
#include "command_line.h"

@ -24,8 +24,8 @@
#include <vector>
#include <unistd.h>
#include <mysql.h>
#include <mysql/mysqld_error.h>
#include "mysql.h"
#include "mysql/mysqld_error.h"
#include "json.hpp"

@ -21,8 +21,8 @@ It stresses how proxysql managers prepared statements, specifically:
#include <tuple>
#include <unistd.h>
#include <mysql.h>
#include <mysql/mysqld_error.h>
#include "mysql.h"
#include "mysql/mysqld_error.h"
#include "command_line.h"
#include "proxysql_utils.h"

@ -3,7 +3,7 @@
#include <stdio.h>
#include <cstring>
#include <unistd.h>
#include <mysql.h>
#include "mysql.h"
#include "tap.h"
#include "command_line.h"

@ -5,7 +5,7 @@
#include <string>
#include <sstream>
#include <mysql.h>
#include "mysql.h"
#include "tap.h"
#include "command_line.h"

@ -5,7 +5,7 @@
#include <string>
#include <sstream>
#include <mysql.h>
#include "mysql.h"
#include "tap.h"
#include "command_line.h"

@ -5,7 +5,7 @@
#include <string>
#include <sstream>
#include <mysql.h>
#include "mysql.h"
#include "tap.h"
#include "command_line.h"

@ -3,7 +3,7 @@
#include <stdio.h>
#include <cstring>
#include <unistd.h>
#include <mysql.h>
#include "mysql.h"
#include "tap.h"
#include "command_line.h"

@ -5,7 +5,7 @@
#include <string>
#include <sstream>
#include <mysql.h>
#include "mysql.h"
#include "tap.h"
#include "command_line.h"

@ -5,7 +5,7 @@
#include <string>
#include <sstream>
#include <mysql.h>
#include "mysql.h"
#include "tap.h"
#include "command_line.h"

@ -5,7 +5,7 @@
#include <string>
#include <sstream>
#include <mysql.h>
#include "mysql.h"
#include <dirent.h>
#include "tap.h"

@ -15,8 +15,8 @@
#include <fstream>
#include <unistd.h>
#include <mysql.h>
#include <mysql/mysqld_error.h>
#include "mysql.h"
#include "mysql/mysqld_error.h"
#include "json.hpp"

@ -3,7 +3,7 @@
#include <stdio.h>
#include <cstring>
#include <unistd.h>
#include <mysql.h>
#include "mysql.h"
#include "tap.h"
#include "command_line.h"

@ -3,7 +3,7 @@
#include <stdio.h>
#include <cstring>
#include <unistd.h>
#include <mysql.h>
#include "mysql.h"
#include "tap.h"
#include "command_line.h"

@ -11,7 +11,7 @@
#include <stdio.h>
#include <unistd.h>
#include <vector>
#include <mysql.h>
#include "mysql.h"
#include "tap.h"
#include "command_line.h"

@ -8,8 +8,8 @@
#include <string>
#include <stdio.h>
#include <mysql.h>
#include <mysql/mysqld_error.h>
#include "mysql.h"
#include "mysql/mysqld_error.h"
#include "tap.h"
#include "command_line.h"

@ -20,7 +20,7 @@
#include <cstring>
#include <unistd.h>
#include <mysql.h>
#include "mysql.h"
#include "tap.h"
#include "command_line.h"

@ -21,7 +21,7 @@
#include <time.h>
#include <iostream>
#include <mysql.h>
#include "mysql.h"
#include "tap.h"
#include "command_line.h"

@ -7,8 +7,8 @@
#include <vector>
#include <string>
#include <stdio.h>
#include <mysql.h>
#include <mysql/mysqld_error.h>
#include "mysql.h"
#include "mysql/mysqld_error.h"
#include "tap.h"
#include "command_line.h"

@ -13,7 +13,7 @@
#include <vector>
#include <string>
#include <stdio.h>
#include <mysql.h>
#include "mysql.h"
#include "tap.h"
#include "command_line.h"

@ -8,8 +8,8 @@
#include <string>
#include <sstream>
#include <stdio.h>
#include <mysql.h>
#include <mysql/mysqld_error.h>
#include "mysql.h"
#include "mysql/mysqld_error.h"
#include "tap.h"
#include "command_line.h"

@ -28,7 +28,7 @@
#include <poll.h>
#include <sys/epoll.h>
#include <mysql.h>
#include "mysql.h"
#include <thread>
#include "tap.h"

@ -13,7 +13,7 @@
#include <stdio.h>
#include <functional>
#include <mysql.h>
#include "mysql.h"
#include "tap.h"
#include "command_line.h"

@ -9,7 +9,7 @@
#include <vector>
#include <string>
#include <stdio.h>
#include <mysql.h>
#include "mysql.h"
#include "tap.h"
#include "command_line.h"

@ -1 +0,0 @@
reg_test_3427-stmt_first_comment1-t.cpp

@ -0,0 +1,284 @@
/**
* @file reg_test_3427-stmt_first_comment-t.cpp
* @brief This test is a regression test for exercising all code related to
* 'first_comment' changes added in PR #3453.
* @details Testing revealed that the fix introduced for proper routing of
* prepared statements with query rules has invalid interaction with query
* annotation 'hostgroup' feature.
* For solving the issue, 'first_comment' was made part of 'MySQL_STMT_Global_info'.
* This test aims to exercise all the parts of ProxySQL affected by this change.
*
* Procedure:
* =========
*
* The test creates a number of prepared statements and execute them, until passing
* the limit of prepared statements allowed per connection. After the connection
* has been reset by ProxySQL because of the limit exceeding, it tries to execute
* the same prepared statements again. This way those prepared statements wont be
* available in the connection and will need to be fetched by ProxySQL for the
* reset connection.
*/
#include <iostream>
#include <chrono>
#include <ctime>
#include <cstring>
#include <unistd.h>
#include <time.h>
#include <vector>
#include <string>
#include <stdio.h>
#include "mysql.h"
#include "mysql/mysqld_error.h"
#include "proxysql_utils.h"
#include "tap.h"
#include "command_line.h"
#include "utils.h"
#include "errno.h"
/**
* @brief String size of the columns created for the testing table.
*/
const int STRING_SIZE=32;
/**
* @brief Number of max stmt per connection to be configured for
* ProxySQL.
*/
const uint32_t MAX_STMT_NUM_QUERIES = 20;
/**
* @brief Number of queries to RESET the connection being target,
* it's simply: MAX_STMT_NUM_QUERIES + 1
*/
const uint32_t RESET_CONNECTION_QUERIES = 2*MAX_STMT_NUM_QUERIES;
/**
* @brief Id for the current writer hostgroup.
*/
const uint32_t WRITER_HOSTGROUP_ID = 0;
int main(int argc, char** argv) {
int res = EXIT_SUCCESS;
CommandLine cl;
if (cl.getEnv()) {
diag("Failed to get the required environmental variables.");
return -1;
}
plan(5*RESET_CONNECTION_QUERIES);
bool param = false;
{
// we parse argv[0] to see if filename includes "param"
std::string str = std::string(argv[0]);
std::size_t found = str.find("param");
if (found!=std::string::npos) {
param = true;
}
}
MYSQL* proxysql_mysql = mysql_init(NULL);
MYSQL* proxysql_admin = mysql_init(NULL);
if (!mysql_real_connect(proxysql_mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) {
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_mysql));
return -1;
}
if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) {
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin));
return -1;
}
// Insert data in the table to be queried
// *************************************************************************
MYSQL_QUERY(proxysql_mysql, "CREATE DATABASE IF NOT EXISTS test");
MYSQL_QUERY(proxysql_mysql, "DROP TABLE IF EXISTS test.reg_test_3427");
MYSQL_QUERY(
proxysql_mysql,
"CREATE TABLE IF NOT EXISTS test.reg_test_3427"
" (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, `c1` BIGINT, `c2` varchar(32))"
);
MYSQL_QUERY(proxysql_mysql, "INSERT INTO test.reg_test_3427(c1, c2) VALUES (100, 'abcde')");
mysql_close(proxysql_mysql);
// Initialize the connection again
proxysql_mysql = mysql_init(NULL);
if (!mysql_real_connect(proxysql_mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) {
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_mysql));
return -1;
}
// *************************************************************************
{
// Set the number of maximum connections for servers in the writer hostgroup
std::string t_update_mysql_servers {
"UPDATE mysql_servers SET max_connections=1 WHERE hostgroup_id=%d"
};
std::string update_mysql_queries {};
string_format(t_update_mysql_servers, update_mysql_queries, WRITER_HOSTGROUP_ID);
MYSQL_QUERY(proxysql_admin, update_mysql_queries.c_str());
MYSQL_QUERY(proxysql_admin, "LOAD MYSQL SERVERS TO RUNTIME");
// Set the number of maximum prepared statements per connection
std::string t_max_stmt_query {
"SET mysql-max_stmts_per_connection=%d"
};
std::string max_stmt_query {};
string_format(t_max_stmt_query, max_stmt_query, MAX_STMT_NUM_QUERIES);
MYSQL_QUERY(proxysql_admin, max_stmt_query.c_str());
MYSQL_QUERY(proxysql_admin, "LOAD MYSQL VARIABLES TO RUNTIME");
uint32_t query_id = 0;
for (uint32_t i = 0; i < RESET_CONNECTION_QUERIES; i++) {
if (i <= MAX_STMT_NUM_QUERIES) {
query_id = i;
} else if (i == MAX_STMT_NUM_QUERIES + 1) {
query_id = 0;
} else {
query_id += 1;
}
// create unique stmt
std::string query_t {};
if (param) {
query_t = "SELECT /* ;hostgroup=0;%d */ * FROM test.reg_test_3427 WHERE id IN (?)";
} else {
query_t = "SELECT /* ;hostgroup=0;%d */ * FROM test.reg_test_3427";
}
std::string query {};
string_format(query_t, query, query_id);
MYSQL_STMT* stmt = mysql_stmt_init(proxysql_mysql);
if (!stmt) {
diag("mysql_stmt_init(), out of memory");
res = EXIT_FAILURE;
goto exit;
}
ok(stmt != NULL , "mysql_stmt_init() succeeded");
if (mysql_stmt_prepare(stmt, query.c_str(), strlen(query.c_str()))) {
diag("mysql_stmt_prepare at line %d failed: %s", __LINE__ , mysql_error(proxysql_mysql));
mysql_close(proxysql_mysql);
res = EXIT_FAILURE;
goto exit;
} else {
ok(1,"mysql_stmt_prepare() succeeded");
}
if (param) {
MYSQL_BIND bind_params;
int64_t data_param = 1;
memset(&bind_params, 0, sizeof(MYSQL_BIND));
bind_params.buffer_type = MYSQL_TYPE_LONGLONG;
bind_params.buffer = (char *)&data_param;
bind_params.buffer_length = sizeof(int64_t);
if (mysql_stmt_bind_param(stmt, &bind_params)) {
diag(
"mysql_stmt_bind_result at line %d failed: %s", __LINE__ ,
mysql_stmt_error(stmt)
);
res = EXIT_FAILURE;
goto exit;
}
}
if (mysql_stmt_execute(stmt)) {
diag(
"mysql_stmt_execute at line %d failed: %s", __LINE__ ,
mysql_stmt_error(stmt)
);
res = EXIT_FAILURE;
goto exit;
} else {
ok(1,"mysql_stmt_execute() succeeded");
}
MYSQL_BIND bind[3];
int data_id;
int64_t data_c1;
char data_c2[STRING_SIZE];
char is_null[3];
long unsigned int length[3];
char error[3];
memset(bind, 0, sizeof(bind));
bind[0].buffer_type = MYSQL_TYPE_LONG;
bind[0].buffer = (char *)&data_id;
bind[0].buffer_length = sizeof(int);
bind[0].is_null = &is_null[0];
bind[0].length = &length[0];
bind[1].buffer_type = MYSQL_TYPE_LONGLONG;
bind[1].buffer = (char *)&data_c1;
bind[1].buffer_length = sizeof(int64_t);
bind[1].is_null = &is_null[1];
bind[1].length = &length[1];
bind[2].buffer_type = MYSQL_TYPE_STRING;
bind[2].buffer = (char *)&data_c2;
bind[2].buffer_length = STRING_SIZE;
bind[2].is_null = &is_null[2];
bind[2].length = &length[2];
bind[2].error = &error[2];
if (mysql_stmt_bind_result(stmt, bind)) {
diag(
"mysql_stmt_bind_result at line %d failed: %s", __LINE__,
mysql_stmt_error(stmt)
);
res = EXIT_FAILURE;
goto exit;
} else {
ok(1,"mysql_stmt_bind_result() succeeded");
}
if (mysql_stmt_fetch(stmt) == 1) {
diag(
"mysql_stmt_fetch at line %d failed: %s", __LINE__,
mysql_stmt_error(stmt)
);
res = EXIT_FAILURE;
goto exit;
} else {
ok(1,"mysql_stmt_fetch() succeeded");
}
bool data_match_expected =
(data_id == static_cast<int64_t>(1)) &&
(data_c1 == static_cast<int64_t>(100)) &&
(strcmp(data_c2, "abcde") == 0);
if (data_match_expected == false) {
diag(
"Prepared statement SELECT result didn't matched expected -"
" Exp=(id:1, c1:100, c2:'abcde'), Act=(id:%d, c1:%ld, c2:'%s')",
data_id,
data_c1,
data_c2
);
res = EXIT_FAILURE;
goto exit;
}
mysql_stmt_close(stmt);
}
}
exit:
mysql_close(proxysql_mysql);
mysql_close(proxysql_admin);
return exit_status();
}

@ -29,8 +29,8 @@
#include <string>
#include <stdio.h>
#include <mysql.h>
#include <mysql/mysqld_error.h>
#include "mysql.h"
#include "mysql/mysqld_error.h"
#include "proxysql_utils.h"
#include "tap.h"

@ -1 +0,0 @@
reg_test_3427-stmt_first_comment1-t.cpp

@ -0,0 +1,284 @@
/**
* @file reg_test_3427-stmt_first_comment-t.cpp
* @brief This test is a regression test for exercising all code related to
* 'first_comment' changes added in PR #3453.
* @details Testing revealed that the fix introduced for proper routing of
* prepared statements with query rules has invalid interaction with query
* annotation 'hostgroup' feature.
* For solving the issue, 'first_comment' was made part of 'MySQL_STMT_Global_info'.
* This test aims to exercise all the parts of ProxySQL affected by this change.
*
* Procedure:
* =========
*
* The test creates a number of prepared statements and execute them, until passing
* the limit of prepared statements allowed per connection. After the connection
* has been reset by ProxySQL because of the limit exceeding, it tries to execute
* the same prepared statements again. This way those prepared statements wont be
* available in the connection and will need to be fetched by ProxySQL for the
* reset connection.
*/
#include <iostream>
#include <chrono>
#include <ctime>
#include <cstring>
#include <unistd.h>
#include <time.h>
#include <vector>
#include <string>
#include <stdio.h>
#include "mysql.h"
#include "mysql/mysqld_error.h"
#include "proxysql_utils.h"
#include "tap.h"
#include "command_line.h"
#include "utils.h"
#include "errno.h"
/**
* @brief String size of the columns created for the testing table.
*/
const int STRING_SIZE=32;
/**
* @brief Number of max stmt per connection to be configured for
* ProxySQL.
*/
const uint32_t MAX_STMT_NUM_QUERIES = 20;
/**
* @brief Number of queries to RESET the connection being target,
* it's simply: MAX_STMT_NUM_QUERIES + 1
*/
const uint32_t RESET_CONNECTION_QUERIES = 2*MAX_STMT_NUM_QUERIES;
/**
* @brief Id for the current writer hostgroup.
*/
const uint32_t WRITER_HOSTGROUP_ID = 0;
int main(int argc, char** argv) {
int res = EXIT_SUCCESS;
CommandLine cl;
if (cl.getEnv()) {
diag("Failed to get the required environmental variables.");
return -1;
}
plan(5*RESET_CONNECTION_QUERIES);
bool param = false;
{
// we parse argv[0] to see if filename includes "param"
std::string str = std::string(argv[0]);
std::size_t found = str.find("param");
if (found!=std::string::npos) {
param = true;
}
}
MYSQL* proxysql_mysql = mysql_init(NULL);
MYSQL* proxysql_admin = mysql_init(NULL);
if (!mysql_real_connect(proxysql_mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) {
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_mysql));
return -1;
}
if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) {
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin));
return -1;
}
// Insert data in the table to be queried
// *************************************************************************
MYSQL_QUERY(proxysql_mysql, "CREATE DATABASE IF NOT EXISTS test");
MYSQL_QUERY(proxysql_mysql, "DROP TABLE IF EXISTS test.reg_test_3427");
MYSQL_QUERY(
proxysql_mysql,
"CREATE TABLE IF NOT EXISTS test.reg_test_3427"
" (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, `c1` BIGINT, `c2` varchar(32))"
);
MYSQL_QUERY(proxysql_mysql, "INSERT INTO test.reg_test_3427(c1, c2) VALUES (100, 'abcde')");
mysql_close(proxysql_mysql);
// Initialize the connection again
proxysql_mysql = mysql_init(NULL);
if (!mysql_real_connect(proxysql_mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) {
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_mysql));
return -1;
}
// *************************************************************************
{
// Set the number of maximum connections for servers in the writer hostgroup
std::string t_update_mysql_servers {
"UPDATE mysql_servers SET max_connections=1 WHERE hostgroup_id=%d"
};
std::string update_mysql_queries {};
string_format(t_update_mysql_servers, update_mysql_queries, WRITER_HOSTGROUP_ID);
MYSQL_QUERY(proxysql_admin, update_mysql_queries.c_str());
MYSQL_QUERY(proxysql_admin, "LOAD MYSQL SERVERS TO RUNTIME");
// Set the number of maximum prepared statements per connection
std::string t_max_stmt_query {
"SET mysql-max_stmts_per_connection=%d"
};
std::string max_stmt_query {};
string_format(t_max_stmt_query, max_stmt_query, MAX_STMT_NUM_QUERIES);
MYSQL_QUERY(proxysql_admin, max_stmt_query.c_str());
MYSQL_QUERY(proxysql_admin, "LOAD MYSQL VARIABLES TO RUNTIME");
uint32_t query_id = 0;
for (uint32_t i = 0; i < RESET_CONNECTION_QUERIES; i++) {
if (i <= MAX_STMT_NUM_QUERIES) {
query_id = i;
} else if (i == MAX_STMT_NUM_QUERIES + 1) {
query_id = 0;
} else {
query_id += 1;
}
// create unique stmt
std::string query_t {};
if (param) {
query_t = "SELECT /* ;hostgroup=0;%d */ * FROM test.reg_test_3427 WHERE id IN (?)";
} else {
query_t = "SELECT /* ;hostgroup=0;%d */ * FROM test.reg_test_3427";
}
std::string query {};
string_format(query_t, query, query_id);
MYSQL_STMT* stmt = mysql_stmt_init(proxysql_mysql);
if (!stmt) {
diag("mysql_stmt_init(), out of memory");
res = EXIT_FAILURE;
goto exit;
}
ok(stmt != NULL , "mysql_stmt_init() succeeded");
if (mysql_stmt_prepare(stmt, query.c_str(), strlen(query.c_str()))) {
diag("mysql_stmt_prepare at line %d failed: %s", __LINE__ , mysql_error(proxysql_mysql));
mysql_close(proxysql_mysql);
res = EXIT_FAILURE;
goto exit;
} else {
ok(1,"mysql_stmt_prepare() succeeded");
}
if (param) {
MYSQL_BIND bind_params;
int64_t data_param = 1;
memset(&bind_params, 0, sizeof(MYSQL_BIND));
bind_params.buffer_type = MYSQL_TYPE_LONGLONG;
bind_params.buffer = (char *)&data_param;
bind_params.buffer_length = sizeof(int64_t);
if (mysql_stmt_bind_param(stmt, &bind_params)) {
diag(
"mysql_stmt_bind_result at line %d failed: %s", __LINE__ ,
mysql_stmt_error(stmt)
);
res = EXIT_FAILURE;
goto exit;
}
}
if (mysql_stmt_execute(stmt)) {
diag(
"mysql_stmt_execute at line %d failed: %s", __LINE__ ,
mysql_stmt_error(stmt)
);
res = EXIT_FAILURE;
goto exit;
} else {
ok(1,"mysql_stmt_execute() succeeded");
}
MYSQL_BIND bind[3];
int data_id;
int64_t data_c1;
char data_c2[STRING_SIZE];
char is_null[3];
long unsigned int length[3];
char error[3];
memset(bind, 0, sizeof(bind));
bind[0].buffer_type = MYSQL_TYPE_LONG;
bind[0].buffer = (char *)&data_id;
bind[0].buffer_length = sizeof(int);
bind[0].is_null = &is_null[0];
bind[0].length = &length[0];
bind[1].buffer_type = MYSQL_TYPE_LONGLONG;
bind[1].buffer = (char *)&data_c1;
bind[1].buffer_length = sizeof(int64_t);
bind[1].is_null = &is_null[1];
bind[1].length = &length[1];
bind[2].buffer_type = MYSQL_TYPE_STRING;
bind[2].buffer = (char *)&data_c2;
bind[2].buffer_length = STRING_SIZE;
bind[2].is_null = &is_null[2];
bind[2].length = &length[2];
bind[2].error = &error[2];
if (mysql_stmt_bind_result(stmt, bind)) {
diag(
"mysql_stmt_bind_result at line %d failed: %s", __LINE__,
mysql_stmt_error(stmt)
);
res = EXIT_FAILURE;
goto exit;
} else {
ok(1,"mysql_stmt_bind_result() succeeded");
}
if (mysql_stmt_fetch(stmt) == 1) {
diag(
"mysql_stmt_fetch at line %d failed: %s", __LINE__,
mysql_stmt_error(stmt)
);
res = EXIT_FAILURE;
goto exit;
} else {
ok(1,"mysql_stmt_fetch() succeeded");
}
bool data_match_expected =
(data_id == static_cast<int64_t>(1)) &&
(data_c1 == static_cast<int64_t>(100)) &&
(strcmp(data_c2, "abcde") == 0);
if (data_match_expected == false) {
diag(
"Prepared statement SELECT result didn't matched expected -"
" Exp=(id:1, c1:100, c2:'abcde'), Act=(id:%d, c1:%ld, c2:'%s')",
data_id,
data_c1,
data_c2
);
res = EXIT_FAILURE;
goto exit;
}
mysql_stmt_close(stmt);
}
}
exit:
mysql_close(proxysql_mysql);
mysql_close(proxysql_admin);
return exit_status();
}

@ -1 +0,0 @@
reg_test_3427-stmt_first_comment1-t.cpp

@ -0,0 +1,284 @@
/**
* @file reg_test_3427-stmt_first_comment-t.cpp
* @brief This test is a regression test for exercising all code related to
* 'first_comment' changes added in PR #3453.
* @details Testing revealed that the fix introduced for proper routing of
* prepared statements with query rules has invalid interaction with query
* annotation 'hostgroup' feature.
* For solving the issue, 'first_comment' was made part of 'MySQL_STMT_Global_info'.
* This test aims to exercise all the parts of ProxySQL affected by this change.
*
* Procedure:
* =========
*
* The test creates a number of prepared statements and execute them, until passing
* the limit of prepared statements allowed per connection. After the connection
* has been reset by ProxySQL because of the limit exceeding, it tries to execute
* the same prepared statements again. This way those prepared statements wont be
* available in the connection and will need to be fetched by ProxySQL for the
* reset connection.
*/
#include <iostream>
#include <chrono>
#include <ctime>
#include <cstring>
#include <unistd.h>
#include <time.h>
#include <vector>
#include <string>
#include <stdio.h>
#include "mysql.h"
#include "mysql/mysqld_error.h"
#include "proxysql_utils.h"
#include "tap.h"
#include "command_line.h"
#include "utils.h"
#include "errno.h"
/**
* @brief String size of the columns created for the testing table.
*/
const int STRING_SIZE=32;
/**
* @brief Number of max stmt per connection to be configured for
* ProxySQL.
*/
const uint32_t MAX_STMT_NUM_QUERIES = 20;
/**
* @brief Number of queries to RESET the connection being target,
* it's simply: MAX_STMT_NUM_QUERIES + 1
*/
const uint32_t RESET_CONNECTION_QUERIES = 2*MAX_STMT_NUM_QUERIES;
/**
* @brief Id for the current writer hostgroup.
*/
const uint32_t WRITER_HOSTGROUP_ID = 0;
int main(int argc, char** argv) {
int res = EXIT_SUCCESS;
CommandLine cl;
if (cl.getEnv()) {
diag("Failed to get the required environmental variables.");
return -1;
}
plan(5*RESET_CONNECTION_QUERIES);
bool param = false;
{
// we parse argv[0] to see if filename includes "param"
std::string str = std::string(argv[0]);
std::size_t found = str.find("param");
if (found!=std::string::npos) {
param = true;
}
}
MYSQL* proxysql_mysql = mysql_init(NULL);
MYSQL* proxysql_admin = mysql_init(NULL);
if (!mysql_real_connect(proxysql_mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) {
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_mysql));
return -1;
}
if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) {
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin));
return -1;
}
// Insert data in the table to be queried
// *************************************************************************
MYSQL_QUERY(proxysql_mysql, "CREATE DATABASE IF NOT EXISTS test");
MYSQL_QUERY(proxysql_mysql, "DROP TABLE IF EXISTS test.reg_test_3427");
MYSQL_QUERY(
proxysql_mysql,
"CREATE TABLE IF NOT EXISTS test.reg_test_3427"
" (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, `c1` BIGINT, `c2` varchar(32))"
);
MYSQL_QUERY(proxysql_mysql, "INSERT INTO test.reg_test_3427(c1, c2) VALUES (100, 'abcde')");
mysql_close(proxysql_mysql);
// Initialize the connection again
proxysql_mysql = mysql_init(NULL);
if (!mysql_real_connect(proxysql_mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) {
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_mysql));
return -1;
}
// *************************************************************************
{
// Set the number of maximum connections for servers in the writer hostgroup
std::string t_update_mysql_servers {
"UPDATE mysql_servers SET max_connections=1 WHERE hostgroup_id=%d"
};
std::string update_mysql_queries {};
string_format(t_update_mysql_servers, update_mysql_queries, WRITER_HOSTGROUP_ID);
MYSQL_QUERY(proxysql_admin, update_mysql_queries.c_str());
MYSQL_QUERY(proxysql_admin, "LOAD MYSQL SERVERS TO RUNTIME");
// Set the number of maximum prepared statements per connection
std::string t_max_stmt_query {
"SET mysql-max_stmts_per_connection=%d"
};
std::string max_stmt_query {};
string_format(t_max_stmt_query, max_stmt_query, MAX_STMT_NUM_QUERIES);
MYSQL_QUERY(proxysql_admin, max_stmt_query.c_str());
MYSQL_QUERY(proxysql_admin, "LOAD MYSQL VARIABLES TO RUNTIME");
uint32_t query_id = 0;
for (uint32_t i = 0; i < RESET_CONNECTION_QUERIES; i++) {
if (i <= MAX_STMT_NUM_QUERIES) {
query_id = i;
} else if (i == MAX_STMT_NUM_QUERIES + 1) {
query_id = 0;
} else {
query_id += 1;
}
// create unique stmt
std::string query_t {};
if (param) {
query_t = "SELECT /* ;hostgroup=0;%d */ * FROM test.reg_test_3427 WHERE id IN (?)";
} else {
query_t = "SELECT /* ;hostgroup=0;%d */ * FROM test.reg_test_3427";
}
std::string query {};
string_format(query_t, query, query_id);
MYSQL_STMT* stmt = mysql_stmt_init(proxysql_mysql);
if (!stmt) {
diag("mysql_stmt_init(), out of memory");
res = EXIT_FAILURE;
goto exit;
}
ok(stmt != NULL , "mysql_stmt_init() succeeded");
if (mysql_stmt_prepare(stmt, query.c_str(), strlen(query.c_str()))) {
diag("mysql_stmt_prepare at line %d failed: %s", __LINE__ , mysql_error(proxysql_mysql));
mysql_close(proxysql_mysql);
res = EXIT_FAILURE;
goto exit;
} else {
ok(1,"mysql_stmt_prepare() succeeded");
}
if (param) {
MYSQL_BIND bind_params;
int64_t data_param = 1;
memset(&bind_params, 0, sizeof(MYSQL_BIND));
bind_params.buffer_type = MYSQL_TYPE_LONGLONG;
bind_params.buffer = (char *)&data_param;
bind_params.buffer_length = sizeof(int64_t);
if (mysql_stmt_bind_param(stmt, &bind_params)) {
diag(
"mysql_stmt_bind_result at line %d failed: %s", __LINE__ ,
mysql_stmt_error(stmt)
);
res = EXIT_FAILURE;
goto exit;
}
}
if (mysql_stmt_execute(stmt)) {
diag(
"mysql_stmt_execute at line %d failed: %s", __LINE__ ,
mysql_stmt_error(stmt)
);
res = EXIT_FAILURE;
goto exit;
} else {
ok(1,"mysql_stmt_execute() succeeded");
}
MYSQL_BIND bind[3];
int data_id;
int64_t data_c1;
char data_c2[STRING_SIZE];
char is_null[3];
long unsigned int length[3];
char error[3];
memset(bind, 0, sizeof(bind));
bind[0].buffer_type = MYSQL_TYPE_LONG;
bind[0].buffer = (char *)&data_id;
bind[0].buffer_length = sizeof(int);
bind[0].is_null = &is_null[0];
bind[0].length = &length[0];
bind[1].buffer_type = MYSQL_TYPE_LONGLONG;
bind[1].buffer = (char *)&data_c1;
bind[1].buffer_length = sizeof(int64_t);
bind[1].is_null = &is_null[1];
bind[1].length = &length[1];
bind[2].buffer_type = MYSQL_TYPE_STRING;
bind[2].buffer = (char *)&data_c2;
bind[2].buffer_length = STRING_SIZE;
bind[2].is_null = &is_null[2];
bind[2].length = &length[2];
bind[2].error = &error[2];
if (mysql_stmt_bind_result(stmt, bind)) {
diag(
"mysql_stmt_bind_result at line %d failed: %s", __LINE__,
mysql_stmt_error(stmt)
);
res = EXIT_FAILURE;
goto exit;
} else {
ok(1,"mysql_stmt_bind_result() succeeded");
}
if (mysql_stmt_fetch(stmt) == 1) {
diag(
"mysql_stmt_fetch at line %d failed: %s", __LINE__,
mysql_stmt_error(stmt)
);
res = EXIT_FAILURE;
goto exit;
} else {
ok(1,"mysql_stmt_fetch() succeeded");
}
bool data_match_expected =
(data_id == static_cast<int64_t>(1)) &&
(data_c1 == static_cast<int64_t>(100)) &&
(strcmp(data_c2, "abcde") == 0);
if (data_match_expected == false) {
diag(
"Prepared statement SELECT result didn't matched expected -"
" Exp=(id:1, c1:100, c2:'abcde'), Act=(id:%d, c1:%ld, c2:'%s')",
data_id,
data_c1,
data_c2
);
res = EXIT_FAILURE;
goto exit;
}
mysql_stmt_close(stmt);
}
}
exit:
mysql_close(proxysql_mysql);
mysql_close(proxysql_admin);
return exit_status();
}

@ -17,7 +17,7 @@
#include <iostream>
#include <thread>
#include <mysql.h>
#include "mysql.h"
#include "proxysql_utils.h"
#include "tap.h"

@ -24,7 +24,7 @@
#include <string>
#include <stdio.h>
#include <mysql.h>
#include "mysql.h"
#include "tap.h"
#include "command_line.h"

@ -21,8 +21,8 @@
#include <iostream>
#include <unistd.h>
#include <mysql.h>
#include <mysql/mysqld_error.h>
#include "mysql.h"
#include "mysql/mysqld_error.h"
#include "command_line.h"
#include "proxysql_utils.h"

@ -31,8 +31,8 @@
#include <tuple>
#include <iostream>
#include <mysql.h>
#include <mysql/mysqld_error.h>
#include "mysql.h"
#include "mysql/mysqld_error.h"
#include "proxysql_utils.h"
#include "json.hpp"

@ -20,8 +20,8 @@
#include <string>
#include <stdio.h>
#include <mysql.h>
#include <mysql/mysqld_error.h>
#include "mysql.h"
#include "mysql/mysqld_error.h"
#include "proxysql_utils.h"
#include "tap.h"

@ -12,7 +12,7 @@
#include <string>
#include <stdio.h>
#include <mysql.h>
#include "mysql.h"
#include "proxysql_utils.h"
#include "tap.h"

@ -6,7 +6,7 @@
#include <time.h>
#include <iostream>
#include <mysql.h>
#include "mysql.h"
#include "tap.h"
#include "command_line.h"

@ -16,7 +16,7 @@
#include <stdio.h>
#include <unistd.h>
#include <mysql.h>
#include "mysql.h"
#include "tap.h"
#include "command_line.h"

@ -29,7 +29,7 @@
#include <time.h>
#include <iostream>
#include <mysql.h>
#include "mysql.h"
#include "tap.h"
#include "command_line.h"

@ -18,10 +18,10 @@
#include <string>
#include <stdio.h>
#include <mysql.h>
#include <mysql/mysqld_error.h>
#include "mysql.h"
#include "mysql/mysqld_error.h"
#include <proxysql_utils.h>
#include "proxysql_utils.h"
#include "tap.h"
#include "command_line.h"

@ -15,8 +15,8 @@
#include <stdlib.h>
#include <unistd.h>
#include <mysql.h>
#include <mysql/mysqld_error.h>
#include "mysql.h"
#include "mysql/mysqld_error.h"
#include "tap.h"
#include "command_line.h"

@ -16,7 +16,7 @@
#include <iostream>
#include <random>
#include <mysql.h>
#include "mysql.h"
#include "json.hpp"
#include "tap.h"

@ -16,7 +16,7 @@
#include <poll.h>
#include <sys/epoll.h>
#include <mysql.h>
#include "mysql.h"
#include <thread>
#include "tap.h"

@ -22,8 +22,8 @@
#include "curl/curl.h"
#include <mysql.h>
#include <mysql/mysqld_error.h>
#include "mysql.h"
#include "mysql/mysqld_error.h"
#include "json.hpp"
#include "tap.h"

@ -10,8 +10,8 @@
#include <stdio.h>
#include <unistd.h>
#include <mysql.h>
#include <mysql/mysqld_error.h>
#include "mysql.h"
#include "mysql/mysqld_error.h"
#include "proxysql_utils.h"
#include "tap.h"

@ -11,7 +11,7 @@
#include <stdio.h>
#include <cstring>
#include <unistd.h>
#include <mysql.h>
#include "mysql.h"
#include "tap.h"
#include "command_line.h"

@ -11,7 +11,7 @@
#include <stdio.h>
#include <cstring>
#include <unistd.h>
#include <mysql.h>
#include "mysql.h"
#include "tap.h"
#include "command_line.h"

@ -22,7 +22,7 @@
#include <sys/time.h>
#include <sys/resource.h>
#include <mysql.h>
#include "mysql.h"
#include "command_line.h"
#include "proxysql_utils.h"

@ -7,8 +7,8 @@
#include <unistd.h>
#include <string>
#include <thread>
#include <mysql.h>
#include <mysql/mysqld_error.h>
#include "mysql.h"
#include "mysql/mysqld_error.h"
#include "tap.h"
#include "command_line.h"
#include "utils.h"

@ -41,8 +41,8 @@
#include <stdio.h>
#include <unistd.h>
#include <mysql.h>
#include <mysql/mysqld_error.h>
#include "mysql.h"
#include "mysql/mysqld_error.h"
#include "tap.h"
#include "utils.h"

@ -15,8 +15,8 @@
#include <time.h>
#include <unistd.h>
#include <mysql.h>
#include <mysql/mysqld_error.h>
#include "mysql.h"
#include "mysql/mysqld_error.h"
#include "tap.h"
#include "utils.h"

@ -18,7 +18,7 @@
#include <stdio.h>
#include <cstring>
#include <unistd.h>
#include <mysql.h>
#include "mysql.h"
#include "tap.h"
#include "command_line.h"

@ -13,7 +13,7 @@
#include <stdio.h>
#include <unistd.h>
#include <vector>
#include <mysql.h>
#include "mysql.h"
#include "tap.h"
#include "command_line.h"

@ -12,8 +12,8 @@
#include <utility>
#include <unistd.h>
#include <mysql.h>
#include <mysql/mysqld_error.h>
#include "mysql.h"
#include "mysql/mysqld_error.h"
#include "json.hpp"

@ -16,8 +16,8 @@
#include <utility>
#include <vector>
#include <mysql.h>
#include <mysql/mysqld_error.h>
#include "mysql.h"
#include "mysql/mysqld_error.h"
#include "proxysql_utils.h"
#include "tap.h"

@ -8,8 +8,8 @@
#include <utility>
#include <vector>
#include <mysql.h>
#include <mysql/mysqld_error.h>
#include "mysql.h"
#include "mysql/mysqld_error.h"
#include "proxysql_utils.h"
#include "tap.h"

@ -56,7 +56,7 @@
#include <poll.h>
#include <sys/epoll.h>
#include <mysql.h>
#include "mysql.h"
#include <thread>
#include "tap.h"

@ -12,7 +12,7 @@
#include <cstring>
#include <unistd.h>
#include <mysql.h>
#include "mysql.h"
#include "tap.h"
#include "command_line.h"

@ -7,7 +7,7 @@
*/
#include <string>
#include <mysql.h>
#include "mysql.h"
#include "tap.h"
#include "command_line.h"

@ -1,7 +1,7 @@
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <mysql.h>
#include "mysql.h"
#include <string.h>
#include <string>
#include <time.h>

@ -1,7 +1,7 @@
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <mysql.h>
#include "mysql.h"
#include <string.h>
#include <string>
#include <time.h>

@ -36,7 +36,7 @@
#include <unistd.h>
#include <string>
#include <mysql.h>
#include "mysql.h"
#include "tap.h"
#include "command_line.h"

@ -11,7 +11,7 @@
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <mysql.h>
#include "mysql.h"
#include <string.h>
#include <string>
#include <time.h>

@ -1,7 +1,7 @@
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <mysql.h>
#include "mysql.h"
#include <string.h>
#include <string>
#include <time.h>

@ -11,7 +11,7 @@
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <mysql.h>
#include "mysql.h"
#include <string.h>
#include <string>
#include <time.h>

@ -5,7 +5,8 @@
#include <cstdint>
#include <cstring>
#include <memory>
#include <openssl/ssl.h>
#include "openssl/ssl.h"
#include "mysql.h"
#include "proxysql_structs.h"

@ -5,7 +5,7 @@
#include <string>
#include <sstream>
#include <mysql.h>
#include "mysql.h"
#include "tap.h"
#include "command_line.h"

@ -10,8 +10,8 @@
#include <unistd.h>
#include <vector>
#include <mysql.h>
#include <mysql/mysqld_error.h>
#include "mysql.h"
#include "mysql/mysqld_error.h"
#include "tap.h"
#include "command_line.h"

@ -27,8 +27,8 @@ DELETE FROM history_mysql_status_variables;
#include <unistd.h>
#include <vector>
#include <mysql.h>
#include <mysql/mysqld_error.h>
#include "mysql.h"
#include "mysql/mysqld_error.h"
#include "tap.h"
#include "command_line.h"

@ -28,8 +28,8 @@
#include <iostream>
#include <unistd.h>
#include <mysql.h>
#include <mysql/mysqld_error.h>
#include "mysql.h"
#include "mysql/mysqld_error.h"
#include "json.hpp"

@ -6,7 +6,7 @@
#include <vector>
#include <string>
#include <sstream>
#include <mysql.h>
#include "mysql.h"
#include "tap.h"
#include "command_line.h"

@ -28,8 +28,8 @@
#include <utility>
#include <vector>
#include <mysql.h>
#include <mysql/mysqld_error.h>
#include "mysql.h"
#include "mysql/mysqld_error.h"
#include <json.hpp>
#include "tap.h"

@ -10,7 +10,7 @@
*/
#include <unistd.h>
#include <mysql.h>
#include "mysql.h"
#include <vector>
#include <string>

@ -28,8 +28,8 @@
#include <stdlib.h>
#include <unistd.h>
#include <mysql.h>
#include <mysql/mysqld_error.h>
#include "mysql.h"
#include "mysql/mysqld_error.h"
#include "tap.h"
#include "command_line.h"

@ -48,8 +48,8 @@
#include <fstream>
#include <libconfig.h>
#include <proxysql_utils.h>
#include <mysql.h>
#include "proxysql_utils.h"
#include "mysql.h"
#include "json.hpp"
#include "tap.h"

@ -4,7 +4,7 @@
#include <cstring>
#include <set>
#include <unistd.h>
#include <mysql.h>
#include "mysql.h"
#include "tap.h"
#include "command_line.h"

@ -77,9 +77,9 @@
#include <libconfig.h>
#include <proxysql_utils.h>
#include "proxysql_utils.h"
#include <mysql.h>
#include "mysql.h"
#include "tap.h"
#include "command_line.h"

@ -19,8 +19,8 @@
#include <iostream>
#include <unistd.h>
#include <mysql.h>
#include <mysql/mysqld_error.h>
#include "mysql.h"
#include "mysql/mysqld_error.h"
#include "command_line.h"
#include "proxysql_utils.h"

@ -10,8 +10,8 @@
#include <string>
#include <stdio.h>
#include <mysql.h>
#include <mysql/mysqld_error.h>
#include "mysql.h"
#include "mysql/mysqld_error.h"
#include "tap.h"
#include "command_line.h"

@ -6,7 +6,7 @@
#include <vector>
#include <string>
#include <stdio.h>
#include <mysql.h>
#include "mysql.h"
#include "tap.h"
#include "command_line.h"

@ -17,7 +17,7 @@
#include <unistd.h>
#include <vector>
#include <mysql.h>
#include "mysql.h"
#include "tap.h"
#include "command_line.h"

@ -5,7 +5,7 @@
#include <string>
#include <sstream>
#include <mysql.h>
#include "mysql.h"
#include "tap.h"
#include "command_line.h"

@ -22,7 +22,7 @@
#include <tuple>
#include <vector>
#include <mysql.h>
#include "mysql.h"
#include "tap.h"
#include "command_line.h"

@ -13,7 +13,7 @@
#include <unistd.h>
#include <iostream>
#include <mysql.h>
#include "mysql.h"
#include <vector>
#include <string>
#include <chrono>

@ -14,8 +14,8 @@
#include <chrono>
#include <thread>
#include <mysql.h>
#include <mysql/mysqld_error.h>
#include "mysql.h"
#include "mysql/mysqld_error.h"
#include "tap.h"
#include "command_line.h"

@ -5,7 +5,7 @@
#include <string>
#include <sstream>
#include <mysql.h>
#include "mysql.h"
#include "tap.h"
#include "command_line.h"

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save