Skip to content

Commit 114a575

Browse files
committed
Merge branch 'master' into fix_ptrack_1230
2 parents e0b3e89 + 00070a4 commit 114a575

25 files changed

+1478
-479
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 & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ static void pg_ptrack_clear(void);
109109
static bool pg_ptrack_support(void);
110110
static bool pg_ptrack_enable(void);
111111
static bool pg_is_in_recovery(void);
112-
static bool pg_archive_enabled(void);
113112
static bool pg_ptrack_get_and_clear_db(Oid dbOid, Oid tblspcOid);
114113
static char *pg_ptrack_get_and_clear(Oid tablespace_oid,
115114
Oid db_oid,
@@ -794,13 +793,6 @@ do_backup(time_t start_time)
794793
}
795794
}
796795

797-
/* archiving check */
798-
if (!current.stream && !pg_archive_enabled())
799-
elog(ERROR, "Archiving must be enabled for archive backup");
800-
801-
if (current.backup_mode == BACKUP_MODE_DIFF_PAGE && !pg_archive_enabled())
802-
elog(ERROR, "Archiving must be enabled for PAGE backup");
803-
804796
if (from_replica)
805797
{
806798
/* Check master connection options */
@@ -1119,34 +1111,6 @@ pg_is_in_recovery(void)
11191111
return false;
11201112
}
11211113

1122-
/*
1123-
* Check if archiving is enabled
1124-
*/
1125-
static bool
1126-
pg_archive_enabled(void)
1127-
{
1128-
PGresult *res_db;
1129-
1130-
res_db = pgut_execute(backup_conn, "show archive_mode", 0, NULL, true);
1131-
1132-
if (strcmp(PQgetvalue(res_db, 0, 0), "off") == 0)
1133-
{
1134-
PQclear(res_db);
1135-
return false;
1136-
}
1137-
PQclear(res_db);
1138-
1139-
res_db = pgut_execute(backup_conn, "show archive_command", 0, NULL, true);
1140-
if (strlen(PQgetvalue(res_db, 0, 0)) == 0)
1141-
{
1142-
PQclear(res_db);
1143-
return false;
1144-
}
1145-
PQclear(res_db);
1146-
1147-
return true;
1148-
}
1149-
11501114
/* Clear ptrack files in all databases of the instance we connected to */
11511115
static void
11521116
pg_ptrack_clear(void)
@@ -1350,11 +1314,16 @@ wait_wal_lsn(XLogRecPtr lsn, bool wait_prev_segment)
13501314
TimeLineID tli;
13511315
XLogSegNo targetSegNo;
13521316
char wal_dir[MAXPGPATH],
1353-
wal_segment_full_path[MAXPGPATH];
1317+
wal_segment_path[MAXPGPATH];
13541318
char wal_segment[MAXFNAMELEN];
1319+
bool file_exists = false;
13551320
uint32 try_count = 0,
13561321
timeout;
13571322

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

13601329
/* Compute the name of the WAL file containig requested LSN */
@@ -1367,14 +1336,14 @@ wait_wal_lsn(XLogRecPtr lsn, bool wait_prev_segment)
13671336
{
13681337
pgBackupGetPath2(&current, wal_dir, lengthof(wal_dir),
13691338
DATABASE_DIR, PG_XLOG_DIR);
1370-
join_path_components(wal_segment_full_path, wal_dir, wal_segment);
1339+
join_path_components(wal_segment_path, wal_dir, wal_segment);
13711340

13721341
timeout = (uint32) checkpoint_timeout();
13731342
timeout = timeout + timeout * 0.1;
13741343
}
13751344
else
13761345
{
1377-
join_path_components(wal_segment_full_path, arclog_path, wal_segment);
1346+
join_path_components(wal_segment_path, arclog_path, wal_segment);
13781347
timeout = archive_timeout;
13791348
}
13801349

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

1355+
#ifdef HAVE_LIBZ
1356+
snprintf(gz_wal_segment_path, sizeof(gz_wal_segment_path), "%s.gz",
1357+
wal_segment_path);
1358+
#endif
1359+
13861360
/* Wait until target LSN is archived or streamed */
13871361
while (true)
13881362
{
1389-
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+
}
13901379

13911380
if (file_exists)
13921381
{
1393-
elog(LOG, "Found segment: %s", wal_segment);
13941382
/* Do not check LSN for previous WAL segment */
13951383
if (wait_prev_segment)
13961384
return;
@@ -1409,18 +1397,18 @@ wait_wal_lsn(XLogRecPtr lsn, bool wait_prev_segment)
14091397

14101398
sleep(1);
14111399
if (interrupted)
1412-
elog(ERROR, "interrupted during waiting for WAL archiving");
1400+
elog(ERROR, "Interrupted during waiting for WAL archiving");
14131401
try_count++;
14141402

14151403
/* Inform user if WAL segment is absent in first attempt */
14161404
if (try_count == 1)
14171405
{
14181406
if (wait_prev_segment)
1419-
elog(INFO, "wait for WAL segment %s to be archived",
1420-
wal_segment_full_path);
1407+
elog(INFO, "Wait for WAL segment %s to be archived",
1408+
wal_segment_path);
14211409
else
1422-
elog(INFO, "wait for LSN %X/%X in archived WAL segment %s",
1423-
(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);
14241412
}
14251413

14261414
if (timeout > 0 && try_count > timeout)
@@ -1432,7 +1420,7 @@ wait_wal_lsn(XLogRecPtr lsn, bool wait_prev_segment)
14321420
/* If WAL segment doesn't exist or we wait for previous segment */
14331421
else
14341422
elog(ERROR,
1435-
"switched WAL segment %s could not be archived in %d seconds",
1423+
"Switched WAL segment %s could not be archived in %d seconds",
14361424
wal_segment, timeout);
14371425
}
14381426
}
@@ -1843,22 +1831,6 @@ checkpoint_timeout(void)
18431831
return val_int;
18441832
}
18451833

1846-
/*
1847-
* Return true if the path is a existing regular file.
1848-
*/
1849-
bool
1850-
fileExists(const char *path)
1851-
{
1852-
struct stat buf;
1853-
1854-
if (stat(path, &buf) == -1 && errno == ENOENT)
1855-
return false;
1856-
else if (!S_ISREG(buf.st_mode))
1857-
return false;
1858-
else
1859-
return true;
1860-
}
1861-
18621834
/*
18631835
* Notify end of backup to server when "backup_label" is in the root directory
18641836
* of the DB cluster.

0 commit comments

Comments
 (0)