Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rommellayco make stale seconds configurable #630

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pghoard/restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,9 @@ def fetch_all(self):
except TimeoutError:
self.pending_jobs.clear()
self.last_progress_ts = time.monotonic()

# Increase the timeout and retry
self.max_stale_seconds = min(self.max_stale_seconds * 2, 480)
if self.errors:
break

Expand Down
10 changes: 8 additions & 2 deletions test/test_restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ def test_real_processing_with_threading_retries_on_timeout_fails_after_3(self):

def real_processing_with_threading_retries_on_timeout(self, fetcher, restore_dir, max_fails):
fail_counter = [0]
base_max_stale_seconds = 2

class FailingChunkFetcher(ChunkFetcher):
def _fetch_and_extract_one_backup(self, metadata, file_size, fetch_fn):
Expand All @@ -358,9 +359,14 @@ def _fetch_and_extract_one_backup(self, metadata, file_size, fetch_fn):
# Corrupt the file to test that retrying failed basebackup chunk yields sensible results
with open(os.path.join(restore_dir, "pg_notify", "0000"), "w") as f:
f.write("foo")
time.sleep(4)

fetcher.max_stale_seconds = 2
# ensure we sleep long enough to timeout based on the number of retries
sleep_seconds = base_max_stale_seconds * (
2 ** max_fails
) if max_fails < STALL_MIN_RETRIES else base_max_stale_seconds
time.sleep(sleep_seconds)

fetcher.max_stale_seconds = base_max_stale_seconds
with patch("pghoard.restore.ChunkFetcher", new=FailingChunkFetcher):
if max_fails < STALL_MIN_RETRIES:
fetcher.fetch_all()
Expand Down
Loading