diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2004-02-10 01:55:27 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2004-02-10 01:55:27 +0000 |
commit | 87bd95638552b8fc1f5f787ce5b862bb6fc2eb80 (patch) | |
tree | b2b98d5a934750a9ee791992120343b109dac31d /src/include | |
parent | f06e79525a57ccbf54ae5d0b673cd904ca978d67 (diff) | |
download | postgresql-87bd95638552b8fc1f5f787ce5b862bb6fc2eb80.tar.gz |
Restructure smgr API as per recent proposal. smgr no longer depends on
the relcache, and so the notion of 'blind write' is gone. This should
improve efficiency in bgwriter and background checkpoint processes.
Internal restructuring in md.c to remove the not-very-useful array of
MdfdVec objects --- might as well just use pointers.
Also remove the long-dead 'persistent main memory' storage manager (mm.c),
since it seems quite unlikely to ever get resurrected.
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/catalog/pg_database.h | 11 | ||||
-rw-r--r-- | src/include/storage/sinval.h | 16 | ||||
-rw-r--r-- | src/include/storage/smgr.h | 114 | ||||
-rw-r--r-- | src/include/utils/inval.h | 6 | ||||
-rw-r--r-- | src/include/utils/rel.h | 19 | ||||
-rw-r--r-- | src/include/utils/relcache.h | 10 |
6 files changed, 83 insertions, 93 deletions
diff --git a/src/include/catalog/pg_database.h b/src/include/catalog/pg_database.h index af113eb66a..226c5c2f99 100644 --- a/src/include/catalog/pg_database.h +++ b/src/include/catalog/pg_database.h @@ -8,7 +8,7 @@ * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/catalog/pg_database.h,v 1.30 2003/11/29 22:40:58 pgsql Exp $ + * $PostgreSQL: pgsql/src/include/catalog/pg_database.h,v 1.31 2004/02/10 01:55:26 tgl Exp $ * * NOTES * the genbki.sh script reads this file and generates .bki @@ -72,15 +72,6 @@ typedef FormData_pg_database *Form_pg_database; DATA(insert OID = 1 ( template1 PGUID ENCODING t t 0 0 0 "" _null_ _null_ )); DESCR("Default template database"); - #define TemplateDbOid 1 -/* Just to mark OID as used for unused_oid script -:) */ -#define DATAMARKOID(x) - -DATAMARKOID(= 2) -#define RecoveryDb 2 - -#undef DATAMARKOID - #endif /* PG_DATABASE_H */ diff --git a/src/include/storage/sinval.h b/src/include/storage/sinval.h index a0b523da3d..84706272de 100644 --- a/src/include/storage/sinval.h +++ b/src/include/storage/sinval.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/storage/sinval.h,v 1.32 2003/11/29 22:41:13 pgsql Exp $ + * $PostgreSQL: pgsql/src/include/storage/sinval.h,v 1.33 2004/02/10 01:55:26 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -16,6 +16,7 @@ #include "storage/backendid.h" #include "storage/itemptr.h" +#include "storage/relfilenode.h" /* @@ -27,6 +28,13 @@ * ID field). -1 means a relcache inval message. Other negative values * are available to identify other inval message types. * + * Relcache invalidation messages usually also cause invalidation of entries + * in the smgr's relation cache. This means they must carry both logical + * and physical relation ID info (ie, both dbOID/relOID and RelFileNode). + * In some cases RelFileNode information is not available so the sender fills + * those fields with zeroes --- this is okay so long as no smgr cache flush + * is required. + * * Shared-inval events are initially driven by detecting tuple inserts, * updates and deletions in system catalogs (see CacheInvalidateHeapTuple). * An update generates two inval events, one for the old tuple and one for @@ -63,6 +71,12 @@ typedef struct int16 id; /* type field --- must be first */ Oid dbId; /* database ID, or 0 if a shared relation */ Oid relId; /* relation ID */ + RelFileNode physId; /* physical file ID */ + /* + * Note: it is likely that RelFileNode will someday be changed to + * include database ID. In that case the dbId field will be redundant + * and should be removed to save space. + */ } SharedInvalRelcacheMsg; typedef union diff --git a/src/include/storage/smgr.h b/src/include/storage/smgr.h index 0fd20fd436..738e436fb7 100644 --- a/src/include/storage/smgr.h +++ b/src/include/storage/smgr.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/storage/smgr.h,v 1.39 2003/11/29 22:41:13 pgsql Exp $ + * $PostgreSQL: pgsql/src/include/storage/smgr.h,v 1.40 2004/02/10 01:55:26 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -16,36 +16,54 @@ #include "access/xlog.h" #include "fmgr.h" -#include "storage/relfilenode.h" #include "storage/block.h" -#include "utils/rel.h" +#include "storage/relfilenode.h" + + +/* + * smgr.c maintains a table of SMgrRelation objects, which are essentially + * cached file handles. An SMgrRelation is created (if not already present) + * by smgropen(), and destroyed by smgrclose(). Note that neither of these + * operations imply I/O, they just create or destroy a hashtable entry. + * (But smgrclose() may release associated resources, such as OS-level file + * descriptors.) + */ +typedef struct SMgrRelationData +{ + /* rnode is the hashtable lookup key, so it must be first! */ + RelFileNode smgr_rnode; /* relation physical identifier */ + /* additional public fields may someday exist here */ -#define SM_FAIL 0 -#define SM_SUCCESS 1 + /* + * Fields below here are intended to be private to smgr.c and its + * submodules. Do not touch them from elsewhere. + */ + int smgr_which; /* storage manager selector */ -#define DEFAULT_SMGR 0 + struct _MdfdVec *md_fd; /* for md.c; NULL if not open */ +} SMgrRelationData; -extern int smgrinit(void); -extern int smgrcreate(int16 which, Relation reln); -extern int smgrunlink(int16 which, Relation reln); -extern int smgrextend(int16 which, Relation reln, BlockNumber blocknum, - char *buffer); -extern int smgropen(int16 which, Relation reln, bool failOK); -extern int smgrclose(int16 which, Relation reln); -extern int smgrread(int16 which, Relation reln, BlockNumber blocknum, - char *buffer); -extern int smgrwrite(int16 which, Relation reln, BlockNumber blocknum, - char *buffer); -extern int smgrblindwrt(int16 which, RelFileNode rnode, - BlockNumber blkno, char *buffer); -extern BlockNumber smgrnblocks(int16 which, Relation reln); -extern BlockNumber smgrtruncate(int16 which, Relation reln, - BlockNumber nblocks); -extern int smgrDoPendingDeletes(bool isCommit); -extern int smgrcommit(void); -extern int smgrabort(void); -extern int smgrsync(void); +typedef SMgrRelationData *SMgrRelation; + + +extern void smgrinit(void); +extern SMgrRelation smgropen(RelFileNode rnode); +extern void smgrclose(SMgrRelation reln); +extern void smgrcloseall(void); +extern void smgrclosenode(RelFileNode rnode); +extern void smgrcreate(SMgrRelation reln, bool isTemp, bool isRedo); +extern void smgrscheduleunlink(SMgrRelation reln, bool isTemp); +extern void smgrdounlink(SMgrRelation reln, bool isTemp, bool isRedo); +extern void smgrextend(SMgrRelation reln, BlockNumber blocknum, char *buffer); +extern void smgrread(SMgrRelation reln, BlockNumber blocknum, char *buffer); +extern void smgrwrite(SMgrRelation reln, BlockNumber blocknum, char *buffer); +extern BlockNumber smgrnblocks(SMgrRelation reln); +extern BlockNumber smgrtruncate(SMgrRelation reln, BlockNumber nblocks); +extern void smgrDoPendingDeletes(bool isCommit); +extern void smgrcommit(void); +extern void smgrabort(void); +extern void smgrsync(void); extern void smgr_redo(XLogRecPtr lsn, XLogRecord *record); extern void smgr_undo(XLogRecPtr lsn, XLogRecord *record); @@ -55,38 +73,18 @@ extern void smgr_desc(char *buf, uint8 xl_info, char *rec); /* internals: move me elsewhere -- ay 7/94 */ /* in md.c */ -extern int mdinit(void); -extern int mdcreate(Relation reln); -extern int mdunlink(RelFileNode rnode); -extern int mdextend(Relation reln, BlockNumber blocknum, char *buffer); -extern int mdopen(Relation reln); -extern int mdclose(Relation reln); -extern int mdread(Relation reln, BlockNumber blocknum, char *buffer); -extern int mdwrite(Relation reln, BlockNumber blocknum, char *buffer); -extern int mdblindwrt(RelFileNode rnode, BlockNumber blkno, char *buffer); -extern BlockNumber mdnblocks(Relation reln); -extern BlockNumber mdtruncate(Relation reln, BlockNumber nblocks); -extern int mdcommit(void); -extern int mdabort(void); -extern int mdsync(void); - -/* mm.c */ -extern int mminit(void); -extern int mmcreate(Relation reln); -extern int mmunlink(RelFileNode rnode); -extern int mmextend(Relation reln, BlockNumber blocknum, char *buffer); -extern int mmopen(Relation reln); -extern int mmclose(Relation reln); -extern int mmread(Relation reln, BlockNumber blocknum, char *buffer); -extern int mmwrite(Relation reln, BlockNumber blocknum, char *buffer); -extern int mmblindwrt(RelFileNode rnode, BlockNumber blkno, char *buffer); -extern BlockNumber mmnblocks(Relation reln); -extern BlockNumber mmtruncate(Relation reln, BlockNumber nblocks); -extern int mmcommit(void); -extern int mmabort(void); - -extern int mmshutdown(void); -extern int MMShmemSize(void); +extern bool mdinit(void); +extern bool mdclose(SMgrRelation reln); +extern bool mdcreate(SMgrRelation reln, bool isRedo); +extern bool mdunlink(RelFileNode rnode, bool isRedo); +extern bool mdextend(SMgrRelation reln, BlockNumber blocknum, char *buffer); +extern bool mdread(SMgrRelation reln, BlockNumber blocknum, char *buffer); +extern bool mdwrite(SMgrRelation reln, BlockNumber blocknum, char *buffer); +extern BlockNumber mdnblocks(SMgrRelation reln); +extern BlockNumber mdtruncate(SMgrRelation reln, BlockNumber nblocks); +extern bool mdcommit(void); +extern bool mdabort(void); +extern bool mdsync(void); /* smgrtype.c */ extern Datum smgrout(PG_FUNCTION_ARGS); diff --git a/src/include/utils/inval.h b/src/include/utils/inval.h index 467d15ee83..e7052726f2 100644 --- a/src/include/utils/inval.h +++ b/src/include/utils/inval.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/utils/inval.h,v 1.29 2003/11/29 22:41:15 pgsql Exp $ + * $PostgreSQL: pgsql/src/include/utils/inval.h,v 1.30 2004/02/10 01:55:26 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -28,7 +28,9 @@ extern void CommandEndInvalidationMessages(bool isCommit); extern void CacheInvalidateHeapTuple(Relation relation, HeapTuple tuple); -extern void CacheInvalidateRelcache(Oid relationId); +extern void CacheInvalidateRelcache(Relation relation); + +extern void CacheInvalidateRelcacheByTuple(HeapTuple classTuple); extern void CacheRegisterSyscacheCallback(int cacheid, CacheCallbackFunction func, diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index dfdb8491e3..8532c5a737 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/utils/rel.h,v 1.72 2004/01/06 18:07:32 neilc Exp $ + * $PostgreSQL: pgsql/src/include/utils/rel.h,v 1.73 2004/02/10 01:55:27 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -20,7 +20,6 @@ #include "catalog/pg_index.h" #include "rewrite/prs2lock.h" #include "storage/block.h" -#include "storage/fd.h" #include "storage/relfilenode.h" @@ -98,16 +97,16 @@ typedef struct PgStat_Info bool index_scan_counted; } PgStat_Info; + /* * Here are the contents of a relation cache entry. */ typedef struct RelationData { - File rd_fd; /* open file descriptor, or -1 if - * none; this is NOT an operating - * system file descriptor */ - RelFileNode rd_node; /* file node (physical identifier) */ + 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_nblocks; /* number of blocks in rel */ BlockNumber rd_targblock; /* current insertion target block, or * InvalidBlockNumber */ @@ -227,14 +226,6 @@ typedef Relation *RelationPtr; #define RelationGetRelid(relation) ((relation)->rd_id) /* - * RelationGetFile - * Returns the open file descriptor for the rel, or -1 if - * none. This is NOT an operating system file descriptor; see md.c - * for more information - */ -#define RelationGetFile(relation) ((relation)->rd_fd) - -/* * RelationGetNumberOfAttributes * Returns the number of attributes in a relation. */ diff --git a/src/include/utils/relcache.h b/src/include/utils/relcache.h index c7c6a9231f..848d68b207 100644 --- a/src/include/utils/relcache.h +++ b/src/include/utils/relcache.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/utils/relcache.h,v 1.38 2003/11/29 22:41:16 pgsql Exp $ + * $PostgreSQL: pgsql/src/include/utils/relcache.h,v 1.39 2004/02/10 01:55:27 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -24,7 +24,6 @@ extern Relation RelationSysNameGetRelation(const char *relationName); /* finds an existing cache entry, but won't make a new one */ extern Relation RelationIdCacheGetRelation(Oid relationId); -extern Relation RelationNodeCacheGetRelation(RelFileNode rnode); extern void RelationClose(Relation relation); @@ -61,7 +60,7 @@ extern Relation RelationBuildLocalRelation(const char *relname, */ extern void RelationForgetRelation(Oid rid); -extern void RelationIdInvalidateRelationCacheByRelationId(Oid relationId); +extern void RelationCacheInvalidateEntry(Oid relationId, RelFileNode *rnode); extern void RelationCacheInvalidate(void); @@ -73,11 +72,6 @@ extern void AtEOXact_RelationCache(bool commit); extern bool RelationIdIsInInitFile(Oid relationId); extern void RelationCacheInitFileInvalidate(bool beforeSend); -/* XLOG support */ -extern void CreateDummyCaches(void); -extern void DestroyDummyCaches(void); - - /* should be used only by relcache.c and catcache.c */ extern bool criticalRelcachesBuilt; |