Commit c7371c4a authored by Fujii Masao's avatar Fujii Masao

Prevent the already-archived WAL file from being archived again.

Previously the archive recovery always created .ready file for
the last WAL file of the old timeline at the end of recovery even when
it's restored from the archive and has .done file. That is, there was
the case where the WAL file had both .ready and .done files.
This caused the already-archived WAL file to be archived again.

This commit prevents the archive recovery from creating .ready file
for the last WAL file if it has .done file, in order to prevent it from
being archived again.

This bug was added when cascading replication feature was introduced,
i.e., the commit 52861058.
So, back-patch to 9.2, where cascading replication was added.

Reviewed by Michael Paquier
parent e64d3c56
...@@ -5323,7 +5323,7 @@ static void ...@@ -5323,7 +5323,7 @@ static void
exitArchiveRecovery(TimeLineID endTLI, XLogSegNo endLogSegNo) exitArchiveRecovery(TimeLineID endTLI, XLogSegNo endLogSegNo)
{ {
char recoveryPath[MAXPGPATH]; char recoveryPath[MAXPGPATH];
char xlogpath[MAXPGPATH]; char xlogfname[MAXFNAMELEN];
/* /*
* We are no longer in archive recovery state. * We are no longer in archive recovery state.
...@@ -5351,17 +5351,19 @@ exitArchiveRecovery(TimeLineID endTLI, XLogSegNo endLogSegNo) ...@@ -5351,17 +5351,19 @@ exitArchiveRecovery(TimeLineID endTLI, XLogSegNo endLogSegNo)
* for the new timeline. * for the new timeline.
* *
* Notify the archiver that the last WAL segment of the old timeline is * Notify the archiver that the last WAL segment of the old timeline is
* ready to copy to archival storage. Otherwise, it is not archived for a * ready to copy to archival storage if its .done file doesn't exist
* while. * (e.g., if it's the restored WAL file, it's expected to have .done file).
* Otherwise, it is not archived for a while.
*/ */
if (endTLI != ThisTimeLineID) if (endTLI != ThisTimeLineID)
{ {
XLogFileCopy(endLogSegNo, endTLI, endLogSegNo); XLogFileCopy(endLogSegNo, endTLI, endLogSegNo);
/* Create .ready file only when neither .ready nor .done files exist */
if (XLogArchivingActive()) if (XLogArchivingActive())
{ {
XLogFileName(xlogpath, endTLI, endLogSegNo); XLogFileName(xlogfname, endTLI, endLogSegNo);
XLogArchiveNotify(xlogpath); XLogArchiveCheckDone(xlogfname);
} }
} }
...@@ -5369,8 +5371,8 @@ exitArchiveRecovery(TimeLineID endTLI, XLogSegNo endLogSegNo) ...@@ -5369,8 +5371,8 @@ exitArchiveRecovery(TimeLineID endTLI, XLogSegNo endLogSegNo)
* Let's just make real sure there are not .ready or .done flags posted * Let's just make real sure there are not .ready or .done flags posted
* for the new segment. * for the new segment.
*/ */
XLogFileName(xlogpath, ThisTimeLineID, endLogSegNo); XLogFileName(xlogfname, ThisTimeLineID, endLogSegNo);
XLogArchiveCleanup(xlogpath); XLogArchiveCleanup(xlogfname);
/* /*
* Since there might be a partial WAL segment named RECOVERYXLOG, get rid * Since there might be a partial WAL segment named RECOVERYXLOG, get rid
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment