Skip to content

Commit 8ef6342

Browse files
authored
Merge pull request #639 from Aiven-Open/rdunklau/fix_timeline_disappearing
One more occurence of making pg_wal contents disappear
2 parents 6afc524 + bc69bc6 commit 8ef6342

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

pghoard/webserver.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ def get_wal_or_timeline_file(self, site: str, filename: str, filetype: str) -> N
537537
# After reaching a recovery_target and restart of a PG server, PG wants to replay and refetch
538538
# files from the archive starting from the latest checkpoint. We have potentially fetched these files
539539
# already earlier. Check if we have the files already and if we do, don't go over the network to refetch
540-
# them yet again but just rename them to the path that PG is requesting.
540+
# them yet again but just copy them to the path that PG is requesting.
541541
xlog_path = os.path.join(xlog_dir, filename)
542542
exists_on_disk = os.path.exists(xlog_path)
543543
if exists_on_disk and filename not in self.server.served_from_disk:
@@ -550,7 +550,8 @@ def get_wal_or_timeline_file(self, site: str, filename: str, filetype: str) -> N
550550
except ValueError as e:
551551
self.server.log.warning("Found file: %r but it was invalid: %s", xlog_path, e)
552552
else:
553-
self._rename(xlog_path, target_path)
553+
if xlog_path != target_path:
554+
shutil.copyfile(xlog_path, target_path)
554555
self.server.served_from_disk.append(filename)
555556
self.server.most_recently_served_files[filetype] = {
556557
"name": filename,

test/test_webserver.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ def test_wal_fetch_optimization(self, pghoard):
189189
)
190190
assert os.path.exists(output_path)
191191
os.unlink(output_path)
192+
os.unlink(valid_wal_path)
192193

193194
with pytest.raises(postgres_command.PGCError):
194195
restore_command(
@@ -601,8 +602,11 @@ def test_retry_fetches_remote(self, pghoard_no_mp):
601602
status = conn.getresponse().status
602603
assert status == 201
603604

605+
# This test used to ensure we deleted files from the pg_xlog directory
606+
# It now tests that if the operation results in a copy, the original file
607+
# is still copied instead of being removed
604608
with open(storage_name, "rb") as f:
605-
assert f.read() == storage_data
609+
assert f.read() == on_disk_data
606610

607611
def test_restore_command_retry(self, pghoard):
608612
failures = [0, ""]

0 commit comments

Comments
 (0)