fix database names

pull/4304/head
Miro Stauder 3 years ago
parent b4438f7315
commit ba87de8037

@ -56,8 +56,8 @@ echo ":: ProxySQL connection completed".PHP_EOL;
echo ":: Starting schema and table creation...".PHP_EOL;
if ($port !== 6090) {
$proxy->query("CREATE DATABASE IF NOT EXISTS test_clickhouse_types_php");
$proxy->query("USE test_clickhouse_types_php");
$proxy->query("CREATE DATABASE IF NOT EXISTS test");
$proxy->query("USE test");
$proxy->query("DROP TABLE IF EXISTS types_table");
$proxy->query("CREATE TABLE IF NOT EXISTS types_table (EventDate DATE, DateTime DATETIME, col1 TINYINT, col2 SMALLINT, col3 INT, col4 BIGINT, col5 FLOAT, col6 DOUBLE)");
@ -80,8 +80,8 @@ if ($port !== 6090) {
echo ":: Finished operations on MySQL conn".PHP_EOL;
exit(0);
} else {
$proxy->query("CREATE DATABASE IF NOT EXISTS test_clickhouse_types_php");
$proxy->query("USE test_clickhouse_types_php");
$proxy->query("CREATE DATABASE IF NOT EXISTS test");
$proxy->query("USE test");
$proxy->query("DROP TABLE IF EXISTS types_table");
$proxy->query("CREATE TABLE IF NOT EXISTS types_table (EventDate DATE, DateTime DATETIME, col1 UInt8, col2 Int16, col3 Int32, col4 Int64, col5 Nullable(Float32), col6 Float64) ENGINE=MergeTree(EventDate, (EventDate), 8192)");
}
@ -266,7 +266,7 @@ foreach ($exp_rows as $exp_row) {
$exit_code |= !($types_match & $vals_match);
}
$proxy->query("DROP DATABASE IF EXISTS test_clickhouse_types_php");
$proxy->query("DROP DATABASE IF EXISTS test");
$result->free();
exit($exit_code);

@ -6,7 +6,7 @@
* test performs the following actions:
*
* 1. Open a MYSQL connection to ProxySQL.
* 2. Drops and creates multiple databases called 'reg_test_3493_use_comment-N'.
* 2. Drops and creates multiple databases called 'test_use_comment-N'.
* 3. Performs a 'USE' statement in the connection.
* 3. Checks the currently selected database in **a new backend database connection** by means of the
* connection annotation "create_new_connection=1". This way it's ensured that ProxySQL is properly keeping
@ -176,21 +176,21 @@ int main(int argc, char** argv) {
MYSQL* proxysql_mysql = mysql_init(NULL);
db_query.push_back(std::make_tuple("reg_test_3493_use_comment", "/*+ placeholder_comment */ USE reg_test_3493_use_comment", false));
db_query.push_back(std::make_tuple("`reg_test_3493_use_comment-a1`", "USE /*+ placeholder_comment */ `reg_test_3493_use_comment-a1`", true));
db_query.push_back(std::make_tuple("reg_test_3493_use_comment_1", " USE /*+ placeholder_comment */ `reg_test_3493_use_comment_1`", false));
db_query.push_back(std::make_tuple("reg_test_3493_use_comment_2", "USE/*+ placeholder_comment */ `reg_test_3493_use_comment_2`", false));
db_query.push_back(std::make_tuple("reg_test_3493_use_comment_3", "USE /*+ placeholder_comment */`reg_test_3493_use_comment_3`", true));
db_query.push_back(std::make_tuple("reg_test_3493_use_comment_4", " USE /*+ placeholder_comment */ reg_test_3493_use_comment_4", false));
db_query.push_back(std::make_tuple("reg_test_3493_use_comment_5", "USE/*+ placeholder_comment */ reg_test_3493_use_comment_5", false));
db_query.push_back(std::make_tuple("reg_test_3493_use_comment_6", "USE /*+ placeholder_comment */reg_test_3493_use_comment_6", true));
db_query.push_back(std::make_tuple("`reg_test_3493_use_comment-1`", " USE /*+ placeholder_comment */ `reg_test_3493_use_comment-1`", false));
db_query.push_back(std::make_tuple("`reg_test_3493_use_comment-2`", "USE/*+ placeholder_comment */ `reg_test_3493_use_comment-2`", false));
db_query.push_back(std::make_tuple("`reg_test_3493_use_comment-3`", "USE /*+ placeholder_comment */`reg_test_3493_use_comment-3`", true));
db_query.push_back(std::make_tuple("`reg_test_3493_use_comment-4`", "/*+ placeholder_comment */USE `reg_test_3493_use_comment-4`", false));
db_query.push_back(std::make_tuple("`reg_test_3493_use_comment-5`", "USE/*+ placeholder_comment */`reg_test_3493_use_comment-5`", false));
db_query.push_back(std::make_tuple("`reg_test_3493_use_comment-6`", "/* comment */USE`reg_test_3493_use_comment-6`", false));
db_query.push_back(std::make_tuple("`reg_test_3493_use_comment-7`", "USE`reg_test_3493_use_comment-7`", false));
db_query.push_back(std::make_tuple("test_use_comment", "/*+ placeholder_comment */ USE test_use_comment", false));
db_query.push_back(std::make_tuple("`test_use_comment-a1`", "USE /*+ placeholder_comment */ `test_use_comment-a1`", true));
db_query.push_back(std::make_tuple("test_use_comment_1", " USE /*+ placeholder_comment */ `test_use_comment_1`", false));
db_query.push_back(std::make_tuple("test_use_comment_2", "USE/*+ placeholder_comment */ `test_use_comment_2`", false));
db_query.push_back(std::make_tuple("test_use_comment_3", "USE /*+ placeholder_comment */`test_use_comment_3`", true));
db_query.push_back(std::make_tuple("test_use_comment_4", " USE /*+ placeholder_comment */ test_use_comment_4", false));
db_query.push_back(std::make_tuple("test_use_comment_5", "USE/*+ placeholder_comment */ test_use_comment_5", false));
db_query.push_back(std::make_tuple("test_use_comment_6", "USE /*+ placeholder_comment */test_use_comment_6", true));
db_query.push_back(std::make_tuple("`test_use_comment-1`", " USE /*+ placeholder_comment */ `test_use_comment-1`", false));
db_query.push_back(std::make_tuple("`test_use_comment-2`", "USE/*+ placeholder_comment */ `test_use_comment-2`", false));
db_query.push_back(std::make_tuple("`test_use_comment-3`", "USE /*+ placeholder_comment */`test_use_comment-3`", true));
db_query.push_back(std::make_tuple("`test_use_comment-4`", "/*+ placeholder_comment */USE `test_use_comment-4`", false));
db_query.push_back(std::make_tuple("`test_use_comment-5`", "USE/*+ placeholder_comment */`test_use_comment-5`", false));
db_query.push_back(std::make_tuple("`test_use_comment-6`", "/* comment */USE`test_use_comment-6`", false));
db_query.push_back(std::make_tuple("`test_use_comment-7`", "USE`test_use_comment-7`", false));
plan(db_query.size() * 2);

@ -50,9 +50,9 @@ int main(int argc, char** argv) {
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql));
return exit_status();
}
MYSQL_QUERY(proxysql, "DROP DATABASE IF EXISTS testdb");
MYSQL_QUERY(proxysql, "CREATE DATABASE testdb");
MYSQL_QUERY(proxysql, "CREATE TABLE testdb.`tmp` ( " \
MYSQL_QUERY(proxysql, "DROP DATABASE IF EXISTS test");
MYSQL_QUERY(proxysql, "CREATE DATABASE test");
MYSQL_QUERY(proxysql, "CREATE TABLE test.`tmp` ( " \
"`id` bigint(20) NOT NULL AUTO_INCREMENT, " \
"`text1` varchar(200) COLLATE utf8_bin NOT NULL, " \
"`text2` varchar(200) COLLATE utf8_bin NOT NULL, " \
@ -61,15 +61,15 @@ int main(int argc, char** argv) {
") ENGINE = InnoDB");
diag("Inserting rows...");
MYSQL_QUERY(proxysql, "INSERT INTO testdb.tmp(text1, text2, time) values('dummy text1', 'dummy text2', now())");
MYSQL_QUERY(proxysql, "INSERT INTO test.tmp(text1, text2, time) values('dummy text1', 'dummy text2', now())");
for (int i = 0; i < 7; i++) {
MYSQL_QUERY(proxysql, "INSERT INTO testdb.tmp(text1, text2, time) SELECT text1, text2, time FROM testdb.tmp");
MYSQL_QUERY(proxysql, "INSERT INTO test.tmp(text1, text2, time) SELECT text1, text2, time FROM test.tmp");
}
std::this_thread::sleep_for(std::chrono::seconds(2));
MYSQL_QUERY(proxysql, "SELECT COUNT(*) FROM testdb.tmp a JOIN testdb.tmp b JOIN testdb.tmp c");
MYSQL_QUERY(proxysql, "SELECT COUNT(*) FROM test.tmp a JOIN test.tmp b JOIN test.tmp c");
auto mysql_result = mysql_use_result(proxysql);
@ -88,7 +88,7 @@ int main(int argc, char** argv) {
diag("Done... Total rows to fetch:'%lu'", add_row_count);
diag("Fetching all rows...");
MYSQL_QUERY(proxysql, "SELECT a.* FROM testdb.tmp a JOIN testdb.tmp b JOIN testdb.tmp c WHERE 1/0 OR 1=1");
MYSQL_QUERY(proxysql, "SELECT a.* FROM test.tmp a JOIN test.tmp b JOIN test.tmp c WHERE 1/0 OR 1=1");
mysql_result = mysql_use_result(proxysql);

@ -67,19 +67,19 @@ int main(int argc, char** argv) {
return exit_status();
}
if (mysql_query(mysql, "drop database if exists t1")) {
if (mysql_query(mysql, "drop database if exists test")) {
fprintf(stderr, "File %s, line %d, Error: %s\n",
__FILE__, __LINE__, mysql_error(mysql));
return exit_status();
}
if (mysql_query(mysql, "create database t1 charset utf8")) {
if (mysql_query(mysql, "create database test charset utf8")) {
fprintf(stderr, "File %s, line %d, Error: %s\n",
__FILE__, __LINE__, mysql_error(mysql));
return exit_status();
}
if (mysql_query(mysql, "use t1")) {
if (mysql_query(mysql, "use test")) {
fprintf(stderr, "File %s, line %d, Error: %s\n",
__FILE__, __LINE__, mysql_error(mysql));
return exit_status();

@ -46,12 +46,12 @@ using nlohmann::json;
int create_testing_tables(MYSQL* mysql_server) {
// Create the testing database
MYSQL_QUERY(mysql_server, "CREATE DATABASE IF NOT EXISTS binlog_db");
MYSQL_QUERY(mysql_server, "DROP TABLE IF EXISTS binlog_db.gtid_test");
MYSQL_QUERY(mysql_server, "CREATE DATABASE IF NOT EXISTS test");
MYSQL_QUERY(mysql_server, "DROP TABLE IF EXISTS test.gtid_test");
MYSQL_QUERY(
mysql_server,
"CREATE TABLE IF NOT EXISTS binlog_db.gtid_test ("
"CREATE TABLE IF NOT EXISTS test.gtid_test ("
" id INTEGER NOT NULL AUTO_INCREMENT,"
" a INT NOT NULL,"
" c varchar(255),"
@ -71,7 +71,7 @@ int insert_random_data(MYSQL* proxysql_mysql, uint32_t rows) {
for (uint32_t i = 0; i < rows; i++) {
string update_query {};
string_format(
"INSERT INTO binlog_db.gtid_test (a, c, pad) VALUES ('%d', '%s', '%s')", update_query,
"INSERT INTO test.gtid_test (a, c, pad) VALUES ('%d', '%s', '%s')", update_query,
i, rnd_c.c_str(), rnd_pad.c_str()
);
MYSQL_QUERY(proxysql_mysql, update_query.c_str());
@ -85,7 +85,7 @@ int perform_update(MYSQL* proxysql_mysql, uint32_t rows) {
string rnd_c = random_string(rand() % 100 + 5);
string rnd_pad = random_string(rand() % 60 + 5);
string query { "UPDATE binlog_db.gtid_test SET a=a+1, c=REVERSE(c)" };
string query { "UPDATE test.gtid_test SET a=a+1, c=REVERSE(c)" };
MYSQL_QUERY(proxysql_mysql, query.c_str());
return EXIT_SUCCESS;
@ -96,10 +96,10 @@ const uint32_t NUM_ROWS = 3000;
const uint32_t NUM_CHECKS = 500;
map<uint32_t, pair<uint32_t,uint32_t>> extract_hosgtroups_stats(const vector<mysql_res_row>& conn_pool_stats) {
uint32_t hg_50_queries = 0;
uint32_t hg_50_sync_queries = 0;
uint32_t hg_60_queries = 0;
uint32_t hg_60_sync_queries = 0;
uint32_t hg_1900_queries = 0;
uint32_t hg_1900_sync_queries = 0;
uint32_t hg_1901_queries = 0;
uint32_t hg_1901_sync_queries = 0;
for (const auto& conn_pool_stats_row : conn_pool_stats) {
if (conn_pool_stats_row.size() < 3) {
@ -112,16 +112,16 @@ map<uint32_t, pair<uint32_t,uint32_t>> extract_hosgtroups_stats(const vector<mys
const uint32_t queries = std::stol(conn_pool_stats_row[1]);
const uint32_t queries_gtid_sync = std::stol(conn_pool_stats_row[2]);
if (hg == 50) {
hg_50_queries += queries;
hg_50_sync_queries += queries_gtid_sync;
} else if (hg == 60) {
hg_60_queries += queries;
hg_60_sync_queries += queries_gtid_sync;
if (hg == 1900) {
hg_1900_queries += queries;
hg_1900_sync_queries += queries_gtid_sync;
} else if (hg == 1901) {
hg_1901_queries += queries;
hg_1901_sync_queries += queries_gtid_sync;
}
}
return { { 50, { hg_50_queries, hg_50_sync_queries } }, { 60, { hg_60_queries, hg_60_sync_queries } } };
return { { 1900, { hg_1900_queries, hg_1900_sync_queries } }, { 1901, { hg_1901_queries, hg_1901_sync_queries } } };
}
int perform_rnd_selects(const CommandLine& cl, uint32_t NUM) {
@ -138,7 +138,7 @@ int perform_rnd_selects(const CommandLine& cl, uint32_t NUM) {
if (r_row == 0) { r_row = 1; }
string s_query {};
string_format("SELECT * FROM binlog_db.gtid_test WHERE id=%d", s_query, r_row);
string_format("SELECT * FROM test.gtid_test WHERE id=%d", s_query, r_row);
// Perform the select and ignore the result
int rc = mysql_query(select_conn, s_query.c_str());
@ -168,28 +168,28 @@ int check_gitd_tracking(const CommandLine& cl, MYSQL* proxysql_mysql, MYSQL* pro
}
auto hg_stats { extract_hosgtroups_stats(conn_pool_stats) };
uint32_t hg_50_queries = hg_stats.at(50).first;
uint32_t hg_50_sync_queries = hg_stats.at(50).second;;
uint32_t hg_60_queries = hg_stats.at(60).first;
uint32_t hg_60_sync_queries = hg_stats.at(60).second;;
uint32_t hg_1900_queries = hg_stats.at(1900).first;
uint32_t hg_1900_sync_queries = hg_stats.at(1900).second;;
uint32_t hg_1901_queries = hg_stats.at(1901).first;
uint32_t hg_1901_sync_queries = hg_stats.at(1901).second;;
uint32_t hg_50_exp_queries =
uint32_t hg_1900_exp_queries =
3 + // Database creation + Table DROP + Table creation
NUM_ROWS + // Initial data load
NUM_CHECKS; // Updates (matching number of checks)
uint32_t hg_50_exp_sync_queries = NUM_CHECKS - 1;
uint32_t hg_1900_exp_sync_queries = NUM_CHECKS - 1;
bool hg_50_checks = hg_50_exp_queries == hg_50_queries && hg_50_sync_queries == hg_50_exp_sync_queries;
bool hg_60_checks = hg_60_queries == NUM_CHECKS && hg_60_sync_queries == NUM_CHECKS;
bool hg_1900_checks = hg_1900_exp_queries == hg_1900_queries && hg_1900_sync_queries == hg_1900_exp_sync_queries;
bool hg_1901_checks = hg_1901_queries == NUM_CHECKS && hg_1901_sync_queries == NUM_CHECKS;
ok(
hg_50_checks && hg_60_checks,
hg_1900_checks && hg_1901_checks,
"GTID based query routing: {"
" hg_50: { exp_queries: %d, act_queries: %d, exp_sync_queries: %d, act_sync_queries: %d },"
" hg_60: { exp_queries: %d, act_queries: %d, exp_sync_queries: %d, act_sync_queries: %d }"
" hg_1900: { exp_queries: %d, act_queries: %d, exp_sync_queries: %d, act_sync_queries: %d },"
" hg_1901: { exp_queries: %d, act_queries: %d, exp_sync_queries: %d, act_sync_queries: %d }"
" }",
hg_50_exp_queries, hg_50_queries, hg_50_exp_sync_queries, hg_50_sync_queries,
NUM_CHECKS, hg_60_queries, NUM_CHECKS, hg_60_queries
hg_1900_exp_queries, hg_1900_queries, hg_1900_exp_sync_queries, hg_1900_sync_queries,
NUM_CHECKS, hg_1901_queries, NUM_CHECKS, hg_1901_queries
);
// Reset connection pool stats
@ -209,19 +209,19 @@ int check_gitd_tracking(const CommandLine& cl, MYSQL* proxysql_mysql, MYSQL* pro
// Extract stats
hg_stats = extract_hosgtroups_stats(conn_pool_stats);
hg_50_queries = hg_stats.at(50).first;
hg_50_sync_queries = hg_stats.at(50).second;;
hg_60_queries = hg_stats.at(60).first;
hg_60_sync_queries = hg_stats.at(60).second;;
hg_1900_queries = hg_stats.at(1900).first;
hg_1900_sync_queries = hg_stats.at(1900).second;;
hg_1901_queries = hg_stats.at(1901).first;
hg_1901_sync_queries = hg_stats.at(1901).second;;
uint32_t hg_60_exp_queries = NUM_CHECKS / 5;
uint32_t hg_1901_exp_queries = NUM_CHECKS / 5;
ok(
hg_50_queries == 0 && hg_50_sync_queries == 0 && hg_60_queries == hg_60_exp_queries && hg_60_sync_queries == 0,
"Queries should only be executed in 'HG 60' and no GTID sync should take place: {"
" hg_50: { exp_queries: 0, act_queries: %d, exp_sync_queries: 0, act_sync_queries: %d },"
" hg_60: { exp_queries: %d, act_queries: %d, exp_sync_queries: 0, act_sync_queries: %d },"
hg_1900_queries == 0 && hg_1900_sync_queries == 0 && hg_1901_queries == hg_1901_exp_queries && hg_1901_sync_queries == 0,
"Queries should only be executed in 'HG 1901' and no GTID sync should take place: {"
" hg_1900: { exp_queries: 0, act_queries: %d, exp_sync_queries: 0, act_sync_queries: %d },"
" hg_1901: { exp_queries: %d, act_queries: %d, exp_sync_queries: 0, act_sync_queries: %d },"
" }",
hg_50_queries, hg_50_sync_queries, hg_60_exp_queries, hg_60_queries, hg_60_sync_queries
hg_1900_queries, hg_1900_sync_queries, hg_1901_exp_queries, hg_1901_queries, hg_1901_sync_queries
);
return EXIT_SUCCESS;
@ -287,7 +287,7 @@ int main(int argc, char** argv) {
if (r_row == 0) { r_row = 1; }
string s_query {};
string_format("SELECT * FROM binlog_db.gtid_test WHERE id=%d", s_query, r_row);
string_format("SELECT * FROM test.gtid_test WHERE id=%d", s_query, r_row);
// Perform the select and ignore the result
rc = mysql_query(proxysql_mysql, s_query.c_str());

@ -95,7 +95,8 @@ int extract_sess_qpo_dest_hg(MYSQL* proxy) {
int check_fast_routing_rules(MYSQL* proxy, uint32_t rng_init, uint32_t rng_end) {
for (uint32_t i = rng_init; i < rng_end; i += 2) {
const string schema { "randomschemaname" + std::to_string(i) };
// const string schema { "randomschemaname" + std::to_string(i) };
const string schema { "test" + std::to_string(i) };
diag("Changing schema to '%s'", schema.c_str());
if (mysql_select_db(proxy, schema.c_str())) {
@ -168,7 +169,8 @@ int create_fast_routing_rules_range(
MYSQL_QUERY_T(admin, ("DELETE FROM mysql_query_rules_fast_routing WHERE destination_hostgroup BETWEEN " + init + " AND " + end).c_str());
for (uint32_t i = rng_init; i < rng_end; i += 2) {
const string schema { "randomschemaname" + std::to_string(i) + "" };
// const string schema { "randomschemaname" + std::to_string(i) + "" };
const string schema { "test" + std::to_string(i) + "" };
const string user { cl.username };
string q = "INSERT INTO mysql_query_rules_fast_routing (username, schemaname, flagIN, destination_hostgroup, comment) VALUES ";

Loading…
Cancel
Save