1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-02 04:21:28 +03:00

Prevent re-use of a deleted relation's relfilenode until after the next

checkpoint.  This guards against an unlikely data-loss scenario in which
we re-use the relfilenode, then crash, then replay the deletion and
recreation of the file.  Even then we'd be OK if all insertions into the
new relation had been WAL-logged ... but that's not guaranteed given all
the no-WAL-logging optimizations that have recently been added.

Patch by Heikki Linnakangas, per a discussion last month.
This commit is contained in:
Tom Lane
2007-11-15 20:36:40 +00:00
parent 7a550cb95c
commit 6cc4451b5c
5 changed files with 274 additions and 25 deletions

View File

@@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/storage/smgr/smgr.c,v 1.106 2007/09/05 18:10:48 tgl Exp $
* $PostgreSQL: pgsql/src/backend/storage/smgr/smgr.c,v 1.107 2007/11/15 20:36:40 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -55,9 +55,11 @@ typedef struct f_smgr
void (*smgr_truncate) (SMgrRelation reln, BlockNumber nblocks,
bool isTemp);
void (*smgr_immedsync) (SMgrRelation reln);
void (*smgr_commit) (void); /* may be NULL */
void (*smgr_abort) (void); /* may be NULL */
void (*smgr_sync) (void); /* may be NULL */
void (*smgr_commit) (void); /* may be NULL */
void (*smgr_abort) (void); /* may be NULL */
void (*smgr_pre_ckpt) (void); /* may be NULL */
void (*smgr_sync) (void); /* may be NULL */
void (*smgr_post_ckpt) (void); /* may be NULL */
} f_smgr;
@@ -65,7 +67,7 @@ static const f_smgr smgrsw[] = {
/* magnetic disk */
{mdinit, NULL, mdclose, mdcreate, mdunlink, mdextend,
mdread, mdwrite, mdnblocks, mdtruncate, mdimmedsync,
NULL, NULL, mdsync
NULL, NULL, mdpreckpt, mdsync, mdpostckpt
}
};
@@ -778,7 +780,22 @@ smgrabort(void)
}
/*
* smgrsync() -- Sync files to disk at checkpoint time.
* smgrpreckpt() -- Prepare for checkpoint.
*/
void
smgrpreckpt(void)
{
int i;
for (i = 0; i < NSmgr; i++)
{
if (smgrsw[i].smgr_pre_ckpt)
(*(smgrsw[i].smgr_pre_ckpt)) ();
}
}
/*
* smgrsync() -- Sync files to disk during checkpoint.
*/
void
smgrsync(void)
@@ -792,6 +809,21 @@ smgrsync(void)
}
}
/*
* smgrpostckpt() -- Post-checkpoint cleanup.
*/
void
smgrpostckpt(void)
{
int i;
for (i = 0; i < NSmgr; i++)
{
if (smgrsw[i].smgr_post_ckpt)
(*(smgrsw[i].smgr_post_ckpt)) ();
}
}
void
smgr_redo(XLogRecPtr lsn, XLogRecord *record)