From 5fb0eef19a8032d59f31e761463bf0e46f7e1462 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Wed, 14 Sep 2022 18:15:55 +0000 Subject: [PATCH 1/2] Fix isolation level in AWS Aurora If aurora_read_replica_read_committed is set, isolation level is internally reset so that it will be set again. This solves the weird behavior in AWS Aurora related to isolation level as described in https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraMySQL.Reference.html#AuroraMySQL.Reference.IsolationLevels Basically, to change isolation level you must first set aurora_read_replica_read_committed , and then isolation level --- lib/MySQL_Session.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index 582e025546..21e64a7bc8 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -2453,8 +2453,17 @@ bool MySQL_Session::handler_again___status_SETTING_GENERIC_VARIABLE(int *_rc, co else { sprintf(query,q,"tx_isolation", var_value); } - } - else { + } else if (strncasecmp("aurora_read_replica_read_committed", var_name, 34) == 0) { + MySQL_Connection *beconn = mybe->server_myds->myconn; + if (beconn->var_hash[SQL_ISOLATION_LEVEL] != 0) { + beconn->var_hash[SQL_ISOLATION_LEVEL] = 0; + if (beconn->variables[SQL_ISOLATION_LEVEL].value) { + free(beconn->variables[SQL_ISOLATION_LEVEL].value); + beconn->variables[SQL_ISOLATION_LEVEL].value = NULL; + } + } + sprintf(query,q,var_name, var_value); + } else { sprintf(query,q,var_name, var_value); } query_length=strlen(query); From 8344be1abc4eb33f187f3da2ef6f50635e4661d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Thu, 15 Sep 2022 06:00:47 +0000 Subject: [PATCH 2/2] Added comment related to aurora_read_replica_read_committed --- lib/MySQL_Session.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index 21e64a7bc8..bf010382e5 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -2454,6 +2454,13 @@ bool MySQL_Session::handler_again___status_SETTING_GENERIC_VARIABLE(int *_rc, co sprintf(query,q,"tx_isolation", var_value); } } else if (strncasecmp("aurora_read_replica_read_committed", var_name, 34) == 0) { + // If aurora_read_replica_read_committed is set, isolation level is + // internally reset so that it will be set again. + // This solves the weird behavior in AWS Aurora related to isolation level + // as described in + // https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraMySQL.Reference.html#AuroraMySQL.Reference.IsolationLevels + // Basically, to change isolation level you must first set + // aurora_read_replica_read_committed , and then isolation level MySQL_Connection *beconn = mybe->server_myds->myconn; if (beconn->var_hash[SQL_ISOLATION_LEVEL] != 0) { beconn->var_hash[SQL_ISOLATION_LEVEL] = 0;