Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3055656

Browse files
committed
Update the location of last removed WAL segment in shared memory only
after actually removing one, so that if we can't remove segments becauseWAL archiving is lagging behind, we don't unnecessarily forbid streamingthe old not-yet-archived segments that are still perfectly valid. Persuggestion from Fujii Masao.
1 parent258174b commit3055656

File tree

2 files changed

+35
-15
lines changed

2 files changed

+35
-15
lines changed

‎src/backend/access/transam/xlog.c

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
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,
546546
boolfailOnerror);
547547
staticvoidPreallocXlogFiles(XLogRecPtrendptr);
548548
staticvoidRemoveOldXlogFiles(uint32log,uint32seg,XLogRecPtrendptr);
549+
staticvoidUpdateLastRemovedPtr(char*filename);
549550
staticvoidValidateXLOGDirectoryStructure(void);
550551
staticvoidCleanupBackupHistory(void);
551552
staticvoidUpdateMinRecoveryPoint(XLogRecPtrlsn,boolforce);
@@ -3168,6 +3169,31 @@ XLogGetLastRemoved(uint32 *log, uint32 *seg)
31683169
SpinLockRelease(&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+
staticvoid
3177+
UpdateLastRemovedPtr(char*filename)
3178+
{
3179+
/* use volatile pointer to prevent code rearrangement */
3180+
volatileXLogCtlData*xlogctl=XLogCtl;
3181+
uint32tli,
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)
31893215
charnewpath[MAXPGPATH];
31903216
#endif
31913217
structstatstatbuf;
3192-
/* use volatile pointer to prevent code rearrangement */
3193-
volatileXLogCtlData*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
{
32533267
snprintf(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

‎src/include/access/xlog_internal.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
1212
* Portions Copyright (c) 1994, Regents of the University of California
1313
*
14-
* $PostgreSQL: pgsql/src/include/access/xlog_internal.h,v 1.31 2010/03/28 09:27:02 sriggs Exp $
14+
* $PostgreSQL: pgsql/src/include/access/xlog_internal.h,v 1.32 2010/04/12 10:40:43 heikki Exp $
1515
*/
1616
#ifndefXLOG_INTERNAL_H
1717
#defineXLOG_INTERNAL_H
@@ -216,6 +216,9 @@ typedef XLogLongPageHeaderData *XLogLongPageHeader;
216216
#defineXLogFileName(fname,tli,log,seg)\
217217
snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli, log, seg)
218218

219+
#defineXLogFromFileName(fname,tli,log,seg)\
220+
sscanf(fname, "%08X%08X%08X", tli, log, seg)
221+
219222
#defineXLogFilePath(path,tli,log,seg)\
220223
snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X", tli, log, seg)
221224

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp