diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2010-03-18 09:18:54 +0000 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2010-03-18 09:18:54 +0000 |
commit | 9c563b6fd0f08fa140459cc825e365514f2dcc2d (patch) | |
tree | 01a8f6040c267737035e86f5907afa2e2ddfc288 | |
parent | c487a9540cb13c344e1830beb3b149308725171f (diff) | |
download | postgresql-9c563b6fd0f08fa140459cc825e365514f2dcc2d.tar.gz postgresql-9c563b6fd0f08fa140459cc825e365514f2dcc2d.zip |
Fix bug in %r handling in recovery_end_command, it always came out as 0
because InRedo was cleared before recovery_end_command was executed.
Also, always take ControlFileLock when reading checkpoint location for
%r. That didn't matter before, but in 8.4 bgwriter is active during
recovery and can modify the control file concurrently.
-rw-r--r-- | src/backend/access/transam/xlog.c | 32 |
1 files changed, 10 insertions, 22 deletions
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index d7aea24382d..43742370e8a 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.345.2.7 2010/02/19 01:04:39 itagaki Exp $ + * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.345.2.8 2010/03/18 09:18:54 heikki Exp $ * *------------------------------------------------------------------------- */ @@ -2711,11 +2711,13 @@ RestoreArchivedFile(char *path, const char *xlogfname, */ if (InRedo) { + LWLockAcquire(ControlFileLock, LW_SHARED); XLByteToSeg(ControlFile->checkPointCopy.redo, restartLog, restartSeg); XLogFileName(lastRestartPointFname, ControlFile->checkPointCopy.ThisTimeLineID, restartLog, restartSeg); + LWLockRelease(ControlFileLock); /* we shouldn't need anything earlier than last restart point */ Assert(strcmp(lastRestartPointFname, xlogfname) <= 0); } @@ -2905,28 +2907,14 @@ ExecuteRecoveryEndCommand(void) * Calculate the archive file cutoff point for use during log shipping * replication. All files earlier than this point can be deleted from the * archive, though there is no requirement to do so. - * - * We initialise this with the filename of an InvalidXLogRecPtr, which - * will prevent the deletion of any WAL files from the archive because of - * the alphabetic sorting property of WAL filenames. - * - * Once we have successfully located the redo pointer of the checkpoint - * from which we start recovery we never request a file prior to the redo - * pointer of the last restartpoint. When redo begins we know that we have - * successfully located it, so there is no need for additional status - * flags to signify the point when we can begin deleting WAL files from - * the archive. */ - if (InRedo) - { - XLByteToSeg(ControlFile->checkPointCopy.redo, - restartLog, restartSeg); - XLogFileName(lastRestartPointFname, - ControlFile->checkPointCopy.ThisTimeLineID, - restartLog, restartSeg); - } - else - XLogFileName(lastRestartPointFname, 0, 0, 0); + LWLockAcquire(ControlFileLock, LW_SHARED); + XLByteToSeg(ControlFile->checkPointCopy.redo, + restartLog, restartSeg); + XLogFileName(lastRestartPointFname, + ControlFile->checkPointCopy.ThisTimeLineID, + restartLog, restartSeg); + LWLockRelease(ControlFileLock); /* * construct the command to be executed |