diff --git a/pgxn/neon/libpagestore.c b/pgxn/neon/libpagestore.c index 3b038f906f..5db9e5e08e 100644 --- a/pgxn/neon/libpagestore.c +++ b/pgxn/neon/libpagestore.c @@ -133,6 +133,9 @@ pageserver_connect(int elevel) const char *values[3]; int n; + static TimestampTz last_connect_time = 0; + TimestampTz now; + Assert(!connected); if (CheckConnstringUpdated()) @@ -140,6 +143,17 @@ pageserver_connect(int elevel) ReloadConnstring(); } + now = GetCurrentTimestamp(); + if ((now - last_connect_time) < RECONNECT_INTERVAL_USEC) + { + pg_usleep(RECONNECT_INTERVAL_USEC); + last_connect_time = GetCurrentTimestamp(); + } + else + { + last_connect_time = now; + } + /* * Connect using the connection string we got from the * neon.pageserver_connstring GUC. If the NEON_AUTH_TOKEN environment @@ -333,7 +347,6 @@ pageserver_send(NeonRequest *request) { HandleMainLoopInterrupts(); n_reconnect_attempts += 1; - pg_usleep(RECONNECT_INTERVAL_USEC); } n_reconnect_attempts = 0; } diff --git a/pgxn/neon/pagestore_smgr.c b/pgxn/neon/pagestore_smgr.c index 6cf2762179..8888cd89c6 100644 --- a/pgxn/neon/pagestore_smgr.c +++ b/pgxn/neon/pagestore_smgr.c @@ -275,26 +275,6 @@ static inline void prefetch_set_unused(uint64 ring_index); static XLogRecPtr neon_get_request_lsn(bool *latest, NRelFileInfo rinfo, ForkNumber forknum, BlockNumber blkno); - -#define INITIAL_EXPONENTIAL_BACKOFF_DELAY 1000 -#define EXPONENTIAL_BACKOFF_EXPONENT 2 -#define MAX_EXPONENTIAL_BACKOFF_DELAY (1000*1000) - -static void -InitExponentialBackoff(long *delay) -{ - *delay = INITIAL_EXPONENTIAL_BACKOFF_DELAY; -} - -static void -PerformExponentialBackoff(long *delay) -{ - pg_usleep(*delay); - *delay *= EXPONENTIAL_BACKOFF_EXPONENT; - if(*delay >= MAX_EXPONENTIAL_BACKOFF_DELAY) - *delay = MAX_EXPONENTIAL_BACKOFF_DELAY; -} - static bool compact_prefetch_buffers(void) { @@ -682,7 +662,6 @@ prefetch_do_request(PrefetchRequest *slot, bool *force_latest, XLogRecPtr *force .forknum = slot->buftag.forkNum, .blkno = slot->buftag.blockNum, }; - long backoff_delay_us; if (force_lsn && force_latest) { @@ -725,11 +704,7 @@ prefetch_do_request(PrefetchRequest *slot, bool *force_latest, XLogRecPtr *force Assert(slot->response == NULL); Assert(slot->my_ring_index == MyPState->ring_unused); - InitExponentialBackoff(&backoff_delay_us); - while (!page_server->send((NeonRequest *) &request)) - { - PerformExponentialBackoff(&backoff_delay_us); - } + while (!page_server->send((NeonRequest *) &request)); /* update prefetch state */ MyPState->n_requests_inflight += 1;