Code cleanup, mostly in the smgr:
- Update comment in IsReservedName() to the present day - Improve some variable & function names in commands/vacuum.c. I was planning to rewrite this to avoid lappend(), but since I still intend to do the list rewrite, there's no need for that. - Update some smgr comments which seemed to imply that we still forced all dirty pages to disk at commit-time. - Replace some #ifdef DIAGNOSTIC code with assertions. - Make the distinction between OS-level file descriptors and virtual file descriptors a little clearer in a few comments - Other minor comment improvements in the smgr code
This commit is contained in:
parent
030f8e7313
commit
dfc7e7b71d
@ -9,7 +9,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/catalog/catalog.c,v 1.50 2003/11/29 19:51:42 pgsql Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/catalog/catalog.c,v 1.51 2004/01/06 18:07:31 neilc Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -165,8 +165,9 @@ IsToastNamespace(Oid namespaceId)
|
||||
* IsReservedName
|
||||
* True iff name starts with the pg_ prefix.
|
||||
*
|
||||
* For some classes of objects, the prefix pg_ is reserved
|
||||
* for system objects only.
|
||||
* For some classes of objects, the prefix pg_ is reserved for
|
||||
* system objects only. As of 7.3, this is now only true for
|
||||
* schema names.
|
||||
*/
|
||||
bool
|
||||
IsReservedName(const char *name)
|
||||
|
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.65 2003/11/29 19:51:47 pgsql Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.66 2004/01/06 18:07:31 neilc Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -204,8 +204,9 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt)
|
||||
}
|
||||
|
||||
/*
|
||||
* Check that it's a plain table; we used to do this in getrels() but
|
||||
* seems safer to check after we've locked the relation.
|
||||
* Check that it's a plain table; we used to do this in
|
||||
* get_rel_oids() but seems safer to check after we've locked the
|
||||
* relation.
|
||||
*/
|
||||
if (onerel->rd_rel->relkind != RELKIND_RELATION)
|
||||
{
|
||||
|
@ -13,7 +13,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.269 2003/11/29 19:51:47 pgsql Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.270 2004/01/06 18:07:31 neilc Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -108,7 +108,7 @@ static TransactionId FreezeLimit;
|
||||
|
||||
|
||||
/* non-export function prototypes */
|
||||
static List *getrels(const RangeVar *vacrel, const char *stmttype);
|
||||
static List *get_rel_oids(const RangeVar *vacrel, const char *stmttype);
|
||||
static void vac_update_dbstats(Oid dbid,
|
||||
TransactionId vacuumXID,
|
||||
TransactionId frozenXID);
|
||||
@ -161,7 +161,7 @@ vacuum(VacuumStmt *vacstmt)
|
||||
TransactionId initialOldestXmin = InvalidTransactionId;
|
||||
TransactionId initialFreezeLimit = InvalidTransactionId;
|
||||
bool all_rels;
|
||||
List *vrl,
|
||||
List *relations,
|
||||
*cur;
|
||||
|
||||
if (vacstmt->verbose)
|
||||
@ -216,7 +216,7 @@ vacuum(VacuumStmt *vacstmt)
|
||||
all_rels = (vacstmt->relation == NULL);
|
||||
|
||||
/* Build list of relations to process (note this lives in vac_context) */
|
||||
vrl = getrels(vacstmt->relation, stmttype);
|
||||
relations = get_rel_oids(vacstmt->relation, stmttype);
|
||||
|
||||
/*
|
||||
* Formerly, there was code here to prevent more than one VACUUM from
|
||||
@ -282,7 +282,7 @@ vacuum(VacuumStmt *vacstmt)
|
||||
/*
|
||||
* Loop to process each selected relation.
|
||||
*/
|
||||
foreach(cur, vrl)
|
||||
foreach(cur, relations)
|
||||
{
|
||||
Oid relid = lfirsto(cur);
|
||||
|
||||
@ -383,21 +383,21 @@ vacuum(VacuumStmt *vacstmt)
|
||||
* per-relation transactions.
|
||||
*/
|
||||
static List *
|
||||
getrels(const RangeVar *vacrel, const char *stmttype)
|
||||
get_rel_oids(const RangeVar *vacrel, const char *stmttype)
|
||||
{
|
||||
List *vrl = NIL;
|
||||
List *oid_list = NIL;
|
||||
MemoryContext oldcontext;
|
||||
|
||||
if (vacrel)
|
||||
{
|
||||
/* Process specific relation */
|
||||
/* Process a specific relation */
|
||||
Oid relid;
|
||||
|
||||
relid = RangeVarGetRelid(vacrel, false);
|
||||
|
||||
/* Make a relation list entry for this guy */
|
||||
oldcontext = MemoryContextSwitchTo(vac_context);
|
||||
vrl = lappendo(vrl, relid);
|
||||
oid_list = lappendo(oid_list, relid);
|
||||
MemoryContextSwitchTo(oldcontext);
|
||||
}
|
||||
else
|
||||
@ -421,7 +421,7 @@ getrels(const RangeVar *vacrel, const char *stmttype)
|
||||
{
|
||||
/* Make a relation list entry for this guy */
|
||||
oldcontext = MemoryContextSwitchTo(vac_context);
|
||||
vrl = lappendo(vrl, HeapTupleGetOid(tuple));
|
||||
oid_list = lappendo(oid_list, HeapTupleGetOid(tuple));
|
||||
MemoryContextSwitchTo(oldcontext);
|
||||
}
|
||||
|
||||
@ -429,7 +429,7 @@ getrels(const RangeVar *vacrel, const char *stmttype)
|
||||
heap_close(pgclass, AccessShareLock);
|
||||
}
|
||||
|
||||
return vrl;
|
||||
return oid_list;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -818,8 +818,9 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind)
|
||||
}
|
||||
|
||||
/*
|
||||
* Check that it's a plain table; we used to do this in getrels() but
|
||||
* seems safer to check after we've locked the relation.
|
||||
* Check that it's a plain table; we used to do this in
|
||||
* get_rel_oids() but seems safer to check after we've locked the
|
||||
* relation.
|
||||
*/
|
||||
if (onerel->rd_rel->relkind != expected_relkind)
|
||||
{
|
||||
|
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/storage/smgr/md.c,v 1.99 2003/11/29 19:51:57 pgsql Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/storage/smgr/md.c,v 1.100 2004/01/06 18:07:31 neilc Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -25,18 +25,15 @@
|
||||
#include "utils/inval.h"
|
||||
#include "utils/memutils.h"
|
||||
|
||||
|
||||
#undef DIAGNOSTIC
|
||||
|
||||
/*
|
||||
* The magnetic disk storage manager keeps track of open file descriptors
|
||||
* in its own descriptor pool. This happens for two reasons. First, at
|
||||
* transaction boundaries, we walk the list of descriptors and flush
|
||||
* anything that we've dirtied in the current transaction. Second, we want
|
||||
* to support relations larger than the OS' file size limit (often 2GBytes).
|
||||
* In order to do that, we break relations up into chunks of < 2GBytes
|
||||
* and store one chunk in each of several files that represent the relation.
|
||||
* See the BLCKSZ and RELSEG_SIZE configuration constants in include/pg_config.h.
|
||||
* The magnetic disk storage manager keeps track of open file
|
||||
* descriptors in its own descriptor pool. This is done to make it
|
||||
* easier to support relations that are larger than the operating
|
||||
* system's file size limit (often 2GBytes). In order to do that, we
|
||||
* we break relations up into chunks of < 2GBytes and store one chunk
|
||||
* in each of several files that represent the relation. See the
|
||||
* BLCKSZ and RELSEG_SIZE configuration constants in
|
||||
* include/pg_config.h.
|
||||
*
|
||||
* The file descriptor stored in the relation cache (see RelationGetFile())
|
||||
* is actually an index into the Md_fdvec array. -1 indicates not open.
|
||||
@ -67,7 +64,7 @@ static MdfdVec *Md_fdvec = (MdfdVec *) NULL;
|
||||
static int Md_Free = -1; /* head of freelist of unused fdvec
|
||||
* entries */
|
||||
static int CurFd = 0; /* first never-used fdvec index */
|
||||
static MemoryContext MdCxt; /* context for all my allocations */
|
||||
static MemoryContext MdCxt; /* context for all md.c allocations */
|
||||
|
||||
/* routines declared here */
|
||||
static void mdclose_fd(int fd);
|
||||
@ -84,11 +81,8 @@ static BlockNumber _mdnblocks(File file, Size blcksz);
|
||||
/*
|
||||
* mdinit() -- Initialize private state for magnetic disk storage manager.
|
||||
*
|
||||
* We keep a private table of all file descriptors. Whenever we do
|
||||
* a write to one, we mark it dirty in our table. Whenever we force
|
||||
* changes to disk, we mark the file descriptor clean. At transaction
|
||||
* commit, we force changes to disk for all dirty file descriptors.
|
||||
* This routine allocates and initializes the table.
|
||||
* We keep a private table of all file descriptors. This routine
|
||||
* allocates and initializes the table.
|
||||
*
|
||||
* Returns SM_SUCCESS or SM_FAIL with errno set as appropriate.
|
||||
*/
|
||||
@ -247,16 +241,13 @@ mdextend(Relation reln, BlockNumber blocknum, char *buffer)
|
||||
|
||||
#ifndef LET_OS_MANAGE_FILESIZE
|
||||
seekpos = (long) (BLCKSZ * (blocknum % ((BlockNumber) RELSEG_SIZE)));
|
||||
#ifdef DIAGNOSTIC
|
||||
if (seekpos >= BLCKSZ * RELSEG_SIZE)
|
||||
elog(FATAL, "seekpos too big");
|
||||
#endif
|
||||
Assert(seekpos < BLCKSZ * RELSEG_SIZE);
|
||||
#else
|
||||
seekpos = (long) (BLCKSZ * (blocknum));
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Note: because caller obtained blocknum by calling mdnblocks, which
|
||||
* Note: because caller obtained blocknum by calling _mdnblocks, which
|
||||
* did a seek(SEEK_END), this seek is often redundant and will be
|
||||
* optimized away by fd.c. It's not redundant, however, if there is a
|
||||
* partial page at the end of the file. In that case we want to try
|
||||
@ -282,10 +273,7 @@ mdextend(Relation reln, BlockNumber blocknum, char *buffer)
|
||||
}
|
||||
|
||||
#ifndef LET_OS_MANAGE_FILESIZE
|
||||
#ifdef DIAGNOSTIC
|
||||
if (_mdnblocks(v->mdfd_vfd, BLCKSZ) > ((BlockNumber) RELSEG_SIZE))
|
||||
elog(FATAL, "segment too big");
|
||||
#endif
|
||||
Assert(_mdnblocks(v->mdfd_vfd, BLCKSZ) <= ((BlockNumber) RELSEG_SIZE));
|
||||
#endif
|
||||
|
||||
return SM_SUCCESS;
|
||||
@ -335,11 +323,7 @@ mdopen(Relation reln)
|
||||
Md_fdvec[vfd].mdfd_flags = (uint16) 0;
|
||||
#ifndef LET_OS_MANAGE_FILESIZE
|
||||
Md_fdvec[vfd].mdfd_chain = (MdfdVec *) NULL;
|
||||
|
||||
#ifdef DIAGNOSTIC
|
||||
if (_mdnblocks(fd, BLCKSZ) > ((BlockNumber) RELSEG_SIZE))
|
||||
elog(FATAL, "segment too big");
|
||||
#endif
|
||||
Assert(_mdnblocks(fd, BLCKSZ) <= ((BlockNumber) RELSEG_SIZE));
|
||||
#endif
|
||||
|
||||
return vfd;
|
||||
@ -348,7 +332,7 @@ mdopen(Relation reln)
|
||||
/*
|
||||
* mdclose() -- Close the specified relation, if it isn't closed already.
|
||||
*
|
||||
* AND FREE fd vector! It may be re-used for other relation!
|
||||
* AND FREE fd vector! It may be re-used for other relations!
|
||||
* reln should be flushed from cache after closing !..
|
||||
*
|
||||
* Returns SM_SUCCESS or SM_FAIL with errno set as appropriate.
|
||||
@ -418,11 +402,7 @@ mdread(Relation reln, BlockNumber blocknum, char *buffer)
|
||||
|
||||
#ifndef LET_OS_MANAGE_FILESIZE
|
||||
seekpos = (long) (BLCKSZ * (blocknum % ((BlockNumber) RELSEG_SIZE)));
|
||||
|
||||
#ifdef DIAGNOSTIC
|
||||
if (seekpos >= BLCKSZ * RELSEG_SIZE)
|
||||
elog(FATAL, "seekpos too big");
|
||||
#endif
|
||||
Assert(seekpos < BLCKSZ * RELSEG_SIZE);
|
||||
#else
|
||||
seekpos = (long) (BLCKSZ * (blocknum));
|
||||
#endif
|
||||
@ -466,10 +446,7 @@ mdwrite(Relation reln, BlockNumber blocknum, char *buffer)
|
||||
|
||||
#ifndef LET_OS_MANAGE_FILESIZE
|
||||
seekpos = (long) (BLCKSZ * (blocknum % ((BlockNumber) RELSEG_SIZE)));
|
||||
#ifdef DIAGNOSTIC
|
||||
if (seekpos >= BLCKSZ * RELSEG_SIZE)
|
||||
elog(FATAL, "seekpos too big");
|
||||
#endif
|
||||
Assert(seekpos < BLCKSZ * RELSEG_SIZE);
|
||||
#else
|
||||
seekpos = (long) (BLCKSZ * (blocknum));
|
||||
#endif
|
||||
@ -505,10 +482,7 @@ mdblindwrt(RelFileNode rnode,
|
||||
|
||||
#ifndef LET_OS_MANAGE_FILESIZE
|
||||
seekpos = (long) (BLCKSZ * (blkno % ((BlockNumber) RELSEG_SIZE)));
|
||||
#ifdef DIAGNOSTIC
|
||||
if (seekpos >= BLCKSZ * RELSEG_SIZE)
|
||||
elog(FATAL, "seekpos too big");
|
||||
#endif
|
||||
Assert(seekpos < BLCKSZ * RELSEG_SIZE);
|
||||
#else
|
||||
seekpos = (long) (BLCKSZ * (blkno));
|
||||
#endif
|
||||
@ -722,8 +696,6 @@ mdcommit(void)
|
||||
|
||||
/*
|
||||
* mdabort() -- Abort a transaction.
|
||||
*
|
||||
* Changes need not be forced to disk at transaction abort.
|
||||
*/
|
||||
int
|
||||
mdabort(void)
|
||||
@ -748,7 +720,7 @@ mdsync(void)
|
||||
}
|
||||
|
||||
/*
|
||||
* _fdvec_alloc () -- grab a free (or new) md file descriptor vector.
|
||||
* _fdvec_alloc() -- Grab a free (or new) md file descriptor vector.
|
||||
*/
|
||||
static int
|
||||
_fdvec_alloc(void)
|
||||
@ -802,7 +774,7 @@ _fdvec_alloc(void)
|
||||
}
|
||||
|
||||
/*
|
||||
* _fdvec_free () -- free md file descriptor vector.
|
||||
* _fdvec_free() -- free md file descriptor vector.
|
||||
*
|
||||
*/
|
||||
static
|
||||
@ -853,19 +825,18 @@ _mdfd_openseg(Relation reln, BlockNumber segno, int oflags)
|
||||
v->mdfd_flags = (uint16) 0;
|
||||
#ifndef LET_OS_MANAGE_FILESIZE
|
||||
v->mdfd_chain = (MdfdVec *) NULL;
|
||||
|
||||
#ifdef DIAGNOSTIC
|
||||
if (_mdnblocks(fd, BLCKSZ) > ((BlockNumber) RELSEG_SIZE))
|
||||
elog(FATAL, "segment too big");
|
||||
#endif
|
||||
Assert(_mdnblocks(fd, BLCKSZ) <= ((BlockNumber) RELSEG_SIZE));
|
||||
#endif
|
||||
|
||||
/* all done */
|
||||
return v;
|
||||
}
|
||||
|
||||
/* Get the fd for the relation, opening it if it's not already open */
|
||||
|
||||
/*
|
||||
* _mdfd_getrelnfd() -- Get the (virtual) fd for the relation,
|
||||
* opening it if it's not already open
|
||||
*
|
||||
*/
|
||||
static int
|
||||
_mdfd_getrelnfd(Relation reln)
|
||||
{
|
||||
@ -882,8 +853,11 @@ _mdfd_getrelnfd(Relation reln)
|
||||
return fd;
|
||||
}
|
||||
|
||||
/* Find the segment of the relation holding the specified block */
|
||||
|
||||
/*
|
||||
* _mdfd_getseg() -- Find the segment of the relation holding the
|
||||
* specified block
|
||||
*
|
||||
*/
|
||||
static MdfdVec *
|
||||
_mdfd_getseg(Relation reln, BlockNumber blkno)
|
||||
{
|
||||
@ -942,7 +916,6 @@ _mdfd_getseg(Relation reln, BlockNumber blkno)
|
||||
*
|
||||
* The return value is the kernel descriptor, or -1 on failure.
|
||||
*/
|
||||
|
||||
static int
|
||||
_mdfd_blind_getseg(RelFileNode rnode, BlockNumber blkno)
|
||||
{
|
||||
|
@ -11,7 +11,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/storage/smgr/smgr.c,v 1.67 2003/12/12 18:45:09 petere Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/storage/smgr/smgr.c,v 1.68 2004/01/06 18:07:31 neilc Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -382,7 +382,7 @@ smgrblindwrt(int16 which,
|
||||
}
|
||||
|
||||
/*
|
||||
* smgrnblocks() -- Calculate the number of POSTGRES blocks in the
|
||||
* smgrnblocks() -- Calculate the number of blocks in the
|
||||
* supplied relation.
|
||||
*
|
||||
* Returns the number of blocks on success, aborts the current
|
||||
@ -411,8 +411,8 @@ smgrnblocks(int16 which, Relation reln)
|
||||
}
|
||||
|
||||
/*
|
||||
* smgrtruncate() -- Truncate supplied relation to a specified number
|
||||
* of blocks
|
||||
* smgrtruncate() -- Truncate supplied relation to the specified number
|
||||
* of blocks
|
||||
*
|
||||
* Returns the number of blocks on success, aborts the current
|
||||
* transaction on failure.
|
||||
@ -444,7 +444,7 @@ smgrtruncate(int16 which, Relation reln, BlockNumber nblocks)
|
||||
}
|
||||
|
||||
/*
|
||||
* smgrDoPendingDeletes() -- take care of relation deletes at end of xact.
|
||||
* smgrDoPendingDeletes() -- Take care of relation deletes at end of xact.
|
||||
*/
|
||||
int
|
||||
smgrDoPendingDeletes(bool isCommit)
|
||||
@ -494,7 +494,7 @@ smgrDoPendingDeletes(bool isCommit)
|
||||
* smgrcommit() -- Prepare to commit changes made during the current
|
||||
* transaction.
|
||||
*
|
||||
* This is called before we actually commit.
|
||||
* This is called before we actually commit.
|
||||
*/
|
||||
int
|
||||
smgrcommit(void)
|
||||
@ -538,7 +538,7 @@ smgrabort(void)
|
||||
}
|
||||
|
||||
/*
|
||||
* Sync files to disk at checkpoint time.
|
||||
* smgrsync() -- Sync files to disk at checkpoint time.
|
||||
*/
|
||||
int
|
||||
smgrsync(void)
|
||||
|
@ -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.71 2003/11/29 22:41:16 pgsql Exp $
|
||||
* $PostgreSQL: pgsql/src/include/utils/rel.h,v 1.72 2004/01/06 18:07:32 neilc Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -104,7 +104,9 @@ typedef struct PgStat_Info
|
||||
|
||||
typedef struct RelationData
|
||||
{
|
||||
File rd_fd; /* open file descriptor, or -1 if none */
|
||||
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) */
|
||||
BlockNumber rd_nblocks; /* number of blocks in rel */
|
||||
BlockNumber rd_targblock; /* current insertion target block, or
|
||||
@ -220,22 +222,21 @@ typedef Relation *RelationPtr;
|
||||
|
||||
/*
|
||||
* RelationGetRelid
|
||||
*
|
||||
* returns the OID of the relation
|
||||
* Returns the OID of the relation
|
||||
*/
|
||||
#define RelationGetRelid(relation) ((relation)->rd_id)
|
||||
|
||||
/*
|
||||
* RelationGetFile
|
||||
*
|
||||
* Returns the open file descriptor for the rel
|
||||
* 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.
|
||||
* Returns the number of attributes in a relation.
|
||||
*/
|
||||
#define RelationGetNumberOfAttributes(relation) ((relation)->rd_rel->relnatts)
|
||||
|
||||
@ -247,8 +248,7 @@ typedef Relation *RelationPtr;
|
||||
|
||||
/*
|
||||
* RelationGetRelationName
|
||||
*
|
||||
* Returns the rel's name.
|
||||
* Returns the rel's name.
|
||||
*
|
||||
* Note that the name is only unique within the containing namespace.
|
||||
*/
|
||||
@ -257,8 +257,7 @@ typedef Relation *RelationPtr;
|
||||
|
||||
/*
|
||||
* RelationGetNamespace
|
||||
*
|
||||
* Returns the rel's namespace OID.
|
||||
* Returns the rel's namespace OID.
|
||||
*/
|
||||
#define RelationGetNamespace(relation) \
|
||||
((relation)->rd_rel->relnamespace)
|
||||
|
Loading…
Reference in New Issue
Block a user