Skip to content

Commit 7b0d214

Browse files
committed
PGPRO-692: Compress/Decompress WAL files during archive-push/archive-get
1 parent 39519f7 commit 7b0d214

File tree

5 files changed

+390
-117
lines changed

5 files changed

+390
-117
lines changed

src/archive.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* --wal-file-path %p --wal-file-name %f', to move backups into arclog_path.
1919
* Where archlog_path is $BACKUP_PATH/wal/system_id.
2020
* Currently it just copies wal files to the new location.
21-
* TODO: Planned options: compress, list the arclog content,
21+
* TODO: Planned options: list the arclog content,
2222
* compute and validate checksums.
2323
*/
2424
int
@@ -64,7 +64,8 @@ do_archive_push(char *wal_file_path, char *wal_file_name)
6464
if (access(backup_wal_file_path, F_OK) != -1)
6565
elog(ERROR, "file '%s', already exists.", backup_wal_file_path);
6666

67-
copy_wal_file(absolute_wal_file_path, backup_wal_file_path);
67+
push_wal_file(absolute_wal_file_path, backup_wal_file_path,
68+
compress_shortcut);
6869
elog(INFO, "pg_probackup archive-push completed successfully");
6970

7071
return 0;
@@ -96,8 +97,9 @@ do_archive_get(char *wal_file_path, char *wal_file_name)
9697
join_path_components(absolute_wal_file_path, current_dir, wal_file_path);
9798
join_path_components(backup_wal_file_path, arclog_path, wal_file_name);
9899

99-
elog(INFO, "pg_probackup archive-get from %s to %s", backup_wal_file_path, absolute_wal_file_path);
100-
copy_wal_file(backup_wal_file_path, absolute_wal_file_path);
100+
elog(INFO, "pg_probackup archive-get from %s to %s",
101+
backup_wal_file_path, absolute_wal_file_path);
102+
get_wal_file(backup_wal_file_path, absolute_wal_file_path);
101103
elog(INFO, "pg_probackup archive-get completed successfully");
102104

103105
return 0;

src/backup.c

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,11 +1350,16 @@ wait_wal_lsn(XLogRecPtr lsn, bool wait_prev_segment)
13501350
TimeLineID tli;
13511351
XLogSegNo targetSegNo;
13521352
char wal_dir[MAXPGPATH],
1353-
wal_segment_full_path[MAXPGPATH];
1353+
wal_segment_path[MAXPGPATH];
13541354
char wal_segment[MAXFNAMELEN];
1355+
bool file_exists = false;
13551356
uint32 try_count = 0,
13561357
timeout;
13571358

1359+
#ifdef HAVE_LIBZ
1360+
char gz_wal_segment_path[MAXPGPATH];
1361+
#endif
1362+
13581363
tli = get_current_timeline(false);
13591364

13601365
/* Compute the name of the WAL file containig requested LSN */
@@ -1367,14 +1372,14 @@ wait_wal_lsn(XLogRecPtr lsn, bool wait_prev_segment)
13671372
{
13681373
pgBackupGetPath2(&current, wal_dir, lengthof(wal_dir),
13691374
DATABASE_DIR, PG_XLOG_DIR);
1370-
join_path_components(wal_segment_full_path, wal_dir, wal_segment);
1375+
join_path_components(wal_segment_path, wal_dir, wal_segment);
13711376

13721377
timeout = (uint32) checkpoint_timeout();
13731378
timeout = timeout + timeout * 0.1;
13741379
}
13751380
else
13761381
{
1377-
join_path_components(wal_segment_full_path, arclog_path, wal_segment);
1382+
join_path_components(wal_segment_path, arclog_path, wal_segment);
13781383
timeout = archive_timeout;
13791384
}
13801385

@@ -1383,14 +1388,33 @@ wait_wal_lsn(XLogRecPtr lsn, bool wait_prev_segment)
13831388
else
13841389
elog(LOG, "Looking for LSN: %X/%X in segment: %s", (uint32) (lsn >> 32), (uint32) lsn, wal_segment);
13851390

1391+
#ifdef HAVE_LIBZ
1392+
snprintf(gz_wal_segment_path, sizeof(gz_wal_segment_path), "%s.gz",
1393+
wal_segment_path);
1394+
#endif
1395+
13861396
/* Wait until target LSN is archived or streamed */
13871397
while (true)
13881398
{
1389-
bool file_exists = fileExists(wal_segment_full_path);
1399+
if (!file_exists)
1400+
{
1401+
file_exists = fileExists(wal_segment_path);
1402+
1403+
/* Try to find compressed WAL file */
1404+
if (!file_exists)
1405+
{
1406+
#ifdef HAVE_LIBZ
1407+
file_exists = fileExists(gz_wal_segment_path);
1408+
if (file_exists)
1409+
elog(LOG, "Found compressed WAL segment: %s", wal_segment_path);
1410+
#endif
1411+
}
1412+
else
1413+
elog(LOG, "Found WAL segment: %s", wal_segment_path);
1414+
}
13901415

13911416
if (file_exists)
13921417
{
1393-
elog(LOG, "Found segment: %s", wal_segment);
13941418
/* Do not check LSN for previous WAL segment */
13951419
if (wait_prev_segment)
13961420
return;
@@ -1409,18 +1433,18 @@ wait_wal_lsn(XLogRecPtr lsn, bool wait_prev_segment)
14091433

14101434
sleep(1);
14111435
if (interrupted)
1412-
elog(ERROR, "interrupted during waiting for WAL archiving");
1436+
elog(ERROR, "Interrupted during waiting for WAL archiving");
14131437
try_count++;
14141438

14151439
/* Inform user if WAL segment is absent in first attempt */
14161440
if (try_count == 1)
14171441
{
14181442
if (wait_prev_segment)
1419-
elog(INFO, "wait for WAL segment %s to be archived",
1420-
wal_segment_full_path);
1443+
elog(INFO, "Wait for WAL segment %s to be archived",
1444+
wal_segment_path);
14211445
else
1422-
elog(INFO, "wait for LSN %X/%X in archived WAL segment %s",
1423-
(uint32) (lsn >> 32), (uint32) lsn, wal_segment_full_path);
1446+
elog(INFO, "Wait for LSN %X/%X in archived WAL segment %s",
1447+
(uint32) (lsn >> 32), (uint32) lsn, wal_segment_path);
14241448
}
14251449

14261450
if (timeout > 0 && try_count > timeout)
@@ -1432,7 +1456,7 @@ wait_wal_lsn(XLogRecPtr lsn, bool wait_prev_segment)
14321456
/* If WAL segment doesn't exist or we wait for previous segment */
14331457
else
14341458
elog(ERROR,
1435-
"switched WAL segment %s could not be archived in %d seconds",
1459+
"Switched WAL segment %s could not be archived in %d seconds",
14361460
wal_segment, timeout);
14371461
}
14381462
}

0 commit comments

Comments
 (0)