diff options
author | Pavan Deolasee | 2016-02-01 09:19:37 +0000 |
---|---|---|
committer | Pavan Deolasee | 2016-10-18 09:48:13 +0000 |
commit | d9727ac8fe71988d2034b26360437878b4077427 (patch) | |
tree | 1a0057a39c5e7c8dba4c9c6acd577768dc8f3e14 | |
parent | b302e17d1e5725441c5ca44b97ec127255bd580c (diff) |
Exponetially increase the sleep before retrying commit on the GTM.
When a transaction waits for another transaction to complete, we enforce the
same ordering on the same GTM by making the former transaction wait on the
latter. We do this by a simple retry logic. While the latter transaction should
ideally finish soon because it has already finished on the datanode, the retry
loop now waits exponentially, starting at 1000usec but limited by 1s.
Patch by Mason Sharp
-rw-r--r-- | src/gtm/client/gtm_client.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/gtm/client/gtm_client.c b/src/gtm/client/gtm_client.c index 1ac19f4c6f..be1f6b27cd 100644 --- a/src/gtm/client/gtm_client.c +++ b/src/gtm/client/gtm_client.c @@ -26,6 +26,7 @@ #define CLIENT_GTM_TIMEOUT 20 #endif #endif +#define MAX_RETRY_SLEEP_MICRO 1000000 #include <time.h> #include "gtm/gtm_c.h" @@ -652,6 +653,7 @@ commit_transaction_internal(GTM_Conn *conn, GlobalTransactionId gxid, { GTM_Result *res = NULL; time_t finish_time; + long retry_sleep = 1000; retry: /* Start the message. */ @@ -712,7 +714,13 @@ retry: * might make sense to flash a warning and proceed after * certain number of retries */ - pg_usleep(1000); + if (retry_sleep <= MAX_RETRY_SLEEP_MICRO) + { + retry_sleep = retry_sleep * 2; + if (retry_sleep > MAX_RETRY_SLEEP_MICRO) + retry_sleep = MAX_RETRY_SLEEP_MICRO; + } + pg_usleep(retry_sleep); goto retry; } } @@ -757,6 +765,7 @@ commit_prepared_transaction_internal(GTM_Conn *conn, { GTM_Result *res = NULL; time_t finish_time; + long retry_sleep = 1000; retry: /* Start the message */ @@ -800,7 +809,13 @@ retry: if (res->gr_resdata.grd_eof_txn.status == STATUS_DELAYED) { /* See comments in commit_transaction_internal() */ - pg_usleep(1000); + if (retry_sleep <= MAX_RETRY_SLEEP_MICRO) + { + retry_sleep = retry_sleep * 2; + if (retry_sleep > MAX_RETRY_SLEEP_MICRO) + retry_sleep = MAX_RETRY_SLEEP_MICRO; + } + pg_usleep(retry_sleep); goto retry; } } |