77 * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
88 * Portions Copyright (c) 1994, Regents of the University of California
99 *
10- * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.392 2010/04/1209:52:29 heikki Exp $
10+ * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.393 2010/04/1210:40:42 heikki Exp $
1111 *
1212 *-------------------------------------------------------------------------
1313 */
@@ -546,6 +546,7 @@ static void ExecuteRecoveryCommand(char *command, char *commandName,
546546bool failOnerror );
547547static void PreallocXlogFiles (XLogRecPtr endptr );
548548static void RemoveOldXlogFiles (uint32 log ,uint32 seg ,XLogRecPtr endptr );
549+ static void UpdateLastRemovedPtr (char * filename );
549550static void ValidateXLOGDirectoryStructure (void );
550551static void CleanupBackupHistory (void );
551552static void UpdateMinRecoveryPoint (XLogRecPtr lsn ,bool force );
@@ -3168,6 +3169,31 @@ XLogGetLastRemoved(uint32 *log, uint32 *seg)
31683169SpinLockRelease (& xlogctl -> info_lck );
31693170}
31703171
3172+ /*
3173+ * Update the last removed log/seg pointer in shared memory, to reflect
3174+ * that the given XLOG file has been removed.
3175+ */
3176+ static void
3177+ UpdateLastRemovedPtr (char * filename )
3178+ {
3179+ /* use volatile pointer to prevent code rearrangement */
3180+ volatile XLogCtlData * xlogctl = XLogCtl ;
3181+ uint32 tli ,
3182+ log ,
3183+ seg ;
3184+
3185+ XLogFromFileName (filename ,& tli ,& log ,& seg );
3186+
3187+ SpinLockAcquire (& xlogctl -> info_lck );
3188+ if (log > xlogctl -> lastRemovedLog ||
3189+ (log == xlogctl -> lastRemovedLog && seg > xlogctl -> lastRemovedSeg ))
3190+ {
3191+ xlogctl -> lastRemovedLog = log ;
3192+ xlogctl -> lastRemovedSeg = seg ;
3193+ }
3194+ SpinLockRelease (& xlogctl -> info_lck );
3195+ }
3196+
31713197/*
31723198 * Recycle or remove all log files older or equal to passed log/seg#
31733199 *
@@ -3189,20 +3215,8 @@ RemoveOldXlogFiles(uint32 log, uint32 seg, XLogRecPtr endptr)
31893215char newpath [MAXPGPATH ];
31903216#endif
31913217struct stat statbuf ;
3192- /* use volatile pointer to prevent code rearrangement */
3193- volatile XLogCtlData * xlogctl = XLogCtl ;
31943218
3195- /* Update the last removed location in shared memory first */
3196- SpinLockAcquire (& xlogctl -> info_lck );
3197- if (log > xlogctl -> lastRemovedLog ||
3198- (log == xlogctl -> lastRemovedLog && seg > xlogctl -> lastRemovedSeg ))
3199- {
3200- xlogctl -> lastRemovedLog = log ;
3201- xlogctl -> lastRemovedSeg = seg ;
3202- }
3203- SpinLockRelease (& xlogctl -> info_lck );
3204-
3205- elog (DEBUG1 ,"removing WAL segments older than %X/%X" ,log ,seg );
3219+ elog (DEBUG2 ,"removing WAL segments older than %X/%X" ,log ,seg );
32063220
32073221/*
32083222 * Initialize info about where to try to recycle to. We allow recycling
@@ -3252,6 +3266,9 @@ RemoveOldXlogFiles(uint32 log, uint32 seg, XLogRecPtr endptr)
32523266{
32533267snprintf (path ,MAXPGPATH ,XLOGDIR "/%s" ,xlde -> d_name );
32543268
3269+ /* Update the last removed location in shared memory first */
3270+ UpdateLastRemovedPtr (xlde -> d_name );
3271+
32553272/*
32563273 * Before deleting the file, see if it can be recycled as a
32573274 * future log segment. Only recycle normal files, pg_standby