- Add dynamic hostgroup discovery from mysql_servers table
- Replace hardcoded hostgroups (0, 1) with discovered ones (e.g., 1300, 1301)
- Add comprehensive debugging output for troubleshooting:
- Current server and user configuration
- Discovered hostgroups
- Query execution details (before/after counts)
- Routing failures with specific queries
The test was failing because it used hardcoded hostgroups 0 and 1,
but the Docker CI infrastructure uses dynamic hostgroups (1300, 1301, etc.)
depending on the infrastructure type.
diag("Discovered writer hostgroup from user 'root': %d",writer_hg);
}
mysql_free_result(hg_res);
// Try to discover reader hostgroup - it's typically the next hostgroup after writer
// or we can query mysql_servers to find hostgroups with servers in ONLINE status
MYSQL_QUERY(proxysql_admin,"SELECT DISTINCT hostgroup_id FROM mysql_servers WHERE status='ONLINE' AND hostgroup_id != 0 ORDER BY hostgroup_id LIMIT 2");
hg_res=mysql_store_result(proxysql_admin);
std::vector<int>online_hostgroups;
while((hg_row=mysql_fetch_row(hg_res))){
online_hostgroups.push_back(atoi(hg_row[0]));
}
mysql_free_result(hg_res);
if(online_hostgroups.size()>=2){
// We have at least 2 hostgroups - use the first two for writer and reader
writer_hg=online_hostgroups[0];
reader_hg=online_hostgroups[1];
diag("Discovered hostgroups from mysql_servers: writer=%d, reader=%d",writer_hg,reader_hg);
}elseif(online_hostgroups.size()==1){
writer_hg=online_hostgroups[0];
reader_hg=writer_hg;// Use same hostgroup if only one exists
diag("Only one hostgroup found: writer=%d, reader=%d (same)",writer_hg,reader_hg);
}
// Now update the test data with the discovered hostgroups
diag("Updating test query rules to use discovered hostgroups: writer=%d, reader=%d",writer_hg,reader_hg);
// Update dst_hostgroup_tests with dynamic hostgroups
for(auto&test:dst_hostgroup_tests){
for(auto&rule:test.first){
// Replace hardcoded hostgroups with discovered ones