Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 90897a5

Browse files
committed
Check segment file for start backup (testing archive_command).
1 parent b127345 commit 90897a5

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

backup.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ static void create_file_list(parray *files,
8080
const char *prefix,
8181
bool is_append);
8282
static void wait_for_archive(PGconn *conn, pgBackup *backup, const char *sql, bool stop_backup);
83+
static void wait_archive_lsn(XLogRecPtr lsn, bool last_segno);
8384
static void make_pagemap_from_ptrack(parray *files);
8485
static void StreamLog(void *arg);
8586

@@ -651,7 +652,12 @@ pg_start_backup(const char *label, bool smooth, pgBackup *backup)
651652
ERROR);
652653

653654
if (backup != NULL)
655+
{
654656
get_lsn(start_stop_connect, res, &backup->start_lsn, false);
657+
if (!stream_wal && !from_replica)
658+
wait_archive_lsn(backup->start_lsn, true);
659+
}
660+
655661
PQclear(res);
656662
}
657663

@@ -842,6 +848,42 @@ wait_for_archive(PGconn *conn, pgBackup *backup, const char *sql, bool stop_back
842848
elog(LOG, "%s() .ready deleted in %d try", __FUNCTION__, try_count);
843849
}
844850

851+
static void
852+
wait_archive_lsn(XLogRecPtr lsn, bool last_segno)
853+
{
854+
TimeLineID tli;
855+
XLogSegNo targetSegNo;
856+
char ready_path[MAXPGPATH];
857+
char file_name[MAXFNAMELEN];
858+
int try_count;
859+
860+
tli = get_current_timeline(false);
861+
862+
/* As well as WAL file name */
863+
XLByteToSeg(lsn, targetSegNo);
864+
if (last_segno)
865+
targetSegNo--;
866+
XLogFileName(file_name, tli, targetSegNo);
867+
868+
snprintf(ready_path, lengthof(ready_path),
869+
"%s/%s", arclog_path, file_name);
870+
elog(LOG, "%s() wait for lsn:%li %s", __FUNCTION__, lsn, ready_path);
871+
/* wait until switched WAL is archived */
872+
try_count = 0;
873+
while (!fileExists(ready_path))
874+
{
875+
sleep(1);
876+
if (interrupted)
877+
elog(ERROR,
878+
"interrupted during waiting for WAL archiving");
879+
try_count++;
880+
if (try_count > TIMEOUT_ARCHIVE)
881+
elog(ERROR,
882+
"switched WAL could not be archived in %d seconds",
883+
TIMEOUT_ARCHIVE);
884+
}
885+
}
886+
845887
/*
846888
* Notify end of backup to PostgreSQL server.
847889
*/

0 commit comments

Comments
 (0)