Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iterate all reader hostgroups in set_testing-240 #4411

Merged
merged 2 commits into from
Jan 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 69 additions & 41 deletions test/tap/tests/set_testing-240-t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,11 @@ void * my_conn_thread(void *arg) {
}
__sync_fetch_and_add(&query_phase_completed,1);

// close all connections
for (i=0; i<count; i++) {
mysql_close(mysqlconns[i]);
}

return NULL;
}

Expand All @@ -469,11 +474,6 @@ int main(int argc, char *argv[]) {

std::string fileName2(std::string(cl.workdir) + "/set_testing-240.csv");

if (detect_version(cl, is_mariadb) != 0) {
diag("Cannot detect MySQL version");
return exit_status();
}

/*
num_threads = 10;
queries_per_connections = 10;
Expand All @@ -498,59 +498,87 @@ int main(int argc, char *argv[]) {
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin));
return EXIT_FAILURE;
}

diag("Disabling admin-hash_passwords to be able to run test on MySQL 8");
MYSQL_QUERY(proxysql_admin, "SET admin-hash_passwords='false'");
MYSQL_QUERY(proxysql_admin, "LOAD ADMIN VARIABLES TO RUNTIME");
MYSQL_QUERY(proxysql_admin, "LOAD MYSQL USERS TO RUNTIME");

diag("Creating new hostgroup 101: DELETE FROM mysql_servers WHERE hostgroup_id = 101");
// find all reader host groups
MYSQL_QUERY(proxysql_admin, "DELETE FROM mysql_servers WHERE hostgroup_id = 101");
const std::string insert = "INSERT INTO mysql_servers (hostgroup_id, hostname, port, max_connections, max_replication_lag, comment) SELECT DISTINCT 101, hostname, port, 100, 0, comment FROM mysql_servers WHERE hostgroup_id = '1'";
diag("Creating new hostgroup 101: %s" , insert.c_str());
MYSQL_QUERY(proxysql_admin, insert.c_str());
MYSQL_QUERY(proxysql_admin, "LOAD MYSQL SERVERS TO RUNTIME");
diag("Changing read traffic to hostgroup 101: UPDATE mysql_query_rules SET destination_hostgroup=101 WHERE destination_hostgroup=1");
MYSQL_QUERY(proxysql_admin, "UPDATE mysql_query_rules SET destination_hostgroup=101 WHERE destination_hostgroup=1");
MYSQL_QUERY(proxysql_admin, "LOAD MYSQL QUERY RULES TO RUNTIME");
MYSQL_QUERY(proxysql_admin, "SELECT hostgroup_id, comment FROM mysql_servers WHERE hostgroup_id%10 = 1 GROUP BY hostgroup_id");
MYSQL_RES *result = mysql_store_result(proxysql_admin);
std::vector<mysql_res_row> rows_res { extract_mysql_rows(result) };
mysql_free_result(result);

for (const auto& act_row : rows_res) {
diag("Found hostgroup: %s '%s'", act_row[0].c_str(), act_row[1].c_str());
}

//queries = 3000;
//queries = testCases.size();
queries = queries / rows_res.size(); // keep test duration constant
unsigned int p = queries * num_threads;
p *= 2; // number of algorithms
p *= 2; // number of algorithms
p *= rows_res.size(); // number of host groups
plan(p);

if (strcmp(host,"localhost")==0) {
local = 1;
}
if (uniquequeries == 0) {
if (queries) uniquequeries=queries;
}
if (uniquequeries) {
uniquequeries=(int)sqrt(uniquequeries);
}
for (const auto& act_row : rows_res) {
diag("Using hostgroup: %s '%s'", act_row[0].c_str(), act_row[1].c_str());

for (int algo = 1; algo <= 2; algo++ ) {
connect_phase_completed = 0;
query_phase_completed = 0;
std::string qu = "SET mysql-set_parser_algorithm=" + std::to_string(algo);
diag("Setting: %s", qu.c_str());
MYSQL_QUERY(proxysql_admin, qu.c_str());
MYSQL_QUERY(proxysql_admin, "LOAD MYSQL VARIABLES TO RUNTIME");
pthread_t *thi=(pthread_t *)malloc(sizeof(pthread_t)*num_threads);
if (thi==NULL)
diag("Creating new hostgroup 101: DELETE FROM mysql_servers WHERE hostgroup_id = 101");
MYSQL_QUERY(proxysql_admin, "DELETE FROM mysql_servers WHERE hostgroup_id = 101");

const std::string insert = "INSERT INTO mysql_servers (hostgroup_id, hostname, port, max_connections, max_replication_lag, comment) SELECT DISTINCT 101, hostname, port, 100, 0, comment FROM mysql_servers WHERE hostgroup_id = '" + act_row[0] + "'";
diag("Creating new hostgroup 101: %s" , insert.c_str());
MYSQL_QUERY(proxysql_admin, insert.c_str());
MYSQL_QUERY(proxysql_admin, "LOAD MYSQL SERVERS TO RUNTIME");

const std::string update = "UPDATE mysql_query_rules SET destination_hostgroup=101 WHERE destination_hostgroup=" + act_row[0];
diag("Changing read traffic to hostgroup 101: %s", update.c_str());
MYSQL_QUERY(proxysql_admin, update.c_str());
MYSQL_QUERY(proxysql_admin, "LOAD MYSQL QUERY RULES TO RUNTIME");

if (detect_version(cl, is_mariadb) != 0) {
diag("Cannot detect MySQL version");
return exit_status();
}

for (unsigned int i=0; i<num_threads; i++) {
if ( pthread_create(&thi[i], NULL, my_conn_thread , NULL) != 0 )
perror("Thread creation");
if (strcmp(host,"localhost")==0) {
local = 1;
}
for (unsigned int i=0; i<num_threads; i++) {
pthread_join(thi[i], NULL);
if (uniquequeries == 0) {
if (queries) uniquequeries=queries;
}
free(thi);
}
for (std::unordered_map<std::string,var_counter>::iterator it = vars_counters.begin(); it!=vars_counters.end(); it++) {
diag("Unknown variable %s:\t Count: %d , unknown: %d", it->first.c_str(), it->second.count, it->second.unknown);
if (uniquequeries) {
uniquequeries=(int)sqrt(uniquequeries);
}

for (int algo = 1; algo <= 2; algo++ ) {
connect_phase_completed = 0;
query_phase_completed = 0;
std::string qu = "SET mysql-set_parser_algorithm=" + std::to_string(algo);
diag("Setting %s", qu.c_str());
MYSQL_QUERY(proxysql_admin, qu.c_str());
MYSQL_QUERY(proxysql_admin, "LOAD MYSQL VARIABLES TO RUNTIME");
pthread_t *thi=(pthread_t *)malloc(sizeof(pthread_t)*num_threads);
if (thi==NULL)
return exit_status();

for (unsigned int i=0; i<num_threads; i++) {
if ( pthread_create(&thi[i], NULL, my_conn_thread , NULL) != 0 )
perror("Thread creation");
}
for (unsigned int i=0; i<num_threads; i++) {
pthread_join(thi[i], NULL);
}
free(thi);
}
for (std::unordered_map<std::string,var_counter>::iterator it = vars_counters.begin(); it!=vars_counters.end(); it++) {
diag("Unknown variable %s:\t Count: %d , unknown: %d", it->first.c_str(), it->second.count, it->second.unknown);
}
sleep(10);

}
return exit_status();
}
Loading