Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions common_mk/openssl_flags.mk
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ else
$(error Warning: OpenSSL libraries directory (SSL_LDIR) not found. Exiting. Please ensure the correct path is set or install OpenSSL version 3.)
endif
else
$(error Warning: OpenSSL headers (SSL_IDIR) not found. Exiting. Please install OpenSSL version 3.)
endif
$(error Warning: OpenSSL headers (SSL_IDIR) not found. Exiting. Please install OpenSSL version 3 and make sure pkg-config is present.)
endif
24 changes: 15 additions & 9 deletions lib/PgSQL_HostGroups_Manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2033,15 +2033,21 @@ PgSQL_SrvC *PgSQL_HGC::get_random_MySrvC(char * gtid_uuid, uint64_t gtid_trxid,
}
}
}
bool use_index_instead_of_weight = false;
if (sum==0) {
proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL, 7, "Returning PgSQL_SrvC NULL because no backend ONLINE or with weight\n");
if (l>32) {
free(mysrvcCandidates);
}
if (num_candidates==0) {
proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL, 7, "Returning PgSQL_SrvC NULL because no backend ONLINE or with weight\n");
if (l>32) {
free(mysrvcCandidates);
}
#ifdef TEST_AURORA
array_mysrvc_cands += num_candidates;
array_mysrvc_cands += num_candidates;
#endif // TEST_AURORA
return NULL; // if we reach here, we couldn't find any target
return NULL; // if we reach here, we couldn't find any target
}
// All servers have weight 0, but we have some candidates - pick a random one (assume they all have weight 1)
proxy_info("No available server in hostgroup %u with weight > 0, but %u candidates found. This is probably due to max_connections reached for all servers. Using candidates with weight 0\n", hid, num_candidates);
use_index_instead_of_weight = true;
}

/*
Expand All @@ -2066,7 +2072,7 @@ PgSQL_SrvC *PgSQL_HGC::get_random_MySrvC(char * gtid_uuid, uint64_t gtid_trxid,
}
*/

unsigned int New_sum=sum;
unsigned int New_sum=use_index_instead_of_weight ? num_candidates : sum;

if (New_sum==0) {
proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL, 7, "Returning PgSQL_SrvC NULL because no backend ONLINE or with weight\n");
Expand Down Expand Up @@ -2114,7 +2120,7 @@ PgSQL_SrvC *PgSQL_HGC::get_random_MySrvC(char * gtid_uuid, uint64_t gtid_trxid,
New_sum = 0;
for (j=0; j<num_candidates; j++) {
mysrvc = mysrvcCandidates[j];
New_sum+=mysrvc->weight;
New_sum+=use_index_instead_of_weight ? 1 : mysrvc->weight;
}
}
}
Expand All @@ -2132,7 +2138,7 @@ PgSQL_SrvC *PgSQL_HGC::get_random_MySrvC(char * gtid_uuid, uint64_t gtid_trxid,

for (j=0; j<num_candidates; j++) {
mysrvc = mysrvcCandidates[j];
New_sum+=mysrvc->weight;
New_sum+=use_index_instead_of_weight ? 1 : mysrvc->weight;
if (k<=New_sum) {
proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL, 7, "Returning PgSQL_SrvC %p, server %s:%d\n", mysrvc, mysrvc->address, mysrvc->port);
if (l>32) {
Expand Down