From 5336e72f1cc229cd303310cffeb92ed1060414bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Thu, 29 Aug 2019 14:44:47 +1000 Subject: [PATCH] For Aurora, do not use the writer if there are good readers candidates --- lib/MySQL_HostGroups_Manager.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/MySQL_HostGroups_Manager.cpp b/lib/MySQL_HostGroups_Manager.cpp index 321ecd018..a225a1435 100644 --- a/lib/MySQL_HostGroups_Manager.cpp +++ b/lib/MySQL_HostGroups_Manager.cpp @@ -2355,6 +2355,31 @@ MySrvC *MyHGC::get_random_MySrvC(char * gtid_uuid, uint64_t gtid_trxid, int max_ } } } +#ifdef USE_MYSRVC_ARRAY + if (max_lag_ms) { // we are using AWS Aurora, as this logic is implemented only here) + if (num_candidates > 2) { // there are at least 2 replicas + // we try to remove the writer + unsigned int total_aws_aurora_current_lag_us=0; + for (j=0; jaws_aurora_current_lag_us; + } + if (total_aws_aurora_current_lag_us) { // we are just double checking that we don't have all servers with aws_aurora_current_lag_us==0 + for (j=0; jaws_aurora_current_lag_us==0) { + sum-=mysrvc->weight; + TotalUsedConn-=mysrvc->ConnectionsUsed->conns_length(); + if (j < num_candidates-1) { + mysrvcCandidates[j]=mysrvcCandidates[num_candidates-1]; + } + num_candidates--; + } + } + } + } + } +#endif // USE_MYSRVC_ARRAY if (sum==0) { // per issue #531 , we try a desperate attempt to bring back online any shunned server // we do this lowering the maximum wait time to 10% @@ -5388,7 +5413,7 @@ bool MySQL_HostGroups_Manager::aws_aurora_replication_lag_action(int _whid, int // the server should be a reader // but it is in the writer hostgroup ret = false; - reader_found_in_whg == true; + reader_found_in_whg = true; } } else { if (is_writer==true) {