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

Commit91d20ff

Browse files
committed
Additional mop-up for sync-to-fsync changes: avoid issuing fsyncs for
temp tables, and avoid WAL-logging truncations of temp tables. Do issuefsync on truncated files (not sure this is necessary but it seems likea good idea).
1 parente674707 commit91d20ff

File tree

5 files changed

+94
-52
lines changed

5 files changed

+94
-52
lines changed

‎src/backend/storage/buffer/bufmgr.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.168 2004/05/3119:24:05 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.169 2004/05/3120:31:33 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -182,7 +182,8 @@ ReadBufferInternal(Relation reln, BlockNumber blockNum,
182182
{
183183
/* new buffers are zero-filled */
184184
MemSet((char*)MAKE_PTR(bufHdr->data),0,BLCKSZ);
185-
smgrextend(reln->rd_smgr,blockNum, (char*)MAKE_PTR(bufHdr->data));
185+
smgrextend(reln->rd_smgr,blockNum, (char*)MAKE_PTR(bufHdr->data),
186+
reln->rd_istemp);
186187
}
187188
else
188189
{
@@ -915,8 +916,8 @@ BufferGetFileNode(Buffer buffer)
915916
* NOTE: this actually just passes the buffer contents to the kernel; the
916917
* real write to disk won't happen until the kernel feels like it. This
917918
* is okay from our point of view since we can redo the changes from WAL.
918-
* However, we will need to force the changes to disk viasync/fsync
919-
*beforewe can checkpoint WAL.
919+
* However, we will need to force the changes to disk via fsync before
920+
* we can checkpoint WAL.
920921
*
921922
* BufMgrLock must be held at entry, and the buffer must be pinned. The
922923
* caller is also responsible for doing StartBufferIO/TerminateBufferIO.
@@ -979,7 +980,8 @@ FlushBuffer(BufferDesc *buf, SMgrRelation reln)
979980
*/
980981
smgrwrite(reln,
981982
buf->tag.blockNum,
982-
(char*)MAKE_PTR(buf->data));
983+
(char*)MAKE_PTR(buf->data),
984+
false);
983985

984986
/* Pop the error context stack */
985987
error_context_stack=errcontext.previous;
@@ -1033,7 +1035,7 @@ RelationTruncate(Relation rel, BlockNumber nblocks)
10331035
rel->rd_targblock=InvalidBlockNumber;
10341036

10351037
/* Do the real work */
1036-
smgrtruncate(rel->rd_smgr,nblocks);
1038+
smgrtruncate(rel->rd_smgr,nblocks,rel->rd_istemp);
10371039
}
10381040

10391041
/* ---------------------------------------------------------------------
@@ -1351,7 +1353,8 @@ FlushRelationBuffers(Relation rel, BlockNumber firstDelBlock)
13511353

13521354
smgrwrite(rel->rd_smgr,
13531355
bufHdr->tag.blockNum,
1354-
(char*)MAKE_PTR(bufHdr->data));
1356+
(char*)MAKE_PTR(bufHdr->data),
1357+
true);
13551358

13561359
bufHdr->flags &= ~(BM_DIRTY |BM_JUST_DIRTIED);
13571360
bufHdr->cntxDirty= false;

‎src/backend/storage/buffer/localbuf.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/storage/buffer/localbuf.c,v 1.54 2004/04/22 07:21:55 neilc Exp $
12+
* $PostgreSQL: pgsql/src/backend/storage/buffer/localbuf.c,v 1.55 2004/05/31 20:31:33 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -111,7 +111,8 @@ LocalBufferAlloc(Relation reln, BlockNumber blockNum, bool *foundPtr)
111111
/* And write... */
112112
smgrwrite(reln,
113113
bufHdr->tag.blockNum,
114-
(char*)MAKE_PTR(bufHdr->data));
114+
(char*)MAKE_PTR(bufHdr->data),
115+
true);
115116

116117
LocalBufferFlushCount++;
117118
}

‎src/backend/storage/smgr/md.c

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/smgr/md.c,v 1.105 2004/05/3103:48:06 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/smgr/md.c,v 1.106 2004/05/3120:31:33 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -270,7 +270,7 @@ mdunlink(RelFileNode rnode, bool isRedo)
270270
* already. Might as well pass in the position and save a seek.
271271
*/
272272
bool
273-
mdextend(SMgrRelationreln,BlockNumberblocknum,char*buffer)
273+
mdextend(SMgrRelationreln,BlockNumberblocknum,char*buffer,boolisTemp)
274274
{
275275
longseekpos;
276276
intnbytes;
@@ -311,8 +311,11 @@ mdextend(SMgrRelation reln, BlockNumber blocknum, char *buffer)
311311
return false;
312312
}
313313

314-
if (!register_dirty_segment(reln,v))
315-
return false;
314+
if (!isTemp)
315+
{
316+
if (!register_dirty_segment(reln,v))
317+
return false;
318+
}
316319

317320
#ifndefLET_OS_MANAGE_FILESIZE
318321
Assert(_mdnblocks(v->mdfd_vfd,BLCKSZ) <= ((BlockNumber)RELSEG_SIZE));
@@ -465,7 +468,7 @@ mdread(SMgrRelation reln, BlockNumber blocknum, char *buffer)
465468
*mdwrite() -- Write the supplied block at the appropriate location.
466469
*/
467470
bool
468-
mdwrite(SMgrRelationreln,BlockNumberblocknum,char*buffer)
471+
mdwrite(SMgrRelationreln,BlockNumberblocknum,char*buffer,boolisTemp)
469472
{
470473
longseekpos;
471474
MdfdVec*v;
@@ -485,8 +488,11 @@ mdwrite(SMgrRelation reln, BlockNumber blocknum, char *buffer)
485488
if (FileWrite(v->mdfd_vfd,buffer,BLCKSZ)!=BLCKSZ)
486489
return false;
487490

488-
if (!register_dirty_segment(reln,v))
489-
return false;
491+
if (!isTemp)
492+
{
493+
if (!register_dirty_segment(reln,v))
494+
return false;
495+
}
490496

491497
return true;
492498
}
@@ -565,7 +571,7 @@ mdnblocks(SMgrRelation reln)
565571
*Returns # of blocks or InvalidBlockNumber on error.
566572
*/
567573
BlockNumber
568-
mdtruncate(SMgrRelationreln,BlockNumbernblocks)
574+
mdtruncate(SMgrRelationreln,BlockNumbernblocks,boolisTemp)
569575
{
570576
MdfdVec*v;
571577
BlockNumbercurnblk;
@@ -624,6 +630,11 @@ mdtruncate(SMgrRelation reln, BlockNumber nblocks)
624630

625631
if (FileTruncate(v->mdfd_vfd,lastsegblocks*BLCKSZ)<0)
626632
returnInvalidBlockNumber;
633+
if (!isTemp)
634+
{
635+
if (!register_dirty_segment(reln,v))
636+
returnInvalidBlockNumber;
637+
}
627638
v=v->mdfd_chain;
628639
ov->mdfd_chain=NULL;
629640
}
@@ -640,6 +651,11 @@ mdtruncate(SMgrRelation reln, BlockNumber nblocks)
640651
#else
641652
if (FileTruncate(v->mdfd_vfd,nblocks*BLCKSZ)<0)
642653
returnInvalidBlockNumber;
654+
if (!isTemp)
655+
{
656+
if (!register_dirty_segment(reln,v))
657+
returnInvalidBlockNumber;
658+
}
643659
#endif
644660

645661
returnnblocks;

‎src/backend/storage/smgr/smgr.c

Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/backend/storage/smgr/smgr.c,v 1.71 2004/05/3103:48:06 tgl Exp $
14+
* $PostgreSQL: pgsql/src/backend/storage/smgr/smgr.c,v 1.72 2004/05/3120:31:33 tgl Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -40,13 +40,14 @@ typedef struct f_smgr
4040
bool(*smgr_create) (SMgrRelationreln,boolisRedo);
4141
bool(*smgr_unlink) (RelFileNodernode,boolisRedo);
4242
bool(*smgr_extend) (SMgrRelationreln,BlockNumberblocknum,
43-
char*buffer);
43+
char*buffer,boolisTemp);
4444
bool(*smgr_read) (SMgrRelationreln,BlockNumberblocknum,
45-
char*buffer);
45+
char*buffer);
4646
bool(*smgr_write) (SMgrRelationreln,BlockNumberblocknum,
47-
char*buffer);
47+
char*buffer,boolisTemp);
4848
BlockNumber (*smgr_nblocks) (SMgrRelationreln);
49-
BlockNumber (*smgr_truncate) (SMgrRelationreln,BlockNumbernblocks);
49+
BlockNumber (*smgr_truncate) (SMgrRelationreln,BlockNumbernblocks,
50+
boolisTemp);
5051
bool(*smgr_commit) (void);/* may be NULL */
5152
bool(*smgr_abort) (void);/* may be NULL */
5253
bool(*smgr_sync) (void);/* may be NULL */
@@ -438,9 +439,10 @@ smgr_internal_unlink(RelFileNode rnode, int which, bool isTemp, bool isRedo)
438439
*failure we clean up by truncating.
439440
*/
440441
void
441-
smgrextend(SMgrRelationreln,BlockNumberblocknum,char*buffer)
442+
smgrextend(SMgrRelationreln,BlockNumberblocknum,char*buffer,boolisTemp)
442443
{
443-
if (! (*(smgrsw[reln->smgr_which].smgr_extend)) (reln,blocknum,buffer))
444+
if (! (*(smgrsw[reln->smgr_which].smgr_extend)) (reln,blocknum,buffer,
445+
isTemp))
444446
ereport(ERROR,
445447
(errcode_for_file_access(),
446448
errmsg("could not extend relation %u/%u: %m",
@@ -473,12 +475,18 @@ smgrread(SMgrRelation reln, BlockNumber blocknum, char *buffer)
473475
*smgrwrite() -- Write the supplied buffer out.
474476
*
475477
*This is not a synchronous write -- the block is not necessarily
476-
*on disk at return, only dumped out to the kernel.
478+
*on disk at return, only dumped out to the kernel. However,
479+
*provisions will be made to fsync the write before the next checkpoint.
480+
*
481+
*isTemp indicates that the relation is a temp table (ie, is managed
482+
*by the local-buffer manager). In this case no provisions need be
483+
*made to fsync the write before checkpointing.
477484
*/
478485
void
479-
smgrwrite(SMgrRelationreln,BlockNumberblocknum,char*buffer)
486+
smgrwrite(SMgrRelationreln,BlockNumberblocknum,char*buffer,boolisTemp)
480487
{
481-
if (! (*(smgrsw[reln->smgr_which].smgr_write)) (reln,blocknum,buffer))
488+
if (! (*(smgrsw[reln->smgr_which].smgr_write)) (reln,blocknum,buffer,
489+
isTemp))
482490
ereport(ERROR,
483491
(errcode_for_file_access(),
484492
errmsg("could not write block %u of relation %u/%u: %m",
@@ -525,12 +533,9 @@ smgrnblocks(SMgrRelation reln)
525533
*transaction on failure.
526534
*/
527535
BlockNumber
528-
smgrtruncate(SMgrRelationreln,BlockNumbernblocks)
536+
smgrtruncate(SMgrRelationreln,BlockNumbernblocks,boolisTemp)
529537
{
530538
BlockNumbernewblks;
531-
XLogRecPtrlsn;
532-
XLogRecDatardata;
533-
xl_smgr_truncatexlrec;
534539

535540
/*
536541
* Tell the free space map to forget anything it may have stored
@@ -540,7 +545,8 @@ smgrtruncate(SMgrRelation reln, BlockNumber nblocks)
540545
FreeSpaceMapTruncateRel(&reln->smgr_rnode,nblocks);
541546

542547
/* Do the truncation */
543-
newblks= (*(smgrsw[reln->smgr_which].smgr_truncate)) (reln,nblocks);
548+
newblks= (*(smgrsw[reln->smgr_which].smgr_truncate)) (reln,nblocks,
549+
isTemp);
544550
if (newblks==InvalidBlockNumber)
545551
ereport(ERROR,
546552
(errcode_for_file_access(),
@@ -549,20 +555,29 @@ smgrtruncate(SMgrRelation reln, BlockNumber nblocks)
549555
reln->smgr_rnode.relNode,
550556
nblocks)));
551557

552-
/*
553-
* Make a non-transactional XLOG entry showing the file truncation. It's
554-
* non-transactional because we should replay it whether the transaction
555-
* commits or not; the underlying file change is certainly not reversible.
556-
*/
557-
xlrec.blkno=newblks;
558-
xlrec.rnode=reln->smgr_rnode;
558+
if (!isTemp)
559+
{
560+
/*
561+
* Make a non-transactional XLOG entry showing the file truncation.
562+
* It's non-transactional because we should replay it whether the
563+
* transaction commits or not; the underlying file change is certainly
564+
* not reversible.
565+
*/
566+
XLogRecPtrlsn;
567+
XLogRecDatardata;
568+
xl_smgr_truncatexlrec;
559569

560-
rdata.buffer=InvalidBuffer;
561-
rdata.data= (char*)&xlrec;
562-
rdata.len=sizeof(xlrec);
563-
rdata.next=NULL;
570+
xlrec.blkno=newblks;
571+
xlrec.rnode=reln->smgr_rnode;
564572

565-
lsn=XLogInsert(RM_SMGR_ID,XLOG_SMGR_TRUNCATE |XLOG_NO_TRAN,&rdata);
573+
rdata.buffer=InvalidBuffer;
574+
rdata.data= (char*)&xlrec;
575+
rdata.len=sizeof(xlrec);
576+
rdata.next=NULL;
577+
578+
lsn=XLogInsert(RM_SMGR_ID,XLOG_SMGR_TRUNCATE |XLOG_NO_TRAN,
579+
&rdata);
580+
}
566581

567582
returnnewblks;
568583
}
@@ -725,7 +740,8 @@ smgr_redo(XLogRecPtr lsn, XLogRecord *record)
725740

726741
/* Do the truncation */
727742
newblks= (*(smgrsw[reln->smgr_which].smgr_truncate)) (reln,
728-
xlrec->blkno);
743+
xlrec->blkno,
744+
false);
729745
if (newblks==InvalidBlockNumber)
730746
ereport(WARNING,
731747
(errcode_for_file_access(),

‎src/include/storage/smgr.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/storage/smgr.h,v 1.42 2004/05/3103:48:10 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/storage/smgr.h,v 1.43 2004/05/3120:31:33 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -55,11 +55,14 @@ extern void smgrclosenode(RelFileNode rnode);
5555
externvoidsmgrcreate(SMgrRelationreln,boolisTemp,boolisRedo);
5656
externvoidsmgrscheduleunlink(SMgrRelationreln,boolisTemp);
5757
externvoidsmgrdounlink(SMgrRelationreln,boolisTemp,boolisRedo);
58-
externvoidsmgrextend(SMgrRelationreln,BlockNumberblocknum,char*buffer);
58+
externvoidsmgrextend(SMgrRelationreln,BlockNumberblocknum,char*buffer,
59+
boolisTemp);
5960
externvoidsmgrread(SMgrRelationreln,BlockNumberblocknum,char*buffer);
60-
externvoidsmgrwrite(SMgrRelationreln,BlockNumberblocknum,char*buffer);
61+
externvoidsmgrwrite(SMgrRelationreln,BlockNumberblocknum,char*buffer,
62+
boolisTemp);
6163
externBlockNumbersmgrnblocks(SMgrRelationreln);
62-
externBlockNumbersmgrtruncate(SMgrRelationreln,BlockNumbernblocks);
64+
externBlockNumbersmgrtruncate(SMgrRelationreln,BlockNumbernblocks,
65+
boolisTemp);
6366
externvoidsmgrDoPendingDeletes(boolisCommit);
6467
externintsmgrGetPendingDeletes(boolforCommit,RelFileNode**ptr);
6568
externvoidsmgrcommit(void);
@@ -78,11 +81,14 @@ extern bool mdinit(void);
7881
externboolmdclose(SMgrRelationreln);
7982
externboolmdcreate(SMgrRelationreln,boolisRedo);
8083
externboolmdunlink(RelFileNodernode,boolisRedo);
81-
externboolmdextend(SMgrRelationreln,BlockNumberblocknum,char*buffer);
84+
externboolmdextend(SMgrRelationreln,BlockNumberblocknum,char*buffer,
85+
boolisTemp);
8286
externboolmdread(SMgrRelationreln,BlockNumberblocknum,char*buffer);
83-
externboolmdwrite(SMgrRelationreln,BlockNumberblocknum,char*buffer);
87+
externboolmdwrite(SMgrRelationreln,BlockNumberblocknum,char*buffer,
88+
boolisTemp);
8489
externBlockNumbermdnblocks(SMgrRelationreln);
85-
externBlockNumbermdtruncate(SMgrRelationreln,BlockNumbernblocks);
90+
externBlockNumbermdtruncate(SMgrRelationreln,BlockNumbernblocks,
91+
boolisTemp);
8692
externboolmdsync(void);
8793

8894
externvoidRememberFsyncRequest(RelFileNodernode,BlockNumbersegno);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp