diff options
-rw-r--r-- | src/backend/access/transam/xlog.c | 45 | ||||
-rw-r--r-- | src/include/access/xlog_internal.h | 5 |
2 files changed, 35 insertions, 15 deletions
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index c5b7f7a98ce..379c6f11750 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.392 2010/04/12 09:52:29 heikki Exp $ + * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.393 2010/04/12 10:40:42 heikki Exp $ * *------------------------------------------------------------------------- */ @@ -546,6 +546,7 @@ static void ExecuteRecoveryCommand(char *command, char *commandName, bool failOnerror); static void PreallocXlogFiles(XLogRecPtr endptr); static void RemoveOldXlogFiles(uint32 log, uint32 seg, XLogRecPtr endptr); +static void UpdateLastRemovedPtr(char *filename); static void ValidateXLOGDirectoryStructure(void); static void CleanupBackupHistory(void); static void UpdateMinRecoveryPoint(XLogRecPtr lsn, bool force); @@ -3169,6 +3170,31 @@ XLogGetLastRemoved(uint32 *log, uint32 *seg) } /* + * Update the last removed log/seg pointer in shared memory, to reflect + * that the given XLOG file has been removed. + */ +static void +UpdateLastRemovedPtr(char *filename) +{ + /* use volatile pointer to prevent code rearrangement */ + volatile XLogCtlData *xlogctl = XLogCtl; + uint32 tli, + log, + seg; + + XLogFromFileName(filename, &tli, &log, &seg); + + SpinLockAcquire(&xlogctl->info_lck); + if (log > xlogctl->lastRemovedLog || + (log == xlogctl->lastRemovedLog && seg > xlogctl->lastRemovedSeg)) + { + xlogctl->lastRemovedLog = log; + xlogctl->lastRemovedSeg = seg; + } + SpinLockRelease(&xlogctl->info_lck); +} + +/* * Recycle or remove all log files older or equal to passed log/seg# * * endptr is current (or recent) end of xlog; this is used to determine @@ -3189,20 +3215,8 @@ RemoveOldXlogFiles(uint32 log, uint32 seg, XLogRecPtr endptr) char newpath[MAXPGPATH]; #endif struct stat statbuf; - /* use volatile pointer to prevent code rearrangement */ - volatile XLogCtlData *xlogctl = XLogCtl; - /* Update the last removed location in shared memory first */ - SpinLockAcquire(&xlogctl->info_lck); - if (log > xlogctl->lastRemovedLog || - (log == xlogctl->lastRemovedLog && seg > xlogctl->lastRemovedSeg)) - { - xlogctl->lastRemovedLog = log; - xlogctl->lastRemovedSeg = seg; - } - SpinLockRelease(&xlogctl->info_lck); - - elog(DEBUG1, "removing WAL segments older than %X/%X", log, seg); + elog(DEBUG2, "removing WAL segments older than %X/%X", log, seg); /* * Initialize info about where to try to recycle to. We allow recycling @@ -3252,6 +3266,9 @@ RemoveOldXlogFiles(uint32 log, uint32 seg, XLogRecPtr endptr) { snprintf(path, MAXPGPATH, XLOGDIR "/%s", xlde->d_name); + /* Update the last removed location in shared memory first */ + UpdateLastRemovedPtr(xlde->d_name); + /* * Before deleting the file, see if it can be recycled as a * future log segment. Only recycle normal files, pg_standby diff --git a/src/include/access/xlog_internal.h b/src/include/access/xlog_internal.h index c93e3848e87..fa21f0a916a 100644 --- a/src/include/access/xlog_internal.h +++ b/src/include/access/xlog_internal.h @@ -11,7 +11,7 @@ * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/access/xlog_internal.h,v 1.31 2010/03/28 09:27:02 sriggs Exp $ + * $PostgreSQL: pgsql/src/include/access/xlog_internal.h,v 1.32 2010/04/12 10:40:43 heikki Exp $ */ #ifndef XLOG_INTERNAL_H #define XLOG_INTERNAL_H @@ -216,6 +216,9 @@ typedef XLogLongPageHeaderData *XLogLongPageHeader; #define XLogFileName(fname, tli, log, seg) \ snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli, log, seg) +#define XLogFromFileName(fname, tli, log, seg) \ + sscanf(fname, "%08X%08X%08X", tli, log, seg) + #define XLogFilePath(path, tli, log, seg) \ snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X", tli, log, seg) |