Skip to content

Commit 4457529

Browse files
committed
Merge branch 'pgpro-1184'
2 parents c6c8d93 + c9d11c5 commit 4457529

File tree

8 files changed

+543
-146
lines changed

8 files changed

+543
-146
lines changed

src/archive.c

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,27 @@
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
25-
do_archive_push(char *wal_file_path, char *wal_file_name)
25+
do_archive_push(char *wal_file_path, char *wal_file_name, bool overwrite)
2626
{
2727
char backup_wal_file_path[MAXPGPATH];
2828
char absolute_wal_file_path[MAXPGPATH];
2929
char current_dir[MAXPGPATH];
3030
int64 system_id;
3131
pgBackupConfig *config;
32+
bool is_compress = false;
3233

3334
if (wal_file_name == NULL && wal_file_path == NULL)
34-
elog(ERROR, "required parameters are not specified: --wal_file_name %%f --wal_file_path %%p");
35+
elog(ERROR, "required parameters are not specified: --wal-file-name %%f --wal-file-path %%p");
3536

3637
if (wal_file_name == NULL)
37-
elog(ERROR, "required parameter not specified: --wal_file_name %%f");
38+
elog(ERROR, "required parameter not specified: --wal-file-name %%f");
3839

3940
if (wal_file_path == NULL)
40-
elog(ERROR, "required parameter not specified: --wal_file_path %%p");
41+
elog(ERROR, "required parameter not specified: --wal-file-path %%p");
4142

4243
if (!getcwd(current_dir, sizeof(current_dir)))
4344
elog(ERROR, "getcwd() error");
@@ -61,10 +62,16 @@ do_archive_push(char *wal_file_path, char *wal_file_name)
6162
join_path_components(backup_wal_file_path, arclog_path, wal_file_name);
6263

6364
elog(INFO, "pg_probackup archive-push from %s to %s", absolute_wal_file_path, backup_wal_file_path);
64-
if (access(backup_wal_file_path, F_OK) != -1)
65-
elog(ERROR, "file '%s', already exists.", backup_wal_file_path);
6665

67-
copy_wal_file(absolute_wal_file_path, backup_wal_file_path);
66+
#ifdef HAVE_LIBZ
67+
if (compress_alg == PGLZ_COMPRESS)
68+
elog(ERROR, "pglz compression is not supported");
69+
if (compress_alg == ZLIB_COMPRESS)
70+
is_compress = IsXLogFileName(wal_file_name);
71+
#endif
72+
73+
push_wal_file(absolute_wal_file_path, backup_wal_file_path, is_compress,
74+
overwrite);
6875
elog(INFO, "pg_probackup archive-push completed successfully");
6976

7077
return 0;
@@ -82,22 +89,23 @@ do_archive_get(char *wal_file_path, char *wal_file_name)
8289
char current_dir[MAXPGPATH];
8390

8491
if (wal_file_name == NULL && wal_file_path == NULL)
85-
elog(ERROR, "required parameters are not specified: --wal_file_name %%f --wal_file_path %%p");
92+
elog(ERROR, "required parameters are not specified: --wal-file-name %%f --wal-file-path %%p");
8693

8794
if (wal_file_name == NULL)
88-
elog(ERROR, "required parameter not specified: --wal_file_name %%f");
95+
elog(ERROR, "required parameter not specified: --wal-file-name %%f");
8996

9097
if (wal_file_path == NULL)
91-
elog(ERROR, "required parameter not specified: --wal_file_path %%p");
98+
elog(ERROR, "required parameter not specified: --wal-file-path %%p");
9299

93100
if (!getcwd(current_dir, sizeof(current_dir)))
94101
elog(ERROR, "getcwd() error");
95102

96103
join_path_components(absolute_wal_file_path, current_dir, wal_file_path);
97104
join_path_components(backup_wal_file_path, arclog_path, wal_file_name);
98105

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);
106+
elog(INFO, "pg_probackup archive-get from %s to %s",
107+
backup_wal_file_path, absolute_wal_file_path);
108+
get_wal_file(backup_wal_file_path, absolute_wal_file_path);
101109
elog(INFO, "pg_probackup archive-get completed successfully");
102110

103111
return 0;

src/backup.c

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,11 +1314,16 @@ wait_wal_lsn(XLogRecPtr lsn, bool wait_prev_segment)
13141314
TimeLineID tli;
13151315
XLogSegNo targetSegNo;
13161316
char wal_dir[MAXPGPATH],
1317-
wal_segment_full_path[MAXPGPATH];
1317+
wal_segment_path[MAXPGPATH];
13181318
char wal_segment[MAXFNAMELEN];
1319+
bool file_exists = false;
13191320
uint32 try_count = 0,
13201321
timeout;
13211322

1323+
#ifdef HAVE_LIBZ
1324+
char gz_wal_segment_path[MAXPGPATH];
1325+
#endif
1326+
13221327
tli = get_current_timeline(false);
13231328

13241329
/* Compute the name of the WAL file containig requested LSN */
@@ -1331,14 +1336,14 @@ wait_wal_lsn(XLogRecPtr lsn, bool wait_prev_segment)
13311336
{
13321337
pgBackupGetPath2(&current, wal_dir, lengthof(wal_dir),
13331338
DATABASE_DIR, PG_XLOG_DIR);
1334-
join_path_components(wal_segment_full_path, wal_dir, wal_segment);
1339+
join_path_components(wal_segment_path, wal_dir, wal_segment);
13351340

13361341
timeout = (uint32) checkpoint_timeout();
13371342
timeout = timeout + timeout * 0.1;
13381343
}
13391344
else
13401345
{
1341-
join_path_components(wal_segment_full_path, arclog_path, wal_segment);
1346+
join_path_components(wal_segment_path, arclog_path, wal_segment);
13421347
timeout = archive_timeout;
13431348
}
13441349

@@ -1347,14 +1352,33 @@ wait_wal_lsn(XLogRecPtr lsn, bool wait_prev_segment)
13471352
else
13481353
elog(LOG, "Looking for LSN: %X/%X in segment: %s", (uint32) (lsn >> 32), (uint32) lsn, wal_segment);
13491354

1355+
#ifdef HAVE_LIBZ
1356+
snprintf(gz_wal_segment_path, sizeof(gz_wal_segment_path), "%s.gz",
1357+
wal_segment_path);
1358+
#endif
1359+
13501360
/* Wait until target LSN is archived or streamed */
13511361
while (true)
13521362
{
1353-
bool file_exists = fileExists(wal_segment_full_path);
1363+
if (!file_exists)
1364+
{
1365+
file_exists = fileExists(wal_segment_path);
1366+
1367+
/* Try to find compressed WAL file */
1368+
if (!file_exists)
1369+
{
1370+
#ifdef HAVE_LIBZ
1371+
file_exists = fileExists(gz_wal_segment_path);
1372+
if (file_exists)
1373+
elog(LOG, "Found compressed WAL segment: %s", wal_segment_path);
1374+
#endif
1375+
}
1376+
else
1377+
elog(LOG, "Found WAL segment: %s", wal_segment_path);
1378+
}
13541379

13551380
if (file_exists)
13561381
{
1357-
elog(LOG, "Found segment: %s", wal_segment);
13581382
/* Do not check LSN for previous WAL segment */
13591383
if (wait_prev_segment)
13601384
return;
@@ -1373,18 +1397,18 @@ wait_wal_lsn(XLogRecPtr lsn, bool wait_prev_segment)
13731397

13741398
sleep(1);
13751399
if (interrupted)
1376-
elog(ERROR, "interrupted during waiting for WAL archiving");
1400+
elog(ERROR, "Interrupted during waiting for WAL archiving");
13771401
try_count++;
13781402

13791403
/* Inform user if WAL segment is absent in first attempt */
13801404
if (try_count == 1)
13811405
{
13821406
if (wait_prev_segment)
1383-
elog(INFO, "wait for WAL segment %s to be archived",
1384-
wal_segment_full_path);
1407+
elog(INFO, "Wait for WAL segment %s to be archived",
1408+
wal_segment_path);
13851409
else
1386-
elog(INFO, "wait for LSN %X/%X in archived WAL segment %s",
1387-
(uint32) (lsn >> 32), (uint32) lsn, wal_segment_full_path);
1410+
elog(INFO, "Wait for LSN %X/%X in archived WAL segment %s",
1411+
(uint32) (lsn >> 32), (uint32) lsn, wal_segment_path);
13881412
}
13891413

13901414
if (timeout > 0 && try_count > timeout)
@@ -1396,7 +1420,7 @@ wait_wal_lsn(XLogRecPtr lsn, bool wait_prev_segment)
13961420
/* If WAL segment doesn't exist or we wait for previous segment */
13971421
else
13981422
elog(ERROR,
1399-
"switched WAL segment %s could not be archived in %d seconds",
1423+
"Switched WAL segment %s could not be archived in %d seconds",
14001424
wal_segment, timeout);
14011425
}
14021426
}
@@ -1807,22 +1831,6 @@ checkpoint_timeout(void)
18071831
return val_int;
18081832
}
18091833

1810-
/*
1811-
* Return true if the path is a existing regular file.
1812-
*/
1813-
bool
1814-
fileExists(const char *path)
1815-
{
1816-
struct stat buf;
1817-
1818-
if (stat(path, &buf) == -1 && errno == ENOENT)
1819-
return false;
1820-
else if (!S_ISREG(buf.st_mode))
1821-
return false;
1822-
else
1823-
return true;
1824-
}
1825-
18261834
/*
18271835
* Notify end of backup to server when "backup_label" is in the root directory
18281836
* of the DB cluster.

0 commit comments

Comments
 (0)