summaryrefslogtreecommitdiff
path: root/src/include/utils/rel.h
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2010-02-09 21:43:30 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2010-02-09 21:43:30 +0000
commitcbe9d6beb4ae1cb20c08cab29b534be4923b6768 (patch)
treea9476492cd8c7eda7718f95b0ad5a45d41e55a3a /src/include/utils/rel.h
parent79647eed86cc972e80ea165dcb0b7f6fef876169 (diff)
Fix up rickety handling of relation-truncation interlocks.
Move rd_targblock, rd_fsm_nblocks, and rd_vm_nblocks from relcache to the smgr relation entries, so that they will get reset to InvalidBlockNumber whenever an smgr-level flush happens. Because we now send smgr invalidation messages immediately (not at end of transaction) when a relation truncation occurs, this ensures that other backends will reset their values before they next access the relation. We no longer need the unreliable assumption that a VACUUM that's doing a truncation will hold its AccessExclusive lock until commit --- in fact, we can intentionally release that lock as soon as we've completed the truncation. This patch therefore reverts (most of) Alvaro's patch of 2009-11-10, as well as my marginal hacking on it yesterday. We can also get rid of assorted no-longer-needed relcache flushes, which are far more expensive than an smgr flush because they kill a lot more state. In passing this patch fixes smgr_redo's failure to perform visibility-map truncation, and cleans up some rather dubious assumptions in freespace.c and visibilitymap.c about when rd_fsm_nblocks and rd_vm_nblocks can be out of date.
Diffstat (limited to 'src/include/utils/rel.h')
-rw-r--r--src/include/utils/rel.h31
1 files changed, 21 insertions, 10 deletions
diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h
index c4a1fcf7b64..405ff18e0ba 100644
--- a/src/include/utils/rel.h
+++ b/src/include/utils/rel.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/utils/rel.h,v 1.122 2010/02/07 20:48:13 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/utils/rel.h,v 1.123 2010/02/09 21:43:30 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -125,8 +125,6 @@ typedef struct RelationData
RelFileNode rd_node; /* relation physical identifier */
/* use "struct" here to avoid needing to include smgr.h: */
struct SMgrRelationData *rd_smgr; /* cached file handle, or NULL */
- BlockNumber rd_targblock; /* current insertion target block, or
- * InvalidBlockNumber */
int rd_refcnt; /* reference count */
bool rd_istemp; /* rel is a temporary relation */
bool rd_islocaltemp; /* rel is a temp rel of this session */
@@ -212,13 +210,6 @@ typedef struct RelationData
*/
Oid rd_toastoid; /* Real TOAST table's OID, or InvalidOid */
- /*
- * sizes of the free space and visibility map forks, or InvalidBlockNumber
- * if not known yet
- */
- BlockNumber rd_fsm_nblocks;
- BlockNumber rd_vm_nblocks;
-
/* use "struct" here to avoid needing to include pgstat.h: */
struct PgStat_TableStatus *pgstat_info; /* statistics collection area */
} RelationData;
@@ -375,6 +366,26 @@ typedef struct StdRdOptions
} while (0)
/*
+ * RelationGetTargetBlock
+ * Fetch relation's current insertion target block.
+ *
+ * Returns InvalidBlockNumber if there is no current target block. Note
+ * that the target block status is discarded on any smgr-level invalidation.
+ */
+#define RelationGetTargetBlock(relation) \
+ ( (relation)->rd_smgr != NULL ? (relation)->rd_smgr->smgr_targblock : InvalidBlockNumber )
+
+/*
+ * RelationSetTargetBlock
+ * Set relation's current insertion target block.
+ */
+#define RelationSetTargetBlock(relation, targblock) \
+ do { \
+ RelationOpenSmgr(relation); \
+ (relation)->rd_smgr->smgr_targblock = (targblock); \
+ } while (0)
+
+/*
* RELATION_IS_LOCAL
* If a rel is either temp or newly created in the current transaction,
* it can be assumed to be visible only to the current backend.