diff options
Diffstat (limited to 'src/backend/storage/smgr')
-rw-r--r-- | src/backend/storage/smgr/md.c | 70 | ||||
-rw-r--r-- | src/backend/storage/smgr/smgr.c | 155 | ||||
-rw-r--r-- | src/backend/storage/smgr/smgrtype.c | 6 |
3 files changed, 116 insertions, 115 deletions
diff --git a/src/backend/storage/smgr/md.c b/src/backend/storage/smgr/md.c index 81e8430c4d5..54e56061cff 100644 --- a/src/backend/storage/smgr/md.c +++ b/src/backend/storage/smgr/md.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/storage/smgr/md.c,v 1.109 2004/08/29 04:12:49 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/storage/smgr/md.c,v 1.110 2004/08/29 05:06:49 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -54,9 +54,9 @@ typedef struct _MdfdVec { - File mdfd_vfd; /* fd number in fd.c's pool */ - BlockNumber mdfd_segno; /* segment number, from 0 */ -#ifndef LET_OS_MANAGE_FILESIZE /* for large relations */ + File mdfd_vfd; /* fd number in fd.c's pool */ + BlockNumber mdfd_segno; /* segment number, from 0 */ +#ifndef LET_OS_MANAGE_FILESIZE /* for large relations */ struct _MdfdVec *mdfd_chain; /* next segment, or NULL */ #endif } MdfdVec; @@ -69,7 +69,7 @@ static MemoryContext MdCxt; /* context for all md.c allocations */ * we keep track of pending fsync operations: we need to remember all relation * segments that have been written since the last checkpoint, so that we can * fsync them down to disk before completing the next checkpoint. This hash - * table remembers the pending operations. We use a hash table not because + * table remembers the pending operations. We use a hash table not because * we want to look up individual operations, but simply as a convenient way * of eliminating duplicate requests. * @@ -80,8 +80,8 @@ static MemoryContext MdCxt; /* context for all md.c allocations */ */ typedef struct { - RelFileNode rnode; /* the targeted relation */ - BlockNumber segno; /* which segment */ + RelFileNode rnode; /* the targeted relation */ + BlockNumber segno; /* which segment */ } PendingOperationEntry; static HTAB *pendingOpsTable = NULL; @@ -91,12 +91,13 @@ static HTAB *pendingOpsTable = NULL; static MdfdVec *mdopen(SMgrRelation reln, bool allowNotFound); static bool register_dirty_segment(SMgrRelation reln, MdfdVec *seg); static MdfdVec *_fdvec_alloc(void); + #ifndef LET_OS_MANAGE_FILESIZE static MdfdVec *_mdfd_openseg(SMgrRelation reln, BlockNumber segno, - int oflags); + int oflags); #endif static MdfdVec *_mdfd_getseg(SMgrRelation reln, BlockNumber blkno, - bool allowNotFound); + bool allowNotFound); static BlockNumber _mdnblocks(File file, Size blcksz); @@ -113,10 +114,10 @@ mdinit(void) ALLOCSET_DEFAULT_MAXSIZE); /* - * Create pending-operations hashtable if we need it. Currently, - * we need it if we are standalone (not under a postmaster) OR - * if we are a bootstrap-mode subprocess of a postmaster (that is, - * a startup or bgwriter process). + * Create pending-operations hashtable if we need it. Currently, we + * need it if we are standalone (not under a postmaster) OR if we are + * a bootstrap-mode subprocess of a postmaster (that is, a startup or + * bgwriter process). */ if (!IsUnderPostmaster || IsBootstrapProcessingMode()) { @@ -130,7 +131,7 @@ mdinit(void) pendingOpsTable = hash_create("Pending Ops Table", 100L, &hash_ctl, - HASH_ELEM | HASH_FUNCTION | HASH_CONTEXT); + HASH_ELEM | HASH_FUNCTION | HASH_CONTEXT); if (pendingOpsTable == NULL) ereport(FATAL, (errcode(ERRCODE_OUT_OF_MEMORY), @@ -333,7 +334,7 @@ mdextend(SMgrRelation reln, BlockNumber blocknum, char *buffer, bool isTemp) static MdfdVec * mdopen(SMgrRelation reln, bool allowNotFound) { - MdfdVec *mdfd; + MdfdVec *mdfd; char *path; File fd; @@ -613,8 +614,7 @@ mdtruncate(SMgrRelation reln, BlockNumber nblocks, bool isTemp) FileTruncate(v->mdfd_vfd, 0); FileUnlink(v->mdfd_vfd); v = v->mdfd_chain; - Assert(ov != reln->md_fd); /* we never drop the 1st - * segment */ + Assert(ov != reln->md_fd); /* we never drop the 1st segment */ pfree(ov); } else if (priorblocks + ((BlockNumber) RELSEG_SIZE) > nblocks) @@ -714,8 +714,8 @@ mdsync(void) /* * If we are in the bgwriter, the sync had better include all fsync * requests that were queued by backends before the checkpoint REDO - * point was determined. We go that a little better by accepting - * all requests queued up to the point where we start fsync'ing. + * point was determined. We go that a little better by accepting all + * requests queued up to the point where we start fsync'ing. */ AbsorbFsyncRequests(); @@ -724,22 +724,22 @@ mdsync(void) { /* * If fsync is off then we don't have to bother opening the file - * at all. (We delay checking until this point so that changing + * at all. (We delay checking until this point so that changing * fsync on the fly behaves sensibly.) */ if (enableFsync) { SMgrRelation reln; - MdfdVec *seg; + MdfdVec *seg; /* - * Find or create an smgr hash entry for this relation. - * This may seem a bit unclean -- md calling smgr? But it's - * really the best solution. It ensures that the open file - * reference isn't permanently leaked if we get an error here. - * (You may say "but an unreferenced SMgrRelation is still a - * leak!" Not really, because the only case in which a checkpoint - * is done by a process that isn't about to shut down is in the + * Find or create an smgr hash entry for this relation. This + * may seem a bit unclean -- md calling smgr? But it's really + * the best solution. It ensures that the open file reference + * isn't permanently leaked if we get an error here. (You may + * say "but an unreferenced SMgrRelation is still a leak!" + * Not really, because the only case in which a checkpoint is + * done by a process that isn't about to shut down is in the * bgwriter, and it will periodically do smgrcloseall(). This * fact justifies our not closing the reln in the success path * either, which is a good thing since in non-bgwriter cases @@ -750,11 +750,11 @@ mdsync(void) reln = smgropen(entry->rnode); /* - * It is possible that the relation has been dropped or truncated - * since the fsync request was entered. Therefore, we have to - * allow file-not-found errors. This applies both during - * _mdfd_getseg() and during FileSync, since fd.c might have - * closed the file behind our back. + * It is possible that the relation has been dropped or + * truncated since the fsync request was entered. Therefore, + * we have to allow file-not-found errors. This applies both + * during _mdfd_getseg() and during FileSync, since fd.c might + * have closed the file behind our back. */ seg = _mdfd_getseg(reln, entry->segno * ((BlockNumber) RELSEG_SIZE), @@ -903,8 +903,7 @@ _mdfd_openseg(SMgrRelation reln, BlockNumber segno, int oflags) /* all done */ return v; } - -#endif /* LET_OS_MANAGE_FILESIZE */ +#endif /* LET_OS_MANAGE_FILESIZE */ /* * _mdfd_getseg() -- Find the segment of the relation holding the @@ -915,6 +914,7 @@ static MdfdVec * _mdfd_getseg(SMgrRelation reln, BlockNumber blkno, bool allowNotFound) { MdfdVec *v = mdopen(reln, allowNotFound); + #ifndef LET_OS_MANAGE_FILESIZE BlockNumber segstogo; BlockNumber nextsegno; diff --git a/src/backend/storage/smgr/smgr.c b/src/backend/storage/smgr/smgr.c index ceb356271a9..ec1d902a10c 100644 --- a/src/backend/storage/smgr/smgr.c +++ b/src/backend/storage/smgr/smgr.c @@ -11,7 +11,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/storage/smgr/smgr.c,v 1.79 2004/08/29 04:12:50 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/storage/smgr/smgr.c,v 1.80 2004/08/29 05:06:49 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -36,36 +36,36 @@ */ typedef struct f_smgr { - bool (*smgr_init) (void); /* may be NULL */ + bool (*smgr_init) (void); /* may be NULL */ bool (*smgr_shutdown) (void); /* may be NULL */ bool (*smgr_close) (SMgrRelation reln); bool (*smgr_create) (SMgrRelation reln, bool isRedo); bool (*smgr_unlink) (RelFileNode rnode, bool isRedo); bool (*smgr_extend) (SMgrRelation reln, BlockNumber blocknum, - char *buffer, bool isTemp); + char *buffer, bool isTemp); bool (*smgr_read) (SMgrRelation reln, BlockNumber blocknum, - char *buffer); + char *buffer); bool (*smgr_write) (SMgrRelation reln, BlockNumber blocknum, - char *buffer, bool isTemp); + char *buffer, bool isTemp); BlockNumber (*smgr_nblocks) (SMgrRelation reln); BlockNumber (*smgr_truncate) (SMgrRelation reln, BlockNumber nblocks, - bool isTemp); + bool isTemp); bool (*smgr_immedsync) (SMgrRelation reln); - bool (*smgr_commit) (void); /* may be NULL */ - bool (*smgr_abort) (void); /* may be NULL */ - bool (*smgr_sync) (void); /* may be NULL */ + bool (*smgr_commit) (void); /* may be NULL */ + bool (*smgr_abort) (void); /* may be NULL */ + bool (*smgr_sync) (void); /* may be NULL */ } f_smgr; static const f_smgr smgrsw[] = { /* magnetic disk */ {mdinit, NULL, mdclose, mdcreate, mdunlink, mdextend, - mdread, mdwrite, mdnblocks, mdtruncate, mdimmedsync, - NULL, NULL, mdsync + mdread, mdwrite, mdnblocks, mdtruncate, mdimmedsync, + NULL, NULL, mdsync } }; -static const int NSmgr = lengthof(smgrsw); +static const int NSmgr = lengthof(smgrsw); /* @@ -119,20 +119,20 @@ static PendingRelDelete *pendingDeletes = NULL; /* head of linked list */ typedef struct xl_smgr_create { - RelFileNode rnode; + RelFileNode rnode; } xl_smgr_create; typedef struct xl_smgr_truncate { - BlockNumber blkno; - RelFileNode rnode; + BlockNumber blkno; + RelFileNode rnode; } xl_smgr_truncate; /* local function prototypes */ static void smgrshutdown(int code, Datum arg); static void smgr_internal_unlink(RelFileNode rnode, int which, - bool isTemp, bool isRedo); + bool isTemp, bool isRedo); /* @@ -151,7 +151,7 @@ smgrinit(void) { if (smgrsw[i].smgr_init) { - if (! (*(smgrsw[i].smgr_init)) ()) + if (!(*(smgrsw[i].smgr_init)) ()) elog(FATAL, "smgr initialization failed on %s: %m", DatumGetCString(DirectFunctionCall1(smgrout, Int16GetDatum(i)))); @@ -171,7 +171,7 @@ smgrshutdown(int code, Datum arg) { if (smgrsw[i].smgr_shutdown) { - if (! (*(smgrsw[i].smgr_shutdown)) ()) + if (!(*(smgrsw[i].smgr_shutdown)) ()) elog(FATAL, "smgr shutdown failed on %s: %m", DatumGetCString(DirectFunctionCall1(smgrout, Int16GetDatum(i)))); @@ -187,7 +187,7 @@ smgrshutdown(int code, Datum arg) SMgrRelation smgropen(RelFileNode rnode) { - SMgrRelation reln; + SMgrRelation reln; bool found; if (SMgrRelationHash == NULL) @@ -233,7 +233,7 @@ smgropen(RelFileNode rnode) void smgrclose(SMgrRelation reln) { - if (! (*(smgrsw[reln->smgr_which].smgr_close)) (reln)) + if (!(*(smgrsw[reln->smgr_which].smgr_close)) (reln)) ereport(ERROR, (errcode_for_file_access(), errmsg("could not close relation %u/%u/%u: %m", @@ -265,9 +265,7 @@ smgrcloseall(void) hash_seq_init(&status, SMgrRelationHash); while ((reln = (SMgrRelation) hash_seq_search(&status)) != NULL) - { smgrclose(reln); - } } /* @@ -283,7 +281,7 @@ smgrcloseall(void) void smgrclosenode(RelFileNode rnode) { - SMgrRelation reln; + SMgrRelation reln; /* Nothing to do if hashtable not set up */ if (SMgrRelationHash == NULL) @@ -310,9 +308,9 @@ smgrclosenode(RelFileNode rnode) void smgrcreate(SMgrRelation reln, bool isTemp, bool isRedo) { - XLogRecPtr lsn; - XLogRecData rdata; - xl_smgr_create xlrec; + XLogRecPtr lsn; + XLogRecData rdata; + xl_smgr_create xlrec; PendingRelDelete *pending; /* @@ -320,15 +318,16 @@ smgrcreate(SMgrRelation reln, bool isTemp, bool isRedo) * database, so create a per-database subdirectory if needed. * * XXX this is a fairly ugly violation of module layering, but this seems - * to be the best place to put the check. Maybe TablespaceCreateDbspace - * should be here and not in commands/tablespace.c? But that would imply - * importing a lot of stuff that smgr.c oughtn't know, either. + * to be the best place to put the check. Maybe + * TablespaceCreateDbspace should be here and not in + * commands/tablespace.c? But that would imply importing a lot of + * stuff that smgr.c oughtn't know, either. */ TablespaceCreateDbspace(reln->smgr_rnode.spcNode, reln->smgr_rnode.dbNode, isRedo); - if (! (*(smgrsw[reln->smgr_which].smgr_create)) (reln, isRedo)) + if (!(*(smgrsw[reln->smgr_which].smgr_create)) (reln, isRedo)) ereport(ERROR, (errcode_for_file_access(), errmsg("could not create relation %u/%u/%u: %m", @@ -340,9 +339,10 @@ smgrcreate(SMgrRelation reln, bool isTemp, bool isRedo) return; /* - * Make a non-transactional XLOG entry showing the file creation. It's - * non-transactional because we should replay it whether the transaction - * commits or not; if not, the file will be dropped at abort time. + * Make a non-transactional XLOG entry showing the file creation. + * It's non-transactional because we should replay it whether the + * transaction commits or not; if not, the file will be dropped at + * abort time. */ xlrec.rnode = reln->smgr_rnode; @@ -417,7 +417,7 @@ smgrscheduleunlink(SMgrRelation reln, bool isTemp) void smgrdounlink(SMgrRelation reln, bool isTemp, bool isRedo) { - RelFileNode rnode = reln->smgr_rnode; + RelFileNode rnode = reln->smgr_rnode; int which = reln->smgr_which; /* Close the file and throw away the hashtable entry */ @@ -433,24 +433,25 @@ static void smgr_internal_unlink(RelFileNode rnode, int which, bool isTemp, bool isRedo) { /* - * Get rid of any leftover buffers for the rel (shouldn't be any in the - * commit case, but there can be in the abort case). + * Get rid of any leftover buffers for the rel (shouldn't be any in + * the commit case, but there can be in the abort case). */ DropRelFileNodeBuffers(rnode, isTemp, 0); /* - * Tell the free space map to forget this relation. It won't be accessed - * any more anyway, but we may as well recycle the map space quickly. + * Tell the free space map to forget this relation. It won't be + * accessed any more anyway, but we may as well recycle the map space + * quickly. */ FreeSpaceMapForgetRel(&rnode); /* * And delete the physical files. * - * Note: we treat deletion failure as a WARNING, not an error, - * because we've already decided to commit or abort the current xact. + * Note: we treat deletion failure as a WARNING, not an error, because + * we've already decided to commit or abort the current xact. */ - if (! (*(smgrsw[which].smgr_unlink)) (rnode, isRedo)) + if (!(*(smgrsw[which].smgr_unlink)) (rnode, isRedo)) ereport(WARNING, (errcode_for_file_access(), errmsg("could not unlink relation %u/%u/%u: %m", @@ -470,8 +471,8 @@ smgr_internal_unlink(RelFileNode rnode, int which, bool isTemp, bool isRedo) void smgrextend(SMgrRelation reln, BlockNumber blocknum, char *buffer, bool isTemp) { - if (! (*(smgrsw[reln->smgr_which].smgr_extend)) (reln, blocknum, buffer, - isTemp)) + if (!(*(smgrsw[reln->smgr_which].smgr_extend)) (reln, blocknum, buffer, + isTemp)) ereport(ERROR, (errcode_for_file_access(), errmsg("could not extend relation %u/%u/%u: %m", @@ -492,14 +493,14 @@ smgrextend(SMgrRelation reln, BlockNumber blocknum, char *buffer, bool isTemp) void smgrread(SMgrRelation reln, BlockNumber blocknum, char *buffer) { - if (! (*(smgrsw[reln->smgr_which].smgr_read)) (reln, blocknum, buffer)) + if (!(*(smgrsw[reln->smgr_which].smgr_read)) (reln, blocknum, buffer)) ereport(ERROR, (errcode_for_file_access(), - errmsg("could not read block %u of relation %u/%u/%u: %m", - blocknum, - reln->smgr_rnode.spcNode, - reln->smgr_rnode.dbNode, - reln->smgr_rnode.relNode))); + errmsg("could not read block %u of relation %u/%u/%u: %m", + blocknum, + reln->smgr_rnode.spcNode, + reln->smgr_rnode.dbNode, + reln->smgr_rnode.relNode))); } /* @@ -516,15 +517,15 @@ smgrread(SMgrRelation reln, BlockNumber blocknum, char *buffer) void smgrwrite(SMgrRelation reln, BlockNumber blocknum, char *buffer, bool isTemp) { - if (! (*(smgrsw[reln->smgr_which].smgr_write)) (reln, blocknum, buffer, - isTemp)) + if (!(*(smgrsw[reln->smgr_which].smgr_write)) (reln, blocknum, buffer, + isTemp)) ereport(ERROR, (errcode_for_file_access(), - errmsg("could not write block %u of relation %u/%u/%u: %m", - blocknum, - reln->smgr_rnode.spcNode, - reln->smgr_rnode.dbNode, - reln->smgr_rnode.relNode))); + errmsg("could not write block %u of relation %u/%u/%u: %m", + blocknum, + reln->smgr_rnode.spcNode, + reln->smgr_rnode.dbNode, + reln->smgr_rnode.relNode))); } /* @@ -571,9 +572,9 @@ smgrtruncate(SMgrRelation reln, BlockNumber nblocks, bool isTemp) BlockNumber newblks; /* - * Tell the free space map to forget anything it may have stored - * for the about-to-be-deleted blocks. We want to be sure it - * won't return bogus block numbers later on. + * Tell the free space map to forget anything it may have stored for + * the about-to-be-deleted blocks. We want to be sure it won't return + * bogus block numbers later on. */ FreeSpaceMapTruncateRel(&reln->smgr_rnode, nblocks); @@ -583,22 +584,22 @@ smgrtruncate(SMgrRelation reln, BlockNumber nblocks, bool isTemp) if (newblks == InvalidBlockNumber) ereport(ERROR, (errcode_for_file_access(), - errmsg("could not truncate relation %u/%u/%u to %u blocks: %m", - reln->smgr_rnode.spcNode, - reln->smgr_rnode.dbNode, - reln->smgr_rnode.relNode, - nblocks))); + errmsg("could not truncate relation %u/%u/%u to %u blocks: %m", + reln->smgr_rnode.spcNode, + reln->smgr_rnode.dbNode, + reln->smgr_rnode.relNode, + nblocks))); if (!isTemp) { /* - * Make a non-transactional XLOG entry showing the file truncation. - * It's non-transactional because we should replay it whether the - * transaction commits or not; the underlying file change is certainly - * not reversible. + * Make a non-transactional XLOG entry showing the file + * truncation. It's non-transactional because we should replay it + * whether the transaction commits or not; the underlying file + * change is certainly not reversible. */ - XLogRecPtr lsn; - XLogRecData rdata; + XLogRecPtr lsn; + XLogRecData rdata; xl_smgr_truncate xlrec; xlrec.blkno = newblks; @@ -637,7 +638,7 @@ smgrtruncate(SMgrRelation reln, BlockNumber nblocks, bool isTemp) void smgrimmedsync(SMgrRelation reln) { - if (! (*(smgrsw[reln->smgr_which].smgr_immedsync)) (reln)) + if (!(*(smgrsw[reln->smgr_which].smgr_immedsync)) (reln)) ereport(ERROR, (errcode_for_file_access(), errmsg("could not sync relation %u/%u/%u: %m", @@ -774,7 +775,7 @@ smgrcommit(void) { if (smgrsw[i].smgr_commit) { - if (! (*(smgrsw[i].smgr_commit)) ()) + if (!(*(smgrsw[i].smgr_commit)) ()) elog(ERROR, "transaction commit failed on %s: %m", DatumGetCString(DirectFunctionCall1(smgrout, Int16GetDatum(i)))); @@ -794,7 +795,7 @@ smgrabort(void) { if (smgrsw[i].smgr_abort) { - if (! (*(smgrsw[i].smgr_abort)) ()) + if (!(*(smgrsw[i].smgr_abort)) ()) elog(ERROR, "transaction abort failed on %s: %m", DatumGetCString(DirectFunctionCall1(smgrout, Int16GetDatum(i)))); @@ -814,7 +815,7 @@ smgrsync(void) { if (smgrsw[i].smgr_sync) { - if (! (*(smgrsw[i].smgr_sync)) ()) + if (!(*(smgrsw[i].smgr_sync)) ()) elog(ERROR, "storage sync failed on %s: %m", DatumGetCString(DirectFunctionCall1(smgrout, Int16GetDatum(i)))); @@ -846,8 +847,8 @@ smgr_redo(XLogRecPtr lsn, XLogRecord *record) /* * First, force bufmgr to drop any buffers it has for the to-be- - * truncated blocks. We must do this, else subsequent XLogReadBuffer - * operations will not re-extend the file properly. + * truncated blocks. We must do this, else subsequent + * XLogReadBuffer operations will not re-extend the file properly. */ DropRelFileNodeBuffers(xlrec->rnode, false, xlrec->blkno); @@ -862,7 +863,7 @@ smgr_redo(XLogRecPtr lsn, XLogRecord *record) /* Do the truncation */ newblks = (*(smgrsw[reln->smgr_which].smgr_truncate)) (reln, - xlrec->blkno, + xlrec->blkno, false); if (newblks == InvalidBlockNumber) ereport(WARNING, diff --git a/src/backend/storage/smgr/smgrtype.c b/src/backend/storage/smgr/smgrtype.c index 33c464030c7..2f9667d5aaa 100644 --- a/src/backend/storage/smgr/smgrtype.c +++ b/src/backend/storage/smgr/smgrtype.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/storage/smgr/smgrtype.c,v 1.24 2004/08/29 04:12:50 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/storage/smgr/smgrtype.c,v 1.25 2004/08/29 05:06:49 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -19,7 +19,7 @@ typedef struct smgrid { - const char *smgr_name; + const char *smgr_name; } smgrid; /* @@ -29,7 +29,7 @@ static const smgrid StorageManager[] = { {"magnetic disk"} }; -static const int NStorageManagers = lengthof(StorageManager); +static const int NStorageManagers = lengthof(StorageManager); Datum |