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

Commitb2a667b

Browse files
committed
Add a new option to RestoreBkpBlocks() to indicate if a cleanup lock should
be used instead of the normal exclusive lock, and make WAL redo functionsresponsible for calling RestoreBkpBlocks(). They know better what kind of alock they need.At the moment, this just moves things around with no functional change, butmakes the hot standby patch that's under review cleaner.
1 parentb287f0a commitb2a667b

File tree

15 files changed

+95
-36
lines changed

15 files changed

+95
-36
lines changed

‎src/backend/access/gin/ginxlog.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/gin/ginxlog.c,v 1.16 2009/01/01 17:23:34 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/gin/ginxlog.c,v 1.17 2009/01/20 18:59:36 heikki Exp $
1212
*-------------------------------------------------------------------------
1313
*/
1414
#include"postgres.h"
@@ -438,6 +438,8 @@ gin_redo(XLogRecPtr lsn, XLogRecord *record)
438438
{
439439
uint8info=record->xl_info& ~XLR_INFO_MASK;
440440

441+
RestoreBkpBlocks(lsn,record, false);
442+
441443
topCtx=MemoryContextSwitchTo(opCtx);
442444
switch (info)
443445
{

‎src/backend/access/gist/gistxlog.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/gist/gistxlog.c,v 1.31 2009/01/01 17:23:35 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/gist/gistxlog.c,v 1.32 2009/01/20 18:59:36 heikki Exp $
1212
*-------------------------------------------------------------------------
1313
*/
1414
#include"postgres.h"
@@ -394,9 +394,10 @@ void
394394
gist_redo(XLogRecPtrlsn,XLogRecord*record)
395395
{
396396
uint8info=record->xl_info& ~XLR_INFO_MASK;
397-
398397
MemoryContextoldCxt;
399398

399+
RestoreBkpBlocks(lsn,record, false);
400+
400401
oldCxt=MemoryContextSwitchTo(opCtx);
401402
switch (info)
402403
{

‎src/backend/access/heap/heapam.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.273 2009/01/01 17:23:35 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.274 2009/01/20 18:59:36 heikki Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -4777,6 +4777,8 @@ heap_redo(XLogRecPtr lsn, XLogRecord *record)
47774777
{
47784778
uint8info=record->xl_info& ~XLR_INFO_MASK;
47794779

4780+
RestoreBkpBlocks(lsn,record, false);
4781+
47804782
switch (info&XLOG_HEAP_OPMASK)
47814783
{
47824784
caseXLOG_HEAP_INSERT:
@@ -4816,12 +4818,15 @@ heap2_redo(XLogRecPtr lsn, XLogRecord *record)
48164818
switch (info&XLOG_HEAP_OPMASK)
48174819
{
48184820
caseXLOG_HEAP2_FREEZE:
4821+
RestoreBkpBlocks(lsn,record, false);
48194822
heap_xlog_freeze(lsn,record);
48204823
break;
48214824
caseXLOG_HEAP2_CLEAN:
4825+
RestoreBkpBlocks(lsn,record, true);
48224826
heap_xlog_clean(lsn,record, false);
48234827
break;
48244828
caseXLOG_HEAP2_CLEAN_MOVE:
4829+
RestoreBkpBlocks(lsn,record, true);
48254830
heap_xlog_clean(lsn,record, true);
48264831
break;
48274832
default:

‎src/backend/access/nbtree/nbtxlog.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtxlog.c,v 1.53 2009/01/01 17:23:36 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtxlog.c,v 1.54 2009/01/20 18:59:37 heikki Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -714,6 +714,8 @@ btree_redo(XLogRecPtr lsn, XLogRecord *record)
714714
{
715715
uint8info=record->xl_info& ~XLR_INFO_MASK;
716716

717+
RestoreBkpBlocks(lsn,record, false);
718+
717719
switch (info)
718720
{
719721
caseXLOG_BTREE_INSERT_LEAF:

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
2727
* Portions Copyright (c) 1994, Regents of the University of California
2828
*
29-
* $PostgreSQL: pgsql/src/backend/access/transam/clog.c,v 1.51 2009/01/01 17:23:36 momjian Exp $
29+
* $PostgreSQL: pgsql/src/backend/access/transam/clog.c,v 1.52 2009/01/20 18:59:37 heikki Exp $
3030
*
3131
*-------------------------------------------------------------------------
3232
*/
@@ -684,6 +684,9 @@ clog_redo(XLogRecPtr lsn, XLogRecord *record)
684684
{
685685
uint8info=record->xl_info& ~XLR_INFO_MASK;
686686

687+
/* Backup blocks are not used in clog records */
688+
Assert(!(record->xl_info&XLR_BKP_BLOCK_MASK));
689+
687690
if (info==CLOG_ZEROPAGE)
688691
{
689692
intpageno;

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
4343
* Portions Copyright (c) 1994, Regents of the University of California
4444
*
45-
* $PostgreSQL: pgsql/src/backend/access/transam/multixact.c,v 1.29 2009/01/01 17:23:36 momjian Exp $
45+
* $PostgreSQL: pgsql/src/backend/access/transam/multixact.c,v 1.30 2009/01/20 18:59:37 heikki Exp $
4646
*
4747
*-------------------------------------------------------------------------
4848
*/
@@ -1870,6 +1870,9 @@ multixact_redo(XLogRecPtr lsn, XLogRecord *record)
18701870
{
18711871
uint8info=record->xl_info& ~XLR_INFO_MASK;
18721872

1873+
/* Backup blocks are not used in multixact records */
1874+
Assert(!(record->xl_info&XLR_BKP_BLOCK_MASK));
1875+
18731876
if (info==XLOG_MULTIXACT_ZERO_OFF_PAGE)
18741877
{
18751878
intpageno;

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.271 2009/01/01 17:23:36 momjian Exp $
13+
* $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.272 2009/01/20 18:59:37 heikki Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -4308,6 +4308,9 @@ xact_redo(XLogRecPtr lsn, XLogRecord *record)
43084308
{
43094309
uint8info=record->xl_info& ~XLR_INFO_MASK;
43104310

4311+
/* Backup blocks are not used in xact records */
4312+
Assert(!(record->xl_info&XLR_BKP_BLOCK_MASK));
4313+
43114314
if (info==XLOG_XACT_COMMIT)
43124315
{
43134316
xl_xact_commit*xlrec= (xl_xact_commit*)XLogRecGetData(record);

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2009, 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.327 2009/01/11 18:02:17 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.328 2009/01/20 18:59:37 heikki Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -2922,9 +2922,15 @@ CleanupBackupHistory(void)
29222922
* page might not be. This will force us to replay all subsequent
29232923
* modifications of the page that appear in XLOG, rather than possibly
29242924
* ignoring them as already applied, but that's not a huge drawback.
2925+
*
2926+
* If 'cleanup' is true, a cleanup lock is used when restoring blocks.
2927+
* Otherwise, a normal exclusive lock is used. At the moment, that's just
2928+
* pro forma, because there can't be any regular backends in the system
2929+
* during recovery. The 'cleanup' argument applies to all backup blocks
2930+
* in the WAL record, that suffices for now.
29252931
*/
2926-
staticvoid
2927-
RestoreBkpBlocks(XLogRecord*record,XLogRecPtrlsn)
2932+
void
2933+
RestoreBkpBlocks(XLogRecPtrlsn,XLogRecord*record,boolcleanup)
29282934
{
29292935
Bufferbuffer;
29302936
Pagepage;
@@ -2944,6 +2950,11 @@ RestoreBkpBlocks(XLogRecord *record, XLogRecPtr lsn)
29442950
buffer=XLogReadBufferExtended(bkpb.node,bkpb.fork,bkpb.block,
29452951
RBM_ZERO);
29462952
Assert(BufferIsValid(buffer));
2953+
if (cleanup)
2954+
LockBufferForCleanup(buffer);
2955+
else
2956+
LockBuffer(buffer,BUFFER_LOCK_EXCLUSIVE);
2957+
29472958
page= (Page)BufferGetPage(buffer);
29482959

29492960
if (bkpb.hole_length==0)
@@ -5199,9 +5210,6 @@ StartupXLOG(void)
51995210
TransactionIdAdvance(ShmemVariableCache->nextXid);
52005211
}
52015212

5202-
if (record->xl_info&XLR_BKP_BLOCK_MASK)
5203-
RestoreBkpBlocks(record,EndRecPtr);
5204-
52055213
RmgrTable[record->xl_rmid].rm_redo(EndRecPtr,record);
52065214

52075215
/* Pop the error context stack */
@@ -6233,6 +6241,9 @@ xlog_redo(XLogRecPtr lsn, XLogRecord *record)
62336241
{
62346242
uint8info=record->xl_info& ~XLR_INFO_MASK;
62356243

6244+
/* Backup blocks are not used in xlog records */
6245+
Assert(!(record->xl_info&XLR_BKP_BLOCK_MASK));
6246+
62366247
if (info==XLOG_NEXTOID)
62376248
{
62386249
OidnextOid;

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

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
1212
* Portions Copyright (c) 1994, Regents of the University of California
1313
*
14-
* $PostgreSQL: pgsql/src/backend/access/transam/xlogutils.c,v 1.66 2009/01/01 17:23:36 momjian Exp $
14+
* $PostgreSQL: pgsql/src/backend/access/transam/xlogutils.c,v 1.67 2009/01/20 18:59:37 heikki Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -217,31 +217,41 @@ XLogCheckInvalidPages(void)
217217

218218
/*
219219
* XLogReadBuffer
220-
*A shorthand of XLogReadBufferExtended(), for reading from the main
221-
*fork.
220+
*Read a page during XLOG replay.
221+
*
222+
* This is a shorthand of XLogReadBufferExtended() followed by
223+
* LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE), for reading from the main
224+
* fork.
225+
*
226+
* (Getting the lock is not really necessary, since we expect that this is
227+
* only used during single-process XLOG replay, but some subroutines such
228+
* as MarkBufferDirty will complain if we don't. And hopefully we'll get
229+
* hot standby support in the future, where there will be backends running
230+
* read-only queries during XLOG replay.)
231+
*
232+
* The returned buffer is exclusively-locked.
222233
*
223234
* For historical reasons, instead of a ReadBufferMode argument, this only
224235
* supports RBM_ZERO (init == true) and RBM_NORMAL (init == false) modes.
225236
*/
226237
Buffer
227238
XLogReadBuffer(RelFileNodernode,BlockNumberblkno,boolinit)
228239
{
229-
returnXLogReadBufferExtended(rnode,MAIN_FORKNUM,blkno,
230-
init ?RBM_ZERO :RBM_NORMAL);
240+
Bufferbuf;
241+
buf=XLogReadBufferExtended(rnode,MAIN_FORKNUM,blkno,
242+
init ?RBM_ZERO :RBM_NORMAL);
243+
if (BufferIsValid(buf))
244+
LockBuffer(buf,BUFFER_LOCK_EXCLUSIVE);
245+
246+
returnbuf;
231247
}
232248

233249
/*
234250
* XLogReadBufferExtended
235251
*Read a page during XLOG replay
236252
*
237-
* This is functionally comparable to ReadBuffer followed by
238-
* LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE): you get back a pinned
239-
* and locked buffer. (Getting the lock is not really necessary, since we
240-
* expect that this is only used during single-process XLOG replay, but
241-
* some subroutines such as MarkBufferDirty will complain if we don't.)
242-
*
243-
* There's some differences in the behavior wrt. the "mode" argument,
244-
* compared to ReadBufferExtended:
253+
* This is functionally comparable to ReadBufferExtended. There's some
254+
* differences in the behavior wrt. the "mode" argument:
245255
*
246256
* In RBM_NORMAL mode, if the page doesn't exist, or contains all-zeroes, we
247257
* return InvalidBuffer. In this case the caller should silently skip the
@@ -306,16 +316,19 @@ XLogReadBufferExtended(RelFileNode rnode, ForkNumber forknum,
306316
Assert(BufferGetBlockNumber(buffer)==blkno);
307317
}
308318

309-
LockBuffer(buffer,BUFFER_LOCK_EXCLUSIVE);
310-
311319
if (mode==RBM_NORMAL)
312320
{
313321
/* check that page has been initialized */
314322
Pagepage= (Page)BufferGetPage(buffer);
315323

324+
/*
325+
* We assume that PageIsNew is safe without a lock. During recovery,
326+
* there should be no other backends that could modify the buffer at
327+
* the same time.
328+
*/
316329
if (PageIsNew(page))
317330
{
318-
UnlockReleaseBuffer(buffer);
331+
ReleaseBuffer(buffer);
319332
log_invalid_page(rnode,forknum,blkno, true);
320333
returnInvalidBuffer;
321334
}

‎src/backend/catalog/storage.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/storage.c,v 1.4 2009/01/04 14:59:22 heikki Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/storage.c,v 1.5 2009/01/20 18:59:37 heikki Exp $
1212
*
1313
* NOTES
1414
* Some of this code used to be in storage/smgr/smgr.c, and the
@@ -401,6 +401,9 @@ smgr_redo(XLogRecPtr lsn, XLogRecord *record)
401401
{
402402
uint8info=record->xl_info& ~XLR_INFO_MASK;
403403

404+
/* Backup blocks are not used in smgr records */
405+
Assert(!(record->xl_info&XLR_BKP_BLOCK_MASK));
406+
404407
if (info==XLOG_SMGR_CREATE)
405408
{
406409
xl_smgr_create*xlrec= (xl_smgr_create*)XLogRecGetData(record);

‎src/backend/commands/dbcommands.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*
1515
* IDENTIFICATION
16-
* $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.217 2009/01/01 17:23:37momjian Exp $
16+
* $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.218 2009/01/20 18:59:37heikki Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -1941,6 +1941,9 @@ dbase_redo(XLogRecPtr lsn, XLogRecord *record)
19411941
{
19421942
uint8info=record->xl_info& ~XLR_INFO_MASK;
19431943

1944+
/* Backup blocks are not used in dbase records */
1945+
Assert(!(record->xl_info&XLR_BKP_BLOCK_MASK));
1946+
19441947
if (info==XLOG_DBASE_CREATE)
19451948
{
19461949
xl_dbase_create_rec*xlrec= (xl_dbase_create_rec*)XLogRecGetData(record);

‎src/backend/commands/sequence.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/sequence.c,v 1.156 2009/01/01 17:23:39 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/sequence.c,v 1.157 2009/01/20 18:59:37 heikki Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1339,6 +1339,9 @@ seq_redo(XLogRecPtr lsn, XLogRecord *record)
13391339
xl_seq_rec*xlrec= (xl_seq_rec*)XLogRecGetData(record);
13401340
sequence_magic*sm;
13411341

1342+
/* Backup blocks are not used in seq records */
1343+
Assert(!(record->xl_info&XLR_BKP_BLOCK_MASK));
1344+
13421345
if (info!=XLOG_SEQ_LOG)
13431346
elog(PANIC,"seq_redo: unknown op code %u",info);
13441347

‎src/backend/commands/tablespace.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $PostgreSQL: pgsql/src/backend/commands/tablespace.c,v 1.59 2009/01/01 17:23:40 momjian Exp $
40+
* $PostgreSQL: pgsql/src/backend/commands/tablespace.c,v 1.60 2009/01/20 18:59:37 heikki Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -1276,6 +1276,9 @@ tblspc_redo(XLogRecPtr lsn, XLogRecord *record)
12761276
{
12771277
uint8info=record->xl_info& ~XLR_INFO_MASK;
12781278

1279+
/* Backup blocks are not used in tblspc records */
1280+
Assert(!(record->xl_info&XLR_BKP_BLOCK_MASK));
1281+
12791282
if (info==XLOG_TBLSPC_CREATE)
12801283
{
12811284
xl_tblspc_create_rec*xlrec= (xl_tblspc_create_rec*)XLogRecGetData(record);

‎src/backend/storage/freespace/freespace.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/freespace/freespace.c,v 1.71 2009/01/01 17:23:47 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/freespace/freespace.c,v 1.72 2009/01/20 18:59:37 heikki Exp $
1212
*
1313
*
1414
* NOTES:
@@ -212,6 +212,8 @@ XLogRecordPageWithFreeSpace(RelFileNode rnode, BlockNumber heapBlk,
212212

213213
/* If the page doesn't exist already, extend */
214214
buf=XLogReadBufferExtended(rnode,FSM_FORKNUM,blkno,RBM_ZERO_ON_ERROR);
215+
LockBuffer(buf,BUFFER_LOCK_EXCLUSIVE);
216+
215217
page=BufferGetPage(buf);
216218
if (PageIsNew(page))
217219
PageInit(page,BLCKSZ,0);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp