fix: make server_backoff_time atomic

Signed-off-by: Wazir Ahmed <wazir@proxysql.com>
session-track-system-variable
Wazir Ahmed 1 month ago
parent a76be53785
commit f815b77812

@ -212,7 +212,7 @@ class MySrvC { // MySQL Server Container
// This is primarily used when `session_track_variables::ENFORCED` mode is active.
// If a server lacks the required capabilities in this mode, it is temporarily
// excluded from selection for a specified duration.
unsigned long long server_backoff_time;
std::atomic<unsigned long long> server_backoff_time;
MySrvConnList *ConnectionsUsed;
MySrvConnList *ConnectionsFree;

@ -18,6 +18,7 @@ MySrvC *MyHGC::get_random_MySrvC(char * gtid_uuid, uint64_t gtid_trxid, int max_
unsigned int TotalUsedConn=0;
unsigned int l=mysrvs->cnt();
static time_t last_hg_log = 0;
unsigned long long server_backoff_time;
#ifdef TEST_AURORA
unsigned long long a1 = array_mysrvc_total/10000;
array_mysrvc_total += l;
@ -39,8 +40,10 @@ MySrvC *MyHGC::get_random_MySrvC(char * gtid_uuid, uint64_t gtid_trxid, int max_
mysrvc=mysrvs->idx(j);
if (mysrvc->get_status() == MYSQL_SERVER_STATUS_ONLINE) { // consider this server only if ONLINE
// skip servers that are in backoff period
if (mysrvc->server_backoff_time > sess->thread->curtime)
server_backoff_time = mysrvc->server_backoff_time.load(std::memory_order_relaxed);
if (server_backoff_time > sess->thread->curtime) {
continue;
}
if (mysrvc->myhgc->num_online_servers.load(std::memory_order_relaxed) <= mysrvc->myhgc->attributes.max_num_online_servers) { // number of online servers in HG is within configured range
if (mysrvc->ConnectionsUsed->conns_length() < mysrvc->max_connections) { // consider this server only if didn't reach max_connections

@ -1,4 +1,5 @@
#include "../deps/json/json.hpp"
#include <atomic>
using json = nlohmann::json;
#define PROXYJSON
@ -9764,8 +9765,9 @@ bool MySQL_Session::handle_session_track_capabilities() {
}
if (!server_support_session_track) {
// be_conn->parent->server_backoff_time = thread->curtime + (600 * 1000000); // 10 minutes
be_conn->parent->server_backoff_time = thread->curtime + (30 * 1000000); // 30 seconds
// set 30 seconds backoff time
be_conn->parent->server_backoff_time.store(thread->curtime + (30 * 1000000), std::memory_order_relaxed);
if (session_fast_forward) {
mybe->server_myds->destroy_MySQL_Connection_From_Pool(false);
} else {

@ -1,4 +1,5 @@
#include "../deps/json/json.hpp"
#include <atomic>
using json = nlohmann::json;
#define PROXYJSON
@ -6388,13 +6389,17 @@ MySQL_Connection * MySQL_Thread::get_MyConn_local(unsigned int _hid, MySQL_Sessi
if (sess->client_myds->myconn == NULL) return NULL;
if (sess->client_myds->myconn->userinfo == NULL) return NULL;
unsigned int i;
unsigned long long server_backoff_time;
std::vector<MySrvC *> parents; // this is a vector of srvers that needs to be excluded in case gtid_uuid is used
MySQL_Connection *c=NULL;
for (i=0; i<cached_connections->len; i++) {
c = (MySQL_Connection *) cached_connections->index(i);
// skip servers that are in backoff period
if (c->parent->server_backoff_time > curtime)
server_backoff_time = c->parent->server_backoff_time.load(std::memory_order_relaxed);
if (server_backoff_time > curtime) {
continue;
}
if (c->parent->myhgc->hid==_hid && sess->client_myds->myconn->match_tracked_options(c)) { // options are all identical
if (

@ -31,7 +31,7 @@ MySrvC::MySrvC(
bytes_recv=0;
max_connections_used=0;
queries_gtid_sync=0;
server_backoff_time = 0;
server_backoff_time.store(0);
time_last_detected_error=0;
connect_ERR_at_time_last_detected_error=0;
shunned_automatic=false;

Loading…
Cancel
Save