Skip to content

Commit 3347226

Browse files
committed
[Issue #177] treat files with '.gz.partial', '.part' and '.gz.part' siffixes as WAL segments
1 parent aa27b53 commit 3347226

File tree

3 files changed

+49
-8
lines changed

3 files changed

+49
-8
lines changed

src/catalog.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,8 @@ pgBackupCreateDir(pgBackup *backup)
853853
}
854854

855855
/*
856-
* Create list of timelines
856+
* Create list of timelines.
857+
* TODO: '.partial' and '.part' segno information should be added to tlinfo.
857858
*/
858859
parray *
859860
catalog_get_timelines(InstanceConfig *instance)
@@ -933,7 +934,8 @@ catalog_get_timelines(InstanceConfig *instance)
933934
continue;
934935
}
935936
/* partial WAL segment */
936-
else if (IsPartialXLogFileName(file->name))
937+
else if (IsPartialXLogFileName(file->name) ||
938+
IsPartialCompressXLogFileName(file->name))
937939
{
938940
elog(VERBOSE, "partial WAL file \"%s\"", file->name);
939941

@@ -952,6 +954,27 @@ catalog_get_timelines(InstanceConfig *instance)
952954
parray_append(tlinfo->xlog_filelist, wal_file);
953955
continue;
954956
}
957+
/* temp WAL segment */
958+
else if (IsTempXLogFileName(file->name) ||
959+
IsTempCompressXLogFileName(file->name))
960+
{
961+
elog(VERBOSE, "temp WAL file \"%s\"", file->name);
962+
963+
if (!tlinfo || tlinfo->tli != tli)
964+
{
965+
tlinfo = timelineInfoNew(tli);
966+
parray_append(timelineinfos, tlinfo);
967+
}
968+
969+
/* append file to xlog file list */
970+
wal_file = palloc(sizeof(xlogFile));
971+
wal_file->file = *file;
972+
wal_file->segno = segno;
973+
wal_file->type = TEMP_SEGMENT;
974+
wal_file->keep = false;
975+
parray_append(tlinfo->xlog_filelist, wal_file);
976+
continue;
977+
}
955978
/* we only expect compressed wal files with .gz suffix */
956979
else if (strcmp(suffix, "gz") != 0)
957980
{

src/delete.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,8 @@ delete_walfiles_in_tli(XLogRecPtr keep_lsn, timelineInfo *tlinfo,
942942
{
943943
if (wal_file->type == SEGMENT)
944944
elog(VERBOSE, "Removed WAL segment \"%s\"", wal_file->file.path);
945+
else if (wal_file->type == TEMP_SEGMENT)
946+
elog(VERBOSE, "Removed temp WAL segment \"%s\"", wal_file->file.path);
945947
else if (wal_file->type == PARTIAL_SEGMENT)
946948
elog(VERBOSE, "Removed partial WAL segment \"%s\"", wal_file->file.path);
947949
else if (wal_file->type == BACKUP_HISTORY_FILE)

src/pg_probackup.h

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ extern const char *PROGRAM_URL;
4646
extern const char *PROGRAM_EMAIL;
4747

4848
/* Directory/File names */
49-
#define DATABASE_DIR "database"
49+
#define DATABASE_DIR "database"
5050
#define BACKUPS_DIR "backups"
5151
#if PG_VERSION_NUM >= 100000
5252
#define PG_XLOG_DIR "pg_wal"
@@ -90,6 +90,7 @@ extern const char *PROGRAM_EMAIL;
9090
/* retry attempts */
9191
#define PAGE_READ_ATTEMPTS 100
9292

93+
/* max size of note, that can be added to backup */
9394
#define MAX_NOTE_SIZE 1024
9495

9596
/* Check if an XLogRecPtr value is pointed to 0 offset */
@@ -514,18 +515,18 @@ typedef struct lsnInterval
514515
typedef enum xlogFileType
515516
{
516517
SEGMENT,
518+
TEMP_SEGMENT,
517519
PARTIAL_SEGMENT,
518520
BACKUP_HISTORY_FILE
519521
} xlogFileType;
520522

521523
typedef struct xlogFile
522524
{
523-
pgFile file;
524-
XLogSegNo segno;
525+
pgFile file;
526+
XLogSegNo segno;
525527
xlogFileType type;
526-
bool keep; /* Used to prevent removal of WAL segments
527-
* required by ARCHIVE backups.
528-
*/
528+
bool keep; /* Used to prevent removal of WAL segments
529+
* required by ARCHIVE backups. */
529530
} xlogFile;
530531

531532

@@ -607,6 +608,21 @@ typedef struct BackupPageHeader
607608
XLogFromFileName(fname, tli, logSegNo)
608609
#endif
609610

611+
#define IsPartialCompressXLogFileName(fname) \
612+
(strlen(fname) == XLOG_FNAME_LEN + strlen(".gz.partial") && \
613+
strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN && \
614+
strcmp((fname) + XLOG_FNAME_LEN, ".gz.partial") == 0)
615+
616+
#define IsTempXLogFileName(fname) \
617+
(strlen(fname) == XLOG_FNAME_LEN + strlen(".part") && \
618+
strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN && \
619+
strcmp((fname) + XLOG_FNAME_LEN, ".part") == 0)
620+
621+
#define IsTempCompressXLogFileName(fname) \
622+
(strlen(fname) == XLOG_FNAME_LEN + strlen(".gz.part") && \
623+
strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN && \
624+
strcmp((fname) + XLOG_FNAME_LEN, ".gz.part") == 0)
625+
610626
#define IsSshProtocol() (instance_config.remote.host && strcmp(instance_config.remote.proto, "ssh") == 0)
611627

612628
/* directory options */

0 commit comments

Comments
 (0)