Commit 33960006 authored by Heikki Linnakangas's avatar Heikki Linnakangas

Rethink the way FSM truncation works. Instead of WAL-logging FSM

truncations in FSM code, call FreeSpaceMapTruncateRel from smgr_redo. To
make that cleaner from modularity point of view, move the WAL-logging one
level up to RelationTruncate, and move RelationTruncate and all the
related WAL-logging to new src/backend/catalog/storage.c file. Introduce
new RelationCreateStorage and RelationDropStorage functions that are used
instead of calling smgrcreate/smgrscheduleunlink directly. Move the
pending rel deletion stuff from smgrcreate/smgrscheduleunlink to the new
functions. This leaves smgr.c as a thin wrapper around md.c; all the
transactional stuff is now in storage.c.

This will make it easier to add new forks with similar truncation logic,
like the visibility map.
parent 26e6c896
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/gin/gininsert.c,v 1.16 2008/11/13 17:42:09 tgl Exp $ * $PostgreSQL: pgsql/src/backend/access/gin/gininsert.c,v 1.17 2008/11/19 10:34:50 heikki Exp $
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -284,9 +284,6 @@ ginbuild(PG_FUNCTION_ARGS) ...@@ -284,9 +284,6 @@ ginbuild(PG_FUNCTION_ARGS)
elog(ERROR, "index \"%s\" already contains data", elog(ERROR, "index \"%s\" already contains data",
RelationGetRelationName(index)); RelationGetRelationName(index));
/* Initialize FSM */
InitIndexFreeSpaceMap(index);
initGinState(&buildstate.ginstate, index); initGinState(&buildstate.ginstate, index);
/* initialize the root page */ /* initialize the root page */
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/gin/ginvacuum.c,v 1.25 2008/11/03 20:47:48 tgl Exp $ * $PostgreSQL: pgsql/src/backend/access/gin/ginvacuum.c,v 1.26 2008/11/19 10:34:50 heikki Exp $
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "access/genam.h" #include "access/genam.h"
#include "access/gin.h" #include "access/gin.h"
#include "catalog/storage.h"
#include "commands/vacuum.h" #include "commands/vacuum.h"
#include "miscadmin.h" #include "miscadmin.h"
#include "storage/bufmgr.h" #include "storage/bufmgr.h"
...@@ -757,7 +758,6 @@ ginvacuumcleanup(PG_FUNCTION_ARGS) ...@@ -757,7 +758,6 @@ ginvacuumcleanup(PG_FUNCTION_ARGS)
if (info->vacuum_full && lastBlock > lastFilledBlock) if (info->vacuum_full && lastBlock > lastFilledBlock)
{ {
/* try to truncate index */ /* try to truncate index */
FreeSpaceMapTruncateRel(index, lastFilledBlock + 1);
RelationTruncate(index, lastFilledBlock + 1); RelationTruncate(index, lastFilledBlock + 1);
stats->pages_removed = lastBlock - lastFilledBlock; stats->pages_removed = lastBlock - lastFilledBlock;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/gist/gist.c,v 1.154 2008/11/13 17:42:09 tgl Exp $ * $PostgreSQL: pgsql/src/backend/access/gist/gist.c,v 1.155 2008/11/19 10:34:50 heikki Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -103,9 +103,6 @@ gistbuild(PG_FUNCTION_ARGS) ...@@ -103,9 +103,6 @@ gistbuild(PG_FUNCTION_ARGS)
elog(ERROR, "index \"%s\" already contains data", elog(ERROR, "index \"%s\" already contains data",
RelationGetRelationName(index)); RelationGetRelationName(index));
/* Initialize FSM */
InitIndexFreeSpaceMap(index);
/* no locking is needed */ /* no locking is needed */
initGISTstate(&buildstate.giststate, index); initGISTstate(&buildstate.giststate, index);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/gist/gistvacuum.c,v 1.40 2008/11/03 20:47:48 tgl Exp $ * $PostgreSQL: pgsql/src/backend/access/gist/gistvacuum.c,v 1.41 2008/11/19 10:34:50 heikki Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "access/genam.h" #include "access/genam.h"
#include "access/gist_private.h" #include "access/gist_private.h"
#include "catalog/storage.h"
#include "commands/vacuum.h" #include "commands/vacuum.h"
#include "miscadmin.h" #include "miscadmin.h"
#include "storage/bufmgr.h" #include "storage/bufmgr.h"
...@@ -603,7 +604,6 @@ gistvacuumcleanup(PG_FUNCTION_ARGS) ...@@ -603,7 +604,6 @@ gistvacuumcleanup(PG_FUNCTION_ARGS)
if (info->vacuum_full && lastFilledBlock < lastBlock) if (info->vacuum_full && lastFilledBlock < lastBlock)
{ /* try to truncate index */ { /* try to truncate index */
FreeSpaceMapTruncateRel(rel, lastFilledBlock + 1);
RelationTruncate(rel, lastFilledBlock + 1); RelationTruncate(rel, lastFilledBlock + 1);
stats->std.pages_removed = lastBlock - lastFilledBlock; stats->std.pages_removed = lastBlock - lastFilledBlock;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.269 2008/11/06 20:51:14 tgl Exp $ * $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.270 2008/11/19 10:34:50 heikki Exp $
* *
* *
* INTERFACE ROUTINES * INTERFACE ROUTINES
...@@ -4863,8 +4863,7 @@ heap_sync(Relation rel) ...@@ -4863,8 +4863,7 @@ heap_sync(Relation rel)
/* FlushRelationBuffers will have opened rd_smgr */ /* FlushRelationBuffers will have opened rd_smgr */
smgrimmedsync(rel->rd_smgr, MAIN_FORKNUM); smgrimmedsync(rel->rd_smgr, MAIN_FORKNUM);
/* sync FSM as well */ /* FSM is not critical, don't bother syncing it */
smgrimmedsync(rel->rd_smgr, FSM_FORKNUM);
/* toast heap, if any */ /* toast heap, if any */
if (OidIsValid(rel->rd_rel->reltoastrelid)) if (OidIsValid(rel->rd_rel->reltoastrelid))
...@@ -4874,7 +4873,6 @@ heap_sync(Relation rel) ...@@ -4874,7 +4873,6 @@ heap_sync(Relation rel)
toastrel = heap_open(rel->rd_rel->reltoastrelid, AccessShareLock); toastrel = heap_open(rel->rd_rel->reltoastrelid, AccessShareLock);
FlushRelationBuffers(toastrel); FlushRelationBuffers(toastrel);
smgrimmedsync(toastrel->rd_smgr, MAIN_FORKNUM); smgrimmedsync(toastrel->rd_smgr, MAIN_FORKNUM);
smgrimmedsync(toastrel->rd_smgr, FSM_FORKNUM);
heap_close(toastrel, AccessShareLock); heap_close(toastrel, AccessShareLock);
} }
} }
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtree.c,v 1.165 2008/11/13 17:42:10 tgl Exp $ * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtree.c,v 1.166 2008/11/19 10:34:50 heikki Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "access/nbtree.h" #include "access/nbtree.h"
#include "access/relscan.h" #include "access/relscan.h"
#include "catalog/index.h" #include "catalog/index.h"
#include "catalog/storage.h"
#include "commands/vacuum.h" #include "commands/vacuum.h"
#include "miscadmin.h" #include "miscadmin.h"
#include "storage/bufmgr.h" #include "storage/bufmgr.h"
...@@ -109,9 +110,6 @@ btbuild(PG_FUNCTION_ARGS) ...@@ -109,9 +110,6 @@ btbuild(PG_FUNCTION_ARGS)
elog(ERROR, "index \"%s\" already contains data", elog(ERROR, "index \"%s\" already contains data",
RelationGetRelationName(index)); RelationGetRelationName(index));
/* Initialize FSM */
InitIndexFreeSpaceMap(index);
buildstate.spool = _bt_spoolinit(index, indexInfo->ii_Unique, false); buildstate.spool = _bt_spoolinit(index, indexInfo->ii_Unique, false);
/* /*
...@@ -696,7 +694,6 @@ btvacuumscan(IndexVacuumInfo *info, IndexBulkDeleteResult *stats, ...@@ -696,7 +694,6 @@ btvacuumscan(IndexVacuumInfo *info, IndexBulkDeleteResult *stats,
/* /*
* Okay to truncate. * Okay to truncate.
*/ */
FreeSpaceMapTruncateRel(rel, new_pages);
RelationTruncate(rel, new_pages); RelationTruncate(rel, new_pages);
/* update statistics */ /* update statistics */
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Resource managers definition * Resource managers definition
* *
* $PostgreSQL: pgsql/src/backend/access/transam/rmgr.c,v 1.26 2008/09/30 10:52:11 heikki Exp $ * $PostgreSQL: pgsql/src/backend/access/transam/rmgr.c,v 1.27 2008/11/19 10:34:50 heikki Exp $
*/ */
#include "postgres.h" #include "postgres.h"
...@@ -16,11 +16,11 @@ ...@@ -16,11 +16,11 @@
#include "access/nbtree.h" #include "access/nbtree.h"
#include "access/xact.h" #include "access/xact.h"
#include "access/xlog_internal.h" #include "access/xlog_internal.h"
#include "catalog/storage.h"
#include "commands/dbcommands.h" #include "commands/dbcommands.h"
#include "commands/sequence.h" #include "commands/sequence.h"
#include "commands/tablespace.h" #include "commands/tablespace.h"
#include "storage/freespace.h" #include "storage/freespace.h"
#include "storage/smgr.h"
const RmgrData RmgrTable[RM_MAX_ID + 1] = { const RmgrData RmgrTable[RM_MAX_ID + 1] = {
...@@ -31,7 +31,7 @@ const RmgrData RmgrTable[RM_MAX_ID + 1] = { ...@@ -31,7 +31,7 @@ const RmgrData RmgrTable[RM_MAX_ID + 1] = {
{"Database", dbase_redo, dbase_desc, NULL, NULL, NULL}, {"Database", dbase_redo, dbase_desc, NULL, NULL, NULL},
{"Tablespace", tblspc_redo, tblspc_desc, NULL, NULL, NULL}, {"Tablespace", tblspc_redo, tblspc_desc, NULL, NULL, NULL},
{"MultiXact", multixact_redo, multixact_desc, NULL, NULL, NULL}, {"MultiXact", multixact_redo, multixact_desc, NULL, NULL, NULL},
{"FreeSpaceMap", fsm_redo, fsm_desc, NULL, NULL, NULL}, {"Reserved 7", NULL, NULL, NULL, NULL, NULL},
{"Reserved 8", NULL, NULL, NULL, NULL, NULL}, {"Reserved 8", NULL, NULL, NULL, NULL, NULL},
{"Heap2", heap2_redo, heap2_desc, NULL, NULL, NULL}, {"Heap2", heap2_redo, heap2_desc, NULL, NULL, NULL},
{"Heap", heap_redo, heap_desc, NULL, NULL, NULL}, {"Heap", heap_redo, heap_desc, NULL, NULL, NULL},
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/transam/twophase.c,v 1.47 2008/11/02 21:24:51 tgl Exp $ * $PostgreSQL: pgsql/src/backend/access/transam/twophase.c,v 1.48 2008/11/19 10:34:50 heikki Exp $
* *
* NOTES * NOTES
* Each global transaction is associated with a global transaction * Each global transaction is associated with a global transaction
...@@ -48,7 +48,9 @@ ...@@ -48,7 +48,9 @@
#include "access/twophase.h" #include "access/twophase.h"
#include "access/twophase_rmgr.h" #include "access/twophase_rmgr.h"
#include "access/xact.h" #include "access/xact.h"
#include "access/xlogutils.h"
#include "catalog/pg_type.h" #include "catalog/pg_type.h"
#include "catalog/storage.h"
#include "funcapi.h" #include "funcapi.h"
#include "miscadmin.h" #include "miscadmin.h"
#include "pg_trace.h" #include "pg_trace.h"
...@@ -141,12 +143,12 @@ static void RecordTransactionCommitPrepared(TransactionId xid, ...@@ -141,12 +143,12 @@ static void RecordTransactionCommitPrepared(TransactionId xid,
int nchildren, int nchildren,
TransactionId *children, TransactionId *children,
int nrels, int nrels,
RelFileFork *rels); RelFileNode *rels);
static void RecordTransactionAbortPrepared(TransactionId xid, static void RecordTransactionAbortPrepared(TransactionId xid,
int nchildren, int nchildren,
TransactionId *children, TransactionId *children,
int nrels, int nrels,
RelFileFork *rels); RelFileNode *rels);
static void ProcessRecords(char *bufptr, TransactionId xid, static void ProcessRecords(char *bufptr, TransactionId xid,
const TwoPhaseCallback callbacks[]); const TwoPhaseCallback callbacks[]);
...@@ -694,8 +696,8 @@ TwoPhaseGetDummyProc(TransactionId xid) ...@@ -694,8 +696,8 @@ TwoPhaseGetDummyProc(TransactionId xid)
* *
* 1. TwoPhaseFileHeader * 1. TwoPhaseFileHeader
* 2. TransactionId[] (subtransactions) * 2. TransactionId[] (subtransactions)
* 3. RelFileFork[] (files to be deleted at commit) * 3. RelFileNode[] (files to be deleted at commit)
* 4. RelFileFork[] (files to be deleted at abort) * 4. RelFileNode[] (files to be deleted at abort)
* 5. TwoPhaseRecordOnDisk * 5. TwoPhaseRecordOnDisk
* 6. ... * 6. ...
* 7. TwoPhaseRecordOnDisk (end sentinel, rmid == TWOPHASE_RM_END_ID) * 7. TwoPhaseRecordOnDisk (end sentinel, rmid == TWOPHASE_RM_END_ID)
...@@ -793,8 +795,8 @@ StartPrepare(GlobalTransaction gxact) ...@@ -793,8 +795,8 @@ StartPrepare(GlobalTransaction gxact)
TransactionId xid = gxact->proc.xid; TransactionId xid = gxact->proc.xid;
TwoPhaseFileHeader hdr; TwoPhaseFileHeader hdr;
TransactionId *children; TransactionId *children;
RelFileFork *commitrels; RelFileNode *commitrels;
RelFileFork *abortrels; RelFileNode *abortrels;
/* Initialize linked list */ /* Initialize linked list */
records.head = palloc0(sizeof(XLogRecData)); records.head = palloc0(sizeof(XLogRecData));
...@@ -832,12 +834,12 @@ StartPrepare(GlobalTransaction gxact) ...@@ -832,12 +834,12 @@ StartPrepare(GlobalTransaction gxact)
} }
if (hdr.ncommitrels > 0) if (hdr.ncommitrels > 0)
{ {
save_state_data(commitrels, hdr.ncommitrels * sizeof(RelFileFork)); save_state_data(commitrels, hdr.ncommitrels * sizeof(RelFileNode));
pfree(commitrels); pfree(commitrels);
} }
if (hdr.nabortrels > 0) if (hdr.nabortrels > 0)
{ {
save_state_data(abortrels, hdr.nabortrels * sizeof(RelFileFork)); save_state_data(abortrels, hdr.nabortrels * sizeof(RelFileNode));
pfree(abortrels); pfree(abortrels);
} }
} }
...@@ -1140,8 +1142,10 @@ FinishPreparedTransaction(const char *gid, bool isCommit) ...@@ -1140,8 +1142,10 @@ FinishPreparedTransaction(const char *gid, bool isCommit)
TwoPhaseFileHeader *hdr; TwoPhaseFileHeader *hdr;
TransactionId latestXid; TransactionId latestXid;
TransactionId *children; TransactionId *children;
RelFileFork *commitrels; RelFileNode *commitrels;
RelFileFork *abortrels; RelFileNode *abortrels;
RelFileNode *delrels;
int ndelrels;
int i; int i;
/* /*
...@@ -1169,10 +1173,10 @@ FinishPreparedTransaction(const char *gid, bool isCommit) ...@@ -1169,10 +1173,10 @@ FinishPreparedTransaction(const char *gid, bool isCommit)
bufptr = buf + MAXALIGN(sizeof(TwoPhaseFileHeader)); bufptr = buf + MAXALIGN(sizeof(TwoPhaseFileHeader));
children = (TransactionId *) bufptr; children = (TransactionId *) bufptr;
bufptr += MAXALIGN(hdr->nsubxacts * sizeof(TransactionId)); bufptr += MAXALIGN(hdr->nsubxacts * sizeof(TransactionId));
commitrels = (RelFileFork *) bufptr; commitrels = (RelFileNode *) bufptr;
bufptr += MAXALIGN(hdr->ncommitrels * sizeof(RelFileFork)); bufptr += MAXALIGN(hdr->ncommitrels * sizeof(RelFileNode));
abortrels = (RelFileFork *) bufptr; abortrels = (RelFileNode *) bufptr;
bufptr += MAXALIGN(hdr->nabortrels * sizeof(RelFileFork)); bufptr += MAXALIGN(hdr->nabortrels * sizeof(RelFileNode));
/* compute latestXid among all children */ /* compute latestXid among all children */
latestXid = TransactionIdLatest(xid, hdr->nsubxacts, children); latestXid = TransactionIdLatest(xid, hdr->nsubxacts, children);
...@@ -1214,21 +1218,28 @@ FinishPreparedTransaction(const char *gid, bool isCommit) ...@@ -1214,21 +1218,28 @@ FinishPreparedTransaction(const char *gid, bool isCommit)
*/ */
if (isCommit) if (isCommit)
{ {
for (i = 0; i < hdr->ncommitrels; i++) delrels = commitrels;
{ ndelrels = hdr->ncommitrels;
SMgrRelation srel = smgropen(commitrels[i].rnode);
smgrdounlink(srel, commitrels[i].forknum, false, false);
smgrclose(srel);
}
} }
else else
{ {
for (i = 0; i < hdr->nabortrels; i++) delrels = abortrels;
ndelrels = hdr->nabortrels;
}
for (i = 0; i < ndelrels; i++)
{
SMgrRelation srel = smgropen(delrels[i]);
ForkNumber fork;
for (fork = 0; fork <= MAX_FORKNUM; fork++)
{ {
SMgrRelation srel = smgropen(abortrels[i].rnode); if (smgrexists(srel, fork))
smgrdounlink(srel, abortrels[i].forknum, false, false); {
smgrclose(srel); XLogDropRelation(delrels[i], fork);
smgrdounlink(srel, fork, false, true);
}
} }
smgrclose(srel);
} }
/* And now do the callbacks */ /* And now do the callbacks */
...@@ -1639,8 +1650,8 @@ RecoverPreparedTransactions(void) ...@@ -1639,8 +1650,8 @@ RecoverPreparedTransactions(void)
bufptr = buf + MAXALIGN(sizeof(TwoPhaseFileHeader)); bufptr = buf + MAXALIGN(sizeof(TwoPhaseFileHeader));
subxids = (TransactionId *) bufptr; subxids = (TransactionId *) bufptr;
bufptr += MAXALIGN(hdr->nsubxacts * sizeof(TransactionId)); bufptr += MAXALIGN(hdr->nsubxacts * sizeof(TransactionId));
bufptr += MAXALIGN(hdr->ncommitrels * sizeof(RelFileFork)); bufptr += MAXALIGN(hdr->ncommitrels * sizeof(RelFileNode));
bufptr += MAXALIGN(hdr->nabortrels * sizeof(RelFileFork)); bufptr += MAXALIGN(hdr->nabortrels * sizeof(RelFileNode));
/* /*
* Reconstruct subtrans state for the transaction --- needed * Reconstruct subtrans state for the transaction --- needed
...@@ -1693,7 +1704,7 @@ RecordTransactionCommitPrepared(TransactionId xid, ...@@ -1693,7 +1704,7 @@ RecordTransactionCommitPrepared(TransactionId xid,
int nchildren, int nchildren,
TransactionId *children, TransactionId *children,
int nrels, int nrels,
RelFileFork *rels) RelFileNode *rels)
{ {
XLogRecData rdata[3]; XLogRecData rdata[3];
int lastrdata = 0; int lastrdata = 0;
...@@ -1718,7 +1729,7 @@ RecordTransactionCommitPrepared(TransactionId xid, ...@@ -1718,7 +1729,7 @@ RecordTransactionCommitPrepared(TransactionId xid,
{ {
rdata[0].next = &(rdata[1]); rdata[0].next = &(rdata[1]);
rdata[1].data = (char *) rels; rdata[1].data = (char *) rels;
rdata[1].len = nrels * sizeof(RelFileFork); rdata[1].len = nrels * sizeof(RelFileNode);
rdata[1].buffer = InvalidBuffer; rdata[1].buffer = InvalidBuffer;
lastrdata = 1; lastrdata = 1;
} }
...@@ -1766,7 +1777,7 @@ RecordTransactionAbortPrepared(TransactionId xid, ...@@ -1766,7 +1777,7 @@ RecordTransactionAbortPrepared(TransactionId xid,
int nchildren, int nchildren,
TransactionId *children, TransactionId *children,
int nrels, int nrels,
RelFileFork *rels) RelFileNode *rels)
{ {
XLogRecData rdata[3]; XLogRecData rdata[3];
int lastrdata = 0; int lastrdata = 0;
...@@ -1796,7 +1807,7 @@ RecordTransactionAbortPrepared(TransactionId xid, ...@@ -1796,7 +1807,7 @@ RecordTransactionAbortPrepared(TransactionId xid,
{ {
rdata[0].next = &(rdata[1]); rdata[0].next = &(rdata[1]);
rdata[1].data = (char *) rels; rdata[1].data = (char *) rels;
rdata[1].len = nrels * sizeof(RelFileFork); rdata[1].len = nrels * sizeof(RelFileNode);
rdata[1].buffer = InvalidBuffer; rdata[1].buffer = InvalidBuffer;
lastrdata = 1; lastrdata = 1;
} }
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.268 2008/11/11 14:17:01 tgl Exp $ * $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.269 2008/11/19 10:34:50 heikki Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "access/xlogutils.h" #include "access/xlogutils.h"
#include "catalog/catalog.h" #include "catalog/catalog.h"
#include "catalog/namespace.h" #include "catalog/namespace.h"
#include "catalog/storage.h"
#include "commands/async.h" #include "commands/async.h"
#include "commands/tablecmds.h" #include "commands/tablecmds.h"
#include "commands/trigger.h" #include "commands/trigger.h"
...@@ -819,7 +820,7 @@ RecordTransactionCommit(void) ...@@ -819,7 +820,7 @@ RecordTransactionCommit(void)
bool markXidCommitted = TransactionIdIsValid(xid); bool markXidCommitted = TransactionIdIsValid(xid);
TransactionId latestXid = InvalidTransactionId; TransactionId latestXid = InvalidTransactionId;
int nrels; int nrels;
RelFileFork *rels; RelFileNode *rels;
bool haveNonTemp; bool haveNonTemp;
int nchildren; int nchildren;
TransactionId *children; TransactionId *children;
...@@ -900,7 +901,7 @@ RecordTransactionCommit(void) ...@@ -900,7 +901,7 @@ RecordTransactionCommit(void)
{ {
rdata[0].next = &(rdata[1]); rdata[0].next = &(rdata[1]);
rdata[1].data = (char *) rels; rdata[1].data = (char *) rels;
rdata[1].len = nrels * sizeof(RelFileFork); rdata[1].len = nrels * sizeof(RelFileNode);
rdata[1].buffer = InvalidBuffer; rdata[1].buffer = InvalidBuffer;
lastrdata = 1; lastrdata = 1;
} }
...@@ -1165,7 +1166,7 @@ RecordTransactionAbort(bool isSubXact) ...@@ -1165,7 +1166,7 @@ RecordTransactionAbort(bool isSubXact)
TransactionId xid = GetCurrentTransactionIdIfAny(); TransactionId xid = GetCurrentTransactionIdIfAny();
TransactionId latestXid; TransactionId latestXid;
int nrels; int nrels;
RelFileFork *rels; RelFileNode *rels;
int nchildren; int nchildren;
TransactionId *children; TransactionId *children;
XLogRecData rdata[3]; XLogRecData rdata[3];
...@@ -1226,7 +1227,7 @@ RecordTransactionAbort(bool isSubXact) ...@@ -1226,7 +1227,7 @@ RecordTransactionAbort(bool isSubXact)
{ {
rdata[0].next = &(rdata[1]); rdata[0].next = &(rdata[1]);
rdata[1].data = (char *) rels; rdata[1].data = (char *) rels;
rdata[1].len = nrels * sizeof(RelFileFork); rdata[1].len = nrels * sizeof(RelFileNode);
rdata[1].buffer = InvalidBuffer; rdata[1].buffer = InvalidBuffer;
lastrdata = 1; lastrdata = 1;
} }
...@@ -2078,7 +2079,6 @@ AbortTransaction(void) ...@@ -2078,7 +2079,6 @@ AbortTransaction(void)
AtEOXact_xml(); AtEOXact_xml();
AtEOXact_on_commit_actions(false); AtEOXact_on_commit_actions(false);
AtEOXact_Namespace(false); AtEOXact_Namespace(false);
smgrabort();
AtEOXact_Files(); AtEOXact_Files();
AtEOXact_ComboCid(); AtEOXact_ComboCid();
AtEOXact_HashTables(false); AtEOXact_HashTables(false);
...@@ -4239,12 +4239,17 @@ xact_redo_commit(xl_xact_commit *xlrec, TransactionId xid) ...@@ -4239,12 +4239,17 @@ xact_redo_commit(xl_xact_commit *xlrec, TransactionId xid)
/* Make sure files supposed to be dropped are dropped */ /* Make sure files supposed to be dropped are dropped */
for (i = 0; i < xlrec->nrels; i++) for (i = 0; i < xlrec->nrels; i++)
{ {
SMgrRelation srel; SMgrRelation srel = smgropen(xlrec->xnodes[i]);
ForkNumber fork;
XLogDropRelation(xlrec->xnodes[i].rnode, xlrec->xnodes[i].forknum); for (fork = 0; fork <= MAX_FORKNUM; fork++)
{
srel = smgropen(xlrec->xnodes[i].rnode); if (smgrexists(srel, fork))
smgrdounlink(srel, xlrec->xnodes[i].forknum, false, true); {
XLogDropRelation(xlrec->xnodes[i], fork);
smgrdounlink(srel, fork, false, true);
}
}
smgrclose(srel); smgrclose(srel);
} }
} }
...@@ -4277,12 +4282,17 @@ xact_redo_abort(xl_xact_abort *xlrec, TransactionId xid) ...@@ -4277,12 +4282,17 @@ xact_redo_abort(xl_xact_abort *xlrec, TransactionId xid)
/* Make sure files supposed to be dropped are dropped */ /* Make sure files supposed to be dropped are dropped */
for (i = 0; i < xlrec->nrels; i++) for (i = 0; i < xlrec->nrels; i++)
{ {
SMgrRelation srel; SMgrRelation srel = smgropen(xlrec->xnodes[i]);
ForkNumber fork;
XLogDropRelation(xlrec->xnodes[i].rnode, xlrec->xnodes[i].forknum); for (fork = 0; fork <= MAX_FORKNUM; fork++)
{
srel = smgropen(xlrec->xnodes[i].rnode); if (smgrexists(srel, fork))
smgrdounlink(srel, xlrec->xnodes[i].forknum, false, true); {
XLogDropRelation(xlrec->xnodes[i], fork);
smgrdounlink(srel, fork, false, true);
}
}
smgrclose(srel); smgrclose(srel);
} }
} }
...@@ -4339,8 +4349,7 @@ xact_desc_commit(StringInfo buf, xl_xact_commit *xlrec) ...@@ -4339,8 +4349,7 @@ xact_desc_commit(StringInfo buf, xl_xact_commit *xlrec)
appendStringInfo(buf, "; rels:"); appendStringInfo(buf, "; rels:");
for (i = 0; i < xlrec->nrels; i++) for (i = 0; i < xlrec->nrels; i++)
{ {
char *path = relpath(xlrec->xnodes[i].rnode, char *path = relpath(xlrec->xnodes[i], MAIN_FORKNUM);
xlrec->xnodes[i].forknum);
appendStringInfo(buf, " %s", path); appendStringInfo(buf, " %s", path);
pfree(path); pfree(path);
} }
...@@ -4367,8 +4376,7 @@ xact_desc_abort(StringInfo buf, xl_xact_abort *xlrec) ...@@ -4367,8 +4376,7 @@ xact_desc_abort(StringInfo buf, xl_xact_abort *xlrec)
appendStringInfo(buf, "; rels:"); appendStringInfo(buf, "; rels:");
for (i = 0; i < xlrec->nrels; i++) for (i = 0; i < xlrec->nrels; i++)
{ {
char *path = relpath(xlrec->xnodes[i].rnode, char *path = relpath(xlrec->xnodes[i], MAIN_FORKNUM);
xlrec->xnodes[i].forknum);
appendStringInfo(buf, " %s", path); appendStringInfo(buf, " %s", path);
pfree(path); pfree(path);
} }
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/backend/access/transam/xlogutils.c,v 1.62 2008/11/11 13:19:16 heikki Exp $ * $PostgreSQL: pgsql/src/backend/access/transam/xlogutils.c,v 1.63 2008/11/19 10:34:50 heikki Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -273,7 +273,7 @@ XLogReadBufferExtended(RelFileNode rnode, ForkNumber forknum, ...@@ -273,7 +273,7 @@ XLogReadBufferExtended(RelFileNode rnode, ForkNumber forknum,
* filesystem loses an inode during a crash. Better to write the data * filesystem loses an inode during a crash. Better to write the data
* until we are actually told to delete the file.) * until we are actually told to delete the file.)
*/ */
smgrcreate(smgr, forknum, false, true); smgrcreate(smgr, forknum, true);
lastblock = smgrnblocks(smgr, forknum); lastblock = smgrnblocks(smgr, forknum);
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# #
# Makefile for backend/catalog # Makefile for backend/catalog
# #
# $PostgreSQL: pgsql/src/backend/catalog/Makefile,v 1.66 2008/02/19 10:30:07 petere Exp $ # $PostgreSQL: pgsql/src/backend/catalog/Makefile,v 1.67 2008/11/19 10:34:51 heikki Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
...@@ -13,7 +13,7 @@ include $(top_builddir)/src/Makefile.global ...@@ -13,7 +13,7 @@ include $(top_builddir)/src/Makefile.global
OBJS = catalog.o dependency.o heap.o index.o indexing.o namespace.o aclchk.o \ OBJS = catalog.o dependency.o heap.o index.o indexing.o namespace.o aclchk.o \
pg_aggregate.o pg_constraint.o pg_conversion.o pg_depend.o pg_enum.o \ pg_aggregate.o pg_constraint.o pg_conversion.o pg_depend.o pg_enum.o \
pg_largeobject.o pg_namespace.o pg_operator.o pg_proc.o pg_shdepend.o \ pg_largeobject.o pg_namespace.o pg_operator.o pg_proc.o pg_shdepend.o \
pg_type.o toasting.o pg_type.o storage.o toasting.o
BKIFILES = postgres.bki postgres.description postgres.shdescription BKIFILES = postgres.bki postgres.description postgres.shdescription
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.344 2008/11/14 01:57:41 alvherre Exp $ * $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.345 2008/11/19 10:34:51 heikki Exp $
* *
* *
* INTERFACE ROUTINES * INTERFACE ROUTINES
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
#include "catalog/pg_tablespace.h" #include "catalog/pg_tablespace.h"
#include "catalog/pg_type.h" #include "catalog/pg_type.h"
#include "catalog/pg_type_fn.h" #include "catalog/pg_type_fn.h"
#include "catalog/storage.h"
#include "commands/tablecmds.h" #include "commands/tablecmds.h"
#include "commands/typecmds.h" #include "commands/typecmds.h"
#include "miscadmin.h" #include "miscadmin.h"
...@@ -295,22 +296,13 @@ heap_create(const char *relname, ...@@ -295,22 +296,13 @@ heap_create(const char *relname,
/* /*
* Have the storage manager create the relation's disk file, if needed. * Have the storage manager create the relation's disk file, if needed.
* *
* We create storage for the main fork here, and also for the FSM for a * We only create the main fork here, other forks will be created on
* heap or toast relation. The caller is responsible for creating any * demand.
* additional forks if needed.
*/ */
if (create_storage) if (create_storage)
{ {
Assert(rel->rd_smgr == NULL);
RelationOpenSmgr(rel); RelationOpenSmgr(rel);
smgrcreate(rel->rd_smgr, MAIN_FORKNUM, rel->rd_istemp, false); RelationCreateStorage(rel->rd_node, rel->rd_istemp);
/*
* For a real heap, create FSM fork as well. Indexams are
* responsible for creating any extra forks themselves.
*/
if (relkind == RELKIND_RELATION || relkind == RELKIND_TOASTVALUE)
smgrcreate(rel->rd_smgr, FSM_FORKNUM, rel->rd_istemp, false);
} }
return rel; return rel;
...@@ -1426,13 +1418,7 @@ heap_drop_with_catalog(Oid relid) ...@@ -1426,13 +1418,7 @@ heap_drop_with_catalog(Oid relid)
if (rel->rd_rel->relkind != RELKIND_VIEW && if (rel->rd_rel->relkind != RELKIND_VIEW &&
rel->rd_rel->relkind != RELKIND_COMPOSITE_TYPE) rel->rd_rel->relkind != RELKIND_COMPOSITE_TYPE)
{ {
ForkNumber forknum; RelationDropStorage(rel);
RelationOpenSmgr(rel);
for (forknum = 0; forknum <= MAX_FORKNUM; forknum++)
if (smgrexists(rel->rd_smgr, forknum))
smgrscheduleunlink(rel->rd_smgr, forknum, rel->rd_istemp);
RelationCloseSmgr(rel);
} }
/* /*
...@@ -2348,7 +2334,6 @@ heap_truncate(List *relids) ...@@ -2348,7 +2334,6 @@ heap_truncate(List *relids)
Relation rel = lfirst(cell); Relation rel = lfirst(cell);
/* Truncate the FSM and actual file (and discard buffers) */ /* Truncate the FSM and actual file (and discard buffers) */
FreeSpaceMapTruncateRel(rel, 0);
RelationTruncate(rel, 0); RelationTruncate(rel, 0);
/* If this relation has indexes, truncate the indexes too */ /* If this relation has indexes, truncate the indexes too */
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.309 2008/11/14 01:57:41 alvherre Exp $ * $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.310 2008/11/19 10:34:51 heikki Exp $
* *
* *
* INTERFACE ROUTINES * INTERFACE ROUTINES
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include "catalog/pg_opclass.h" #include "catalog/pg_opclass.h"
#include "catalog/pg_tablespace.h" #include "catalog/pg_tablespace.h"
#include "catalog/pg_type.h" #include "catalog/pg_type.h"
#include "catalog/storage.h"
#include "commands/tablecmds.h" #include "commands/tablecmds.h"
#include "executor/executor.h" #include "executor/executor.h"
#include "miscadmin.h" #include "miscadmin.h"
...@@ -897,7 +898,6 @@ index_drop(Oid indexId) ...@@ -897,7 +898,6 @@ index_drop(Oid indexId)
Relation indexRelation; Relation indexRelation;
HeapTuple tuple; HeapTuple tuple;
bool hasexprs; bool hasexprs;
ForkNumber forknum;
/* /*
* To drop an index safely, we must grab exclusive lock on its parent * To drop an index safely, we must grab exclusive lock on its parent
...@@ -918,12 +918,7 @@ index_drop(Oid indexId) ...@@ -918,12 +918,7 @@ index_drop(Oid indexId)
/* /*
* Schedule physical removal of the files * Schedule physical removal of the files
*/ */
RelationOpenSmgr(userIndexRelation); RelationDropStorage(userIndexRelation);
for (forknum = 0; forknum <= MAX_FORKNUM; forknum++)
if (smgrexists(userIndexRelation->rd_smgr, forknum))
smgrscheduleunlink(userIndexRelation->rd_smgr, forknum,
userIndexRelation->rd_istemp);
RelationCloseSmgr(userIndexRelation);
/* /*
* Close and flush the index's relcache entry, to ensure relcache doesn't * Close and flush the index's relcache entry, to ensure relcache doesn't
...@@ -1283,11 +1278,9 @@ setNewRelfilenode(Relation relation, TransactionId freezeXid) ...@@ -1283,11 +1278,9 @@ setNewRelfilenode(Relation relation, TransactionId freezeXid)
{ {
Oid newrelfilenode; Oid newrelfilenode;
RelFileNode newrnode; RelFileNode newrnode;
SMgrRelation srel;
Relation pg_class; Relation pg_class;
HeapTuple tuple; HeapTuple tuple;
Form_pg_class rd_rel; Form_pg_class rd_rel;
ForkNumber i;
/* Can't change relfilenode for nailed tables (indexes ok though) */ /* Can't change relfilenode for nailed tables (indexes ok though) */
Assert(!relation->rd_isnailed || Assert(!relation->rd_isnailed ||
...@@ -1318,8 +1311,6 @@ setNewRelfilenode(Relation relation, TransactionId freezeXid) ...@@ -1318,8 +1311,6 @@ setNewRelfilenode(Relation relation, TransactionId freezeXid)
RelationGetRelid(relation)); RelationGetRelid(relation));
rd_rel = (Form_pg_class) GETSTRUCT(tuple); rd_rel = (Form_pg_class) GETSTRUCT(tuple);
RelationOpenSmgr(relation);
/* /*
* ... and create storage for corresponding forks in the new relfilenode. * ... and create storage for corresponding forks in the new relfilenode.
* *
...@@ -1327,28 +1318,14 @@ setNewRelfilenode(Relation relation, TransactionId freezeXid) ...@@ -1327,28 +1318,14 @@ setNewRelfilenode(Relation relation, TransactionId freezeXid)
*/ */
newrnode = relation->rd_node; newrnode = relation->rd_node;
newrnode.relNode = newrelfilenode; newrnode.relNode = newrelfilenode;
srel = smgropen(newrnode);
/* Create the main fork, like heap_create() does */
smgrcreate(srel, MAIN_FORKNUM, relation->rd_istemp, false);
/* /*
* For a heap, create FSM fork as well. Indexams are responsible for * Create the main fork, like heap_create() does, and drop the old
* creating any extra forks themselves. * storage.
*/ */
if (relation->rd_rel->relkind == RELKIND_RELATION || RelationCreateStorage(newrnode, relation->rd_istemp);
relation->rd_rel->relkind == RELKIND_TOASTVALUE) smgrclosenode(newrnode);
smgrcreate(srel, FSM_FORKNUM, relation->rd_istemp, false); RelationDropStorage(relation);
/* schedule unlinking old files */
for (i = 0; i <= MAX_FORKNUM; i++)
{
if (smgrexists(relation->rd_smgr, i))
smgrscheduleunlink(relation->rd_smgr, i, relation->rd_istemp);
}
smgrclose(srel);
RelationCloseSmgr(relation);
/* update the pg_class row */ /* update the pg_class row */
rd_rel->relfilenode = newrelfilenode; rd_rel->relfilenode = newrelfilenode;
...@@ -2326,8 +2303,7 @@ reindex_index(Oid indexId) ...@@ -2326,8 +2303,7 @@ reindex_index(Oid indexId)
if (inplace) if (inplace)
{ {
/* /*
* Truncate the actual file (and discard buffers). The indexam * Truncate the actual file (and discard buffers).
* is responsible for truncating the FSM, if applicable
*/ */
RelationTruncate(iRel, 0); RelationTruncate(iRel, 0);
} }
......
This diff is collapsed.
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.270 2008/11/14 01:57:41 alvherre Exp $ * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.271 2008/11/19 10:34:51 heikki Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "catalog/pg_trigger.h" #include "catalog/pg_trigger.h"
#include "catalog/pg_type.h" #include "catalog/pg_type.h"
#include "catalog/pg_type_fn.h" #include "catalog/pg_type_fn.h"
#include "catalog/storage.h"
#include "catalog/toasting.h" #include "catalog/toasting.h"
#include "commands/cluster.h" #include "commands/cluster.h"
#include "commands/defrem.h" #include "commands/defrem.h"
...@@ -6567,22 +6568,26 @@ ATExecSetTableSpace(Oid tableOid, Oid newTableSpace) ...@@ -6567,22 +6568,26 @@ ATExecSetTableSpace(Oid tableOid, Oid newTableSpace)
* of old physical files. * of old physical files.
* *
* NOTE: any conflict in relfilenode value will be caught in * NOTE: any conflict in relfilenode value will be caught in
* smgrcreate() below. * RelationCreateStorage().
*/ */
for (forkNum = 0; forkNum <= MAX_FORKNUM; forkNum++) RelationCreateStorage(newrnode, rel->rd_istemp);
/* copy main fork */
copy_relation_data(rel->rd_smgr, dstrel, MAIN_FORKNUM, rel->rd_istemp);
/* copy those extra forks that exist */
for (forkNum = MAIN_FORKNUM + 1; forkNum <= MAX_FORKNUM; forkNum++)
{ {
if (smgrexists(rel->rd_smgr, forkNum)) if (smgrexists(rel->rd_smgr, forkNum))
{ {
smgrcreate(dstrel, forkNum, rel->rd_istemp, false); smgrcreate(dstrel, forkNum, false);
copy_relation_data(rel->rd_smgr, dstrel, forkNum, rel->rd_istemp); copy_relation_data(rel->rd_smgr, dstrel, forkNum, rel->rd_istemp);
smgrscheduleunlink(rel->rd_smgr, forkNum, rel->rd_istemp);
} }
} }
/* Close old and new relation */ /* drop old relation, and close new one */
RelationDropStorage(rel);
smgrclose(dstrel); smgrclose(dstrel);
RelationCloseSmgr(rel);
/* update the pg_class row */ /* update the pg_class row */
rd_rel->reltablespace = (newTableSpace == MyDatabaseTableSpace) ? InvalidOid : newTableSpace; rd_rel->reltablespace = (newTableSpace == MyDatabaseTableSpace) ? InvalidOid : newTableSpace;
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.380 2008/11/10 00:49:37 tgl Exp $ * $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.381 2008/11/19 10:34:51 heikki Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "catalog/namespace.h" #include "catalog/namespace.h"
#include "catalog/pg_database.h" #include "catalog/pg_database.h"
#include "catalog/pg_namespace.h" #include "catalog/pg_namespace.h"
#include "catalog/storage.h"
#include "commands/dbcommands.h" #include "commands/dbcommands.h"
#include "commands/vacuum.h" #include "commands/vacuum.h"
#include "executor/executor.h" #include "executor/executor.h"
...@@ -2863,7 +2864,6 @@ repair_frag(VRelStats *vacrelstats, Relation onerel, ...@@ -2863,7 +2864,6 @@ repair_frag(VRelStats *vacrelstats, Relation onerel,
/* Truncate relation, if needed */ /* Truncate relation, if needed */
if (blkno < nblocks) if (blkno < nblocks)
{ {
FreeSpaceMapTruncateRel(onerel, blkno);
RelationTruncate(onerel, blkno); RelationTruncate(onerel, blkno);
vacrelstats->rel_pages = blkno; /* set new number of blocks */ vacrelstats->rel_pages = blkno; /* set new number of blocks */
} }
...@@ -3258,7 +3258,6 @@ vacuum_heap(VRelStats *vacrelstats, Relation onerel, VacPageList vacuum_pages) ...@@ -3258,7 +3258,6 @@ vacuum_heap(VRelStats *vacrelstats, Relation onerel, VacPageList vacuum_pages)
(errmsg("\"%s\": truncated %u to %u pages", (errmsg("\"%s\": truncated %u to %u pages",
RelationGetRelationName(onerel), RelationGetRelationName(onerel),
vacrelstats->rel_pages, relblocks))); vacrelstats->rel_pages, relblocks)));
FreeSpaceMapTruncateRel(onerel, relblocks);
RelationTruncate(onerel, relblocks); RelationTruncate(onerel, relblocks);
vacrelstats->rel_pages = relblocks; /* set new number of blocks */ vacrelstats->rel_pages = relblocks; /* set new number of blocks */
} }
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.110 2008/11/10 00:49:37 tgl Exp $ * $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.111 2008/11/19 10:34:51 heikki Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include "access/genam.h" #include "access/genam.h"
#include "access/heapam.h" #include "access/heapam.h"
#include "access/transam.h" #include "access/transam.h"
#include "catalog/storage.h"
#include "commands/dbcommands.h" #include "commands/dbcommands.h"
#include "commands/vacuum.h" #include "commands/vacuum.h"
#include "miscadmin.h" #include "miscadmin.h"
...@@ -827,7 +828,6 @@ lazy_truncate_heap(Relation onerel, LVRelStats *vacrelstats) ...@@ -827,7 +828,6 @@ lazy_truncate_heap(Relation onerel, LVRelStats *vacrelstats)
/* /*
* Okay to truncate. * Okay to truncate.
*/ */
FreeSpaceMapTruncateRel(onerel, new_rel_pages);
RelationTruncate(onerel, new_rel_pages); RelationTruncate(onerel, new_rel_pages);
/* /*
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/rewrite/rewriteDefine.c,v 1.132 2008/11/09 21:24:32 tgl Exp $ * $PostgreSQL: pgsql/src/backend/rewrite/rewriteDefine.c,v 1.133 2008/11/19 10:34:52 heikki Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -19,13 +19,13 @@ ...@@ -19,13 +19,13 @@
#include "catalog/indexing.h" #include "catalog/indexing.h"
#include "catalog/namespace.h" #include "catalog/namespace.h"
#include "catalog/pg_rewrite.h" #include "catalog/pg_rewrite.h"
#include "catalog/storage.h"
#include "miscadmin.h" #include "miscadmin.h"
#include "nodes/nodeFuncs.h" #include "nodes/nodeFuncs.h"
#include "parser/parse_utilcmd.h" #include "parser/parse_utilcmd.h"
#include "rewrite/rewriteDefine.h" #include "rewrite/rewriteDefine.h"
#include "rewrite/rewriteManip.h" #include "rewrite/rewriteManip.h"
#include "rewrite/rewriteSupport.h" #include "rewrite/rewriteSupport.h"
#include "storage/smgr.h"
#include "utils/acl.h" #include "utils/acl.h"
#include "utils/builtins.h" #include "utils/builtins.h"
#include "utils/inval.h" #include "utils/inval.h"
...@@ -484,16 +484,7 @@ DefineQueryRewrite(char *rulename, ...@@ -484,16 +484,7 @@ DefineQueryRewrite(char *rulename,
* XXX what about getting rid of its TOAST table? For now, we don't. * XXX what about getting rid of its TOAST table? For now, we don't.
*/ */
if (RelisBecomingView) if (RelisBecomingView)
{ RelationDropStorage(event_relation);
ForkNumber forknum;
RelationOpenSmgr(event_relation);
for (forknum = 0; forknum <= MAX_FORKNUM; forknum++)
if (smgrexists(event_relation->rd_smgr, forknum))
smgrscheduleunlink(event_relation->rd_smgr, forknum,
event_relation->rd_istemp);
RelationCloseSmgr(event_relation);
}
/* Close rel, but keep lock till commit... */ /* Close rel, but keep lock till commit... */
heap_close(event_relation, NoLock); heap_close(event_relation, NoLock);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.241 2008/11/11 13:19:16 heikki Exp $ * $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.242 2008/11/19 10:34:52 heikki Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1695,8 +1695,6 @@ void ...@@ -1695,8 +1695,6 @@ void
BufmgrCommit(void) BufmgrCommit(void)
{ {
/* Nothing to do in bufmgr anymore... */ /* Nothing to do in bufmgr anymore... */
smgrcommit();
} }
/* /*
...@@ -1848,26 +1846,6 @@ RelationGetNumberOfBlocks(Relation relation) ...@@ -1848,26 +1846,6 @@ RelationGetNumberOfBlocks(Relation relation)
return smgrnblocks(relation->rd_smgr, MAIN_FORKNUM); return smgrnblocks(relation->rd_smgr, MAIN_FORKNUM);
} }
/*
* RelationTruncate
* Physically truncate a relation to the specified number of blocks.
*
* As of Postgres 8.1, this includes getting rid of any buffers for the
* blocks that are to be dropped; previously, callers had to do that.
*/
void
RelationTruncate(Relation rel, BlockNumber nblocks)
{
/* Open it at the smgr level if not already done */
RelationOpenSmgr(rel);
/* Make sure rd_targblock isn't pointing somewhere past end */
rel->rd_targblock = InvalidBlockNumber;
/* Do the real work */
smgrtruncate(rel->rd_smgr, MAIN_FORKNUM, nblocks, rel->rd_istemp);
}
/* --------------------------------------------------------------------- /* ---------------------------------------------------------------------
* DropRelFileNodeBuffers * DropRelFileNodeBuffers
* *
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/storage/freespace/freespace.c,v 1.66 2008/10/31 19:40:27 heikki Exp $ * $PostgreSQL: pgsql/src/backend/storage/freespace/freespace.c,v 1.67 2008/11/19 10:34:52 heikki Exp $
* *
* *
* NOTES: * NOTES:
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
* MaxFSMRequestSize depends on the architecture and BLCKSZ, but assuming * MaxFSMRequestSize depends on the architecture and BLCKSZ, but assuming
* default 8k BLCKSZ, and that MaxFSMRequestSize is 24 bytes, the categories * default 8k BLCKSZ, and that MaxFSMRequestSize is 24 bytes, the categories
* look like this * look like this
* *
* *
* Range Category * Range Category
* 0 - 31 0 * 0 - 31 0
...@@ -93,15 +93,6 @@ typedef struct ...@@ -93,15 +93,6 @@ typedef struct
/* Address of the root page. */ /* Address of the root page. */
static const FSMAddress FSM_ROOT_ADDRESS = { FSM_ROOT_LEVEL, 0 }; static const FSMAddress FSM_ROOT_ADDRESS = { FSM_ROOT_LEVEL, 0 };
/* XLOG record types */
#define XLOG_FSM_TRUNCATE 0x00 /* truncate */
typedef struct
{
RelFileNode node; /* truncated relation */
BlockNumber nheapblocks; /* new number of blocks in the heap */
} xl_fsm_truncate;
/* functions to navigate the tree */ /* functions to navigate the tree */
static FSMAddress fsm_get_child(FSMAddress parent, uint16 slot); static FSMAddress fsm_get_child(FSMAddress parent, uint16 slot);
static FSMAddress fsm_get_parent(FSMAddress child, uint16 *slot); static FSMAddress fsm_get_parent(FSMAddress child, uint16 *slot);
...@@ -110,7 +101,7 @@ static BlockNumber fsm_get_heap_blk(FSMAddress addr, uint16 slot); ...@@ -110,7 +101,7 @@ static BlockNumber fsm_get_heap_blk(FSMAddress addr, uint16 slot);
static BlockNumber fsm_logical_to_physical(FSMAddress addr); static BlockNumber fsm_logical_to_physical(FSMAddress addr);
static Buffer fsm_readbuf(Relation rel, FSMAddress addr, bool extend); static Buffer fsm_readbuf(Relation rel, FSMAddress addr, bool extend);
static void fsm_extend(Relation rel, BlockNumber nfsmblocks); static void fsm_extend(Relation rel, BlockNumber nfsmblocks, bool createstorage);
/* functions to convert amount of free space to a FSM category */ /* functions to convert amount of free space to a FSM category */
static uint8 fsm_space_avail_to_cat(Size avail); static uint8 fsm_space_avail_to_cat(Size avail);
...@@ -123,8 +114,6 @@ static int fsm_set_and_search(Relation rel, FSMAddress addr, uint16 slot, ...@@ -123,8 +114,6 @@ static int fsm_set_and_search(Relation rel, FSMAddress addr, uint16 slot,
static BlockNumber fsm_search(Relation rel, uint8 min_cat); static BlockNumber fsm_search(Relation rel, uint8 min_cat);
static uint8 fsm_vacuum_page(Relation rel, FSMAddress addr, bool *eof); static uint8 fsm_vacuum_page(Relation rel, FSMAddress addr, bool *eof);
static void fsm_redo_truncate(xl_fsm_truncate *xlrec);
/******** Public API ********/ /******** Public API ********/
...@@ -275,6 +264,13 @@ FreeSpaceMapTruncateRel(Relation rel, BlockNumber nblocks) ...@@ -275,6 +264,13 @@ FreeSpaceMapTruncateRel(Relation rel, BlockNumber nblocks)
RelationOpenSmgr(rel); RelationOpenSmgr(rel);
/*
* If no FSM has been created yet for this relation, there's nothing to
* truncate.
*/
if (!smgrexists(rel->rd_smgr, FSM_FORKNUM))
return;
/* Get the location in the FSM of the first removed heap block */ /* Get the location in the FSM of the first removed heap block */
first_removed_address = fsm_get_location(nblocks, &first_removed_slot); first_removed_address = fsm_get_location(nblocks, &first_removed_slot);
...@@ -306,43 +302,12 @@ FreeSpaceMapTruncateRel(Relation rel, BlockNumber nblocks) ...@@ -306,43 +302,12 @@ FreeSpaceMapTruncateRel(Relation rel, BlockNumber nblocks)
/* Truncate the unused FSM pages */ /* Truncate the unused FSM pages */
smgrtruncate(rel->rd_smgr, FSM_FORKNUM, new_nfsmblocks, rel->rd_istemp); smgrtruncate(rel->rd_smgr, FSM_FORKNUM, new_nfsmblocks, rel->rd_istemp);
/*
* FSM truncations are WAL-logged, because we must never return a block
* that doesn't exist in the heap, not even if we crash before the FSM
* truncation has made it to disk. smgrtruncate() writes its own WAL
* record, but that's not enough to zero out the last remaining FSM page.
* (if we didn't need to zero out anything above, we can skip this)
*/
if (!rel->rd_istemp && first_removed_slot != 0)
{
xl_fsm_truncate xlrec;
XLogRecData rdata;
XLogRecPtr recptr;
xlrec.node = rel->rd_node;
xlrec.nheapblocks = nblocks;
rdata.data = (char *) &xlrec;
rdata.len = sizeof(xl_fsm_truncate);
rdata.buffer = InvalidBuffer;
rdata.next = NULL;
recptr = XLogInsert(RM_FREESPACE_ID, XLOG_FSM_TRUNCATE, &rdata);
/*
* Flush, because otherwise the truncation of the main relation
* might hit the disk before the WAL record of truncating the
* FSM is flushed. If we crashed during that window, we'd be
* left with a truncated heap, without a truncated FSM.
*/
XLogFlush(recptr);
}
/* /*
* Need to invalidate the relcache entry, because rd_fsm_nblocks_cache * Need to invalidate the relcache entry, because rd_fsm_nblocks_cache
* seen by other backends is no longer valid. * seen by other backends is no longer valid.
*/ */
CacheInvalidateRelcache(rel); if (!InRecovery)
CacheInvalidateRelcache(rel);
rel->rd_fsm_nblocks_cache = new_nfsmblocks; rel->rd_fsm_nblocks_cache = new_nfsmblocks;
} }
...@@ -538,14 +503,19 @@ fsm_readbuf(Relation rel, FSMAddress addr, bool extend) ...@@ -538,14 +503,19 @@ fsm_readbuf(Relation rel, FSMAddress addr, bool extend)
RelationOpenSmgr(rel); RelationOpenSmgr(rel);
if (rel->rd_fsm_nblocks_cache == InvalidBlockNumber || if (rel->rd_fsm_nblocks_cache == InvalidBlockNumber ||
rel->rd_fsm_nblocks_cache <= blkno) rel->rd_fsm_nblocks_cache <= blkno)
rel->rd_fsm_nblocks_cache = smgrnblocks(rel->rd_smgr, FSM_FORKNUM); {
if (!smgrexists(rel->rd_smgr, FSM_FORKNUM))
fsm_extend(rel, blkno + 1, true);
else
rel->rd_fsm_nblocks_cache = smgrnblocks(rel->rd_smgr, FSM_FORKNUM);
}
if (blkno >= rel->rd_fsm_nblocks_cache) if (blkno >= rel->rd_fsm_nblocks_cache)
{ {
if (extend) if (extend)
fsm_extend(rel, blkno + 1); fsm_extend(rel, blkno + 1, false);
else else
return InvalidBuffer; return InvalidBuffer;
} }
...@@ -566,10 +536,11 @@ fsm_readbuf(Relation rel, FSMAddress addr, bool extend) ...@@ -566,10 +536,11 @@ fsm_readbuf(Relation rel, FSMAddress addr, bool extend)
/* /*
* Ensure that the FSM fork is at least n_fsmblocks long, extending * Ensure that the FSM fork is at least n_fsmblocks long, extending
* it if necessary with empty pages. And by empty, I mean pages filled * it if necessary with empty pages. And by empty, I mean pages filled
* with zeros, meaning there's no free space. * with zeros, meaning there's no free space. If createstorage is true,
* the FSM file might need to be created first.
*/ */
static void static void
fsm_extend(Relation rel, BlockNumber n_fsmblocks) fsm_extend(Relation rel, BlockNumber n_fsmblocks, bool createstorage)
{ {
BlockNumber n_fsmblocks_now; BlockNumber n_fsmblocks_now;
Page pg; Page pg;
...@@ -589,7 +560,15 @@ fsm_extend(Relation rel, BlockNumber n_fsmblocks) ...@@ -589,7 +560,15 @@ fsm_extend(Relation rel, BlockNumber n_fsmblocks)
*/ */
LockRelationForExtension(rel, ExclusiveLock); LockRelationForExtension(rel, ExclusiveLock);
n_fsmblocks_now = smgrnblocks(rel->rd_smgr, FSM_FORKNUM); /* Create the FSM file first if it doesn't exist */
if (createstorage && !smgrexists(rel->rd_smgr, FSM_FORKNUM))
{
smgrcreate(rel->rd_smgr, FSM_FORKNUM, false);
n_fsmblocks_now = 0;
}
else
n_fsmblocks_now = smgrnblocks(rel->rd_smgr, FSM_FORKNUM);
while (n_fsmblocks_now < n_fsmblocks) while (n_fsmblocks_now < n_fsmblocks)
{ {
smgrextend(rel->rd_smgr, FSM_FORKNUM, n_fsmblocks_now, smgrextend(rel->rd_smgr, FSM_FORKNUM, n_fsmblocks_now,
...@@ -799,75 +778,3 @@ fsm_vacuum_page(Relation rel, FSMAddress addr, bool *eof_p) ...@@ -799,75 +778,3 @@ fsm_vacuum_page(Relation rel, FSMAddress addr, bool *eof_p)
return max_avail; return max_avail;
} }
/****** WAL-logging ******/
static void
fsm_redo_truncate(xl_fsm_truncate *xlrec)
{
FSMAddress first_removed_address;
uint16 first_removed_slot;
BlockNumber fsmblk;
Buffer buf;
/* Get the location in the FSM of the first removed heap block */
first_removed_address = fsm_get_location(xlrec->nheapblocks,
&first_removed_slot);
fsmblk = fsm_logical_to_physical(first_removed_address);
/*
* Zero out the tail of the last remaining FSM page. We rely on the
* replay of the smgr truncation record to remove completely unused
* pages.
*/
buf = XLogReadBufferExtended(xlrec->node, FSM_FORKNUM, fsmblk,
RBM_ZERO_ON_ERROR);
if (BufferIsValid(buf))
{
Page page = BufferGetPage(buf);
if (PageIsNew(page))
PageInit(page, BLCKSZ, 0);
fsm_truncate_avail(page, first_removed_slot);
MarkBufferDirty(buf);
UnlockReleaseBuffer(buf);
}
}
void
fsm_redo(XLogRecPtr lsn, XLogRecord *record)
{
uint8 info = record->xl_info & ~XLR_INFO_MASK;
switch (info)
{
case XLOG_FSM_TRUNCATE:
fsm_redo_truncate((xl_fsm_truncate *) XLogRecGetData(record));
break;
default:
elog(PANIC, "fsm_redo: unknown op code %u", info);
}
}
void
fsm_desc(StringInfo buf, uint8 xl_info, char *rec)
{
uint8 info = xl_info & ~XLR_INFO_MASK;
switch (info)
{
case XLOG_FSM_TRUNCATE:
{
xl_fsm_truncate *xlrec = (xl_fsm_truncate *) rec;
appendStringInfo(buf, "truncate: rel %u/%u/%u; nheapblocks %u;",
xlrec->node.spcNode, xlrec->node.dbNode,
xlrec->node.relNode, xlrec->nheapblocks);
break;
}
default:
appendStringInfo(buf, "UNKNOWN");
break;
}
}
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/storage/freespace/indexfsm.c,v 1.2 2008/10/06 08:04:11 heikki Exp $ * $PostgreSQL: pgsql/src/backend/storage/freespace/indexfsm.c,v 1.3 2008/11/19 10:34:52 heikki Exp $
* *
* *
* NOTES: * NOTES:
...@@ -30,20 +30,6 @@ ...@@ -30,20 +30,6 @@
* Exported routines * Exported routines
*/ */
/*
* InitIndexFreeSpaceMap - Create or reset the FSM fork for relation.
*/
void
InitIndexFreeSpaceMap(Relation rel)
{
/* Create FSM fork if it doesn't exist yet, or truncate it if it does */
RelationOpenSmgr(rel);
if (!smgrexists(rel->rd_smgr, FSM_FORKNUM))
smgrcreate(rel->rd_smgr, FSM_FORKNUM, rel->rd_istemp, false);
else
smgrtruncate(rel->rd_smgr, FSM_FORKNUM, 0, rel->rd_istemp);
}
/* /*
* GetFreeIndexPage - return a free page from the FSM * GetFreeIndexPage - return a free page from the FSM
* *
...@@ -79,18 +65,6 @@ RecordUsedIndexPage(Relation rel, BlockNumber usedBlock) ...@@ -79,18 +65,6 @@ RecordUsedIndexPage(Relation rel, BlockNumber usedBlock)
RecordPageWithFreeSpace(rel, usedBlock, 0); RecordPageWithFreeSpace(rel, usedBlock, 0);
} }
/*
* IndexFreeSpaceMapTruncate - adjust for truncation of a relation.
*
* We need to delete any stored data past the new relation length, so that
* we don't bogusly return removed block numbers.
*/
void
IndexFreeSpaceMapTruncate(Relation rel, BlockNumber nblocks)
{
FreeSpaceMapTruncateRel(rel, nblocks);
}
/* /*
* IndexFreeSpaceMapVacuum - scan and fix any inconsistencies in the FSM * IndexFreeSpaceMapVacuum - scan and fix any inconsistencies in the FSM
*/ */
......
This diff is collapsed.
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Resource managers definition * Resource managers definition
* *
* $PostgreSQL: pgsql/src/include/access/rmgr.h,v 1.18 2008/09/30 10:52:13 heikki Exp $ * $PostgreSQL: pgsql/src/include/access/rmgr.h,v 1.19 2008/11/19 10:34:52 heikki Exp $
*/ */
#ifndef RMGR_H #ifndef RMGR_H
#define RMGR_H #define RMGR_H
...@@ -23,7 +23,6 @@ typedef uint8 RmgrId; ...@@ -23,7 +23,6 @@ typedef uint8 RmgrId;
#define RM_DBASE_ID 4 #define RM_DBASE_ID 4
#define RM_TBLSPC_ID 5 #define RM_TBLSPC_ID 5
#define RM_MULTIXACT_ID 6 #define RM_MULTIXACT_ID 6
#define RM_FREESPACE_ID 7
#define RM_HEAP2_ID 9 #define RM_HEAP2_ID 9
#define RM_HEAP_ID 10 #define RM_HEAP_ID 10
#define RM_BTREE_ID 11 #define RM_BTREE_ID 11
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/access/xact.h,v 1.95 2008/08/11 11:05:11 heikki Exp $ * $PostgreSQL: pgsql/src/include/access/xact.h,v 1.96 2008/11/19 10:34:52 heikki Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -88,10 +88,10 @@ typedef void (*SubXactCallback) (SubXactEvent event, SubTransactionId mySubid, ...@@ -88,10 +88,10 @@ typedef void (*SubXactCallback) (SubXactEvent event, SubTransactionId mySubid,
typedef struct xl_xact_commit typedef struct xl_xact_commit
{ {
TimestampTz xact_time; /* time of commit */ TimestampTz xact_time; /* time of commit */
int nrels; /* number of RelFileForks */ int nrels; /* number of RelFileNodes */
int nsubxacts; /* number of subtransaction XIDs */ int nsubxacts; /* number of subtransaction XIDs */
/* Array of RelFileFork(s) to drop at commit */ /* Array of RelFileNode(s) to drop at commit */
RelFileFork xnodes[1]; /* VARIABLE LENGTH ARRAY */ RelFileNode xnodes[1]; /* VARIABLE LENGTH ARRAY */
/* ARRAY OF COMMITTED SUBTRANSACTION XIDs FOLLOWS */ /* ARRAY OF COMMITTED SUBTRANSACTION XIDs FOLLOWS */
} xl_xact_commit; } xl_xact_commit;
...@@ -100,10 +100,10 @@ typedef struct xl_xact_commit ...@@ -100,10 +100,10 @@ typedef struct xl_xact_commit
typedef struct xl_xact_abort typedef struct xl_xact_abort
{ {
TimestampTz xact_time; /* time of abort */ TimestampTz xact_time; /* time of abort */
int nrels; /* number of RelFileForks */ int nrels; /* number of RelFileNodes */
int nsubxacts; /* number of subtransaction XIDs */ int nsubxacts; /* number of subtransaction XIDs */
/* Array of RelFileFork(s) to drop at abort */ /* Array of RelFileNode(s) to drop at abort */
RelFileFork xnodes[1]; /* VARIABLE LENGTH ARRAY */ RelFileNode xnodes[1]; /* VARIABLE LENGTH ARRAY */
/* ARRAY OF ABORTED SUBTRANSACTION XIDs FOLLOWS */ /* ARRAY OF ABORTED SUBTRANSACTION XIDs FOLLOWS */
} xl_xact_abort; } xl_xact_abort;
......
/*-------------------------------------------------------------------------
*
* storage.h
* prototypes for functions in backend/catalog/storage.c
*
*
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/include/catalog/storage.h,v 1.1 2008/11/19 10:34:52 heikki Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef STORAGE_H
#define STORAGE_H
#include "storage/block.h"
#include "storage/relfilenode.h"
#include "utils/rel.h"
extern void RelationCreateStorage(RelFileNode rnode, bool istemp);
extern void RelationDropStorage(Relation rel);
extern void RelationTruncate(Relation rel, BlockNumber nblocks);
/*
* These functions used to be in storage/smgr/smgr.c, which explains the
* naming
*/
extern void smgrDoPendingDeletes(bool isCommit);
extern int smgrGetPendingDeletes(bool forCommit, RelFileNode **ptr,
bool *haveNonTemp);
extern void AtSubCommit_smgr(void);
extern void AtSubAbort_smgr(void);
extern void PostPrepare_smgr(void);
extern void smgr_redo(XLogRecPtr lsn, XLogRecord *record);
extern void smgr_desc(StringInfo buf, uint8 xl_info, char *rec);
#endif /* STORAGE_H */
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/storage/bufmgr.h,v 1.117 2008/11/06 20:51:15 tgl Exp $ * $PostgreSQL: pgsql/src/include/storage/bufmgr.h,v 1.118 2008/11/19 10:34:52 heikki Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -176,7 +176,6 @@ extern void PrintBufferLeakWarning(Buffer buffer); ...@@ -176,7 +176,6 @@ extern void PrintBufferLeakWarning(Buffer buffer);
extern void CheckPointBuffers(int flags); extern void CheckPointBuffers(int flags);
extern BlockNumber BufferGetBlockNumber(Buffer buffer); extern BlockNumber BufferGetBlockNumber(Buffer buffer);
extern BlockNumber RelationGetNumberOfBlocks(Relation relation); extern BlockNumber RelationGetNumberOfBlocks(Relation relation);
extern void RelationTruncate(Relation rel, BlockNumber nblocks);
extern void FlushRelationBuffers(Relation rel); extern void FlushRelationBuffers(Relation rel);
extern void FlushDatabaseBuffers(Oid dbid); extern void FlushDatabaseBuffers(Oid dbid);
extern void DropRelFileNodeBuffers(RelFileNode rnode, ForkNumber forkNum, extern void DropRelFileNodeBuffers(RelFileNode rnode, ForkNumber forkNum,
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/storage/freespace.h,v 1.30 2008/10/31 19:40:27 heikki Exp $ * $PostgreSQL: pgsql/src/include/storage/freespace.h,v 1.31 2008/11/19 10:34:52 heikki Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -33,8 +33,4 @@ extern void XLogRecordPageWithFreeSpace(RelFileNode rnode, BlockNumber heapBlk, ...@@ -33,8 +33,4 @@ extern void XLogRecordPageWithFreeSpace(RelFileNode rnode, BlockNumber heapBlk,
extern void FreeSpaceMapTruncateRel(Relation rel, BlockNumber nblocks); extern void FreeSpaceMapTruncateRel(Relation rel, BlockNumber nblocks);
extern void FreeSpaceMapVacuum(Relation rel); extern void FreeSpaceMapVacuum(Relation rel);
/* WAL prototypes */
extern void fsm_desc(StringInfo buf, uint8 xl_info, char *rec);
extern void fsm_redo(XLogRecPtr lsn, XLogRecord *record);
#endif /* FREESPACE_H */ #endif /* FREESPACE_H */
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/storage/indexfsm.h,v 1.2 2008/10/06 08:04:11 heikki Exp $ * $PostgreSQL: pgsql/src/include/storage/indexfsm.h,v 1.3 2008/11/19 10:34:52 heikki Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -20,8 +20,6 @@ extern BlockNumber GetFreeIndexPage(Relation rel); ...@@ -20,8 +20,6 @@ extern BlockNumber GetFreeIndexPage(Relation rel);
extern void RecordFreeIndexPage(Relation rel, BlockNumber page); extern void RecordFreeIndexPage(Relation rel, BlockNumber page);
extern void RecordUsedIndexPage(Relation rel, BlockNumber page); extern void RecordUsedIndexPage(Relation rel, BlockNumber page);
extern void InitIndexFreeSpaceMap(Relation rel);
extern void IndexFreeSpaceMapTruncate(Relation rel, BlockNumber nblocks);
extern void IndexFreeSpaceMapVacuum(Relation rel); extern void IndexFreeSpaceMapVacuum(Relation rel);
#endif /* INDEXFSM_H */ #endif /* INDEXFSM_H */
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/storage/relfilenode.h,v 1.19 2008/10/06 14:13:17 heikki Exp $ * $PostgreSQL: pgsql/src/include/storage/relfilenode.h,v 1.20 2008/11/19 10:34:52 heikki Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -78,13 +78,4 @@ typedef struct RelFileNode ...@@ -78,13 +78,4 @@ typedef struct RelFileNode
(node1).dbNode == (node2).dbNode && \ (node1).dbNode == (node2).dbNode && \
(node1).spcNode == (node2).spcNode) (node1).spcNode == (node2).spcNode)
/*
* RelFileFork identifies a particular fork of a relation.
*/
typedef struct RelFileFork
{
RelFileNode rnode;
ForkNumber forknum;
} RelFileFork;
#endif /* RELFILENODE_H */ #endif /* RELFILENODE_H */
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/storage/smgr.h,v 1.63 2008/08/11 11:05:11 heikki Exp $ * $PostgreSQL: pgsql/src/include/storage/smgr.h,v 1.64 2008/11/19 10:34:52 heikki Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -65,10 +65,7 @@ extern void smgrsetowner(SMgrRelation *owner, SMgrRelation reln); ...@@ -65,10 +65,7 @@ extern void smgrsetowner(SMgrRelation *owner, SMgrRelation reln);
extern void smgrclose(SMgrRelation reln); extern void smgrclose(SMgrRelation reln);
extern void smgrcloseall(void); extern void smgrcloseall(void);
extern void smgrclosenode(RelFileNode rnode); extern void smgrclosenode(RelFileNode rnode);
extern void smgrcreate(SMgrRelation reln, ForkNumber forknum, extern void smgrcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo);
bool isTemp, bool isRedo);
extern void smgrscheduleunlink(SMgrRelation reln, ForkNumber forknum,
bool isTemp);
extern void smgrdounlink(SMgrRelation reln, ForkNumber forknum, extern void smgrdounlink(SMgrRelation reln, ForkNumber forknum,
bool isTemp, bool isRedo); bool isTemp, bool isRedo);
extern void smgrextend(SMgrRelation reln, ForkNumber forknum, extern void smgrextend(SMgrRelation reln, ForkNumber forknum,
...@@ -81,21 +78,10 @@ extern BlockNumber smgrnblocks(SMgrRelation reln, ForkNumber forknum); ...@@ -81,21 +78,10 @@ extern BlockNumber smgrnblocks(SMgrRelation reln, ForkNumber forknum);
extern void smgrtruncate(SMgrRelation reln, ForkNumber forknum, extern void smgrtruncate(SMgrRelation reln, ForkNumber forknum,
BlockNumber nblocks, bool isTemp); BlockNumber nblocks, bool isTemp);
extern void smgrimmedsync(SMgrRelation reln, ForkNumber forknum); extern void smgrimmedsync(SMgrRelation reln, ForkNumber forknum);
extern void smgrDoPendingDeletes(bool isCommit);
extern int smgrGetPendingDeletes(bool forCommit, RelFileFork **ptr,
bool *haveNonTemp);
extern void AtSubCommit_smgr(void);
extern void AtSubAbort_smgr(void);
extern void PostPrepare_smgr(void);
extern void smgrcommit(void);
extern void smgrabort(void);
extern void smgrpreckpt(void); extern void smgrpreckpt(void);
extern void smgrsync(void); extern void smgrsync(void);
extern void smgrpostckpt(void); extern void smgrpostckpt(void);
extern void smgr_redo(XLogRecPtr lsn, XLogRecord *record);
extern void smgr_desc(StringInfo buf, uint8 xl_info, char *rec);
/* internals: move me elsewhere -- ay 7/94 */ /* internals: move me elsewhere -- ay 7/94 */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment