diff options
Diffstat (limited to 'src/backend/storage/smgr')
-rw-r--r-- | src/backend/storage/smgr/md.c | 56 | ||||
-rw-r--r-- | src/backend/storage/smgr/smgr.c | 53 |
2 files changed, 60 insertions, 49 deletions
diff --git a/src/backend/storage/smgr/md.c b/src/backend/storage/smgr/md.c index 179be5ab0e9..e4aca5aeee4 100644 --- a/src/backend/storage/smgr/md.c +++ b/src/backend/storage/smgr/md.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/storage/smgr/md.c,v 1.81 2001/01/24 19:43:08 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/storage/smgr/md.c,v 1.82 2001/03/22 03:59:47 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -76,7 +76,7 @@ static int _mdfd_getrelnfd(Relation reln); static MdfdVec *_mdfd_openseg(Relation reln, int segno, int oflags); static MdfdVec *_mdfd_getseg(Relation reln, int blkno); -static int _mdfd_blind_getseg(RelFileNode rnode, int blkno); +static int _mdfd_blind_getseg(RelFileNode rnode, int blkno); static int _fdvec_alloc(void); static void _fdvec_free(int); @@ -135,13 +135,14 @@ mdcreate(Relation reln) if (fd < 0) { - int save_errno = errno; + int save_errno = errno; /* - * During bootstrap, there are cases where a system relation will be - * accessed (by internal backend processes) before the bootstrap - * script nominally creates it. Therefore, allow the file to exist - * already, but in bootstrap mode only. (See also mdopen) + * During bootstrap, there are cases where a system relation will + * be accessed (by internal backend processes) before the + * bootstrap script nominally creates it. Therefore, allow the + * file to exist already, but in bootstrap mode only. (See also + * mdopen) */ if (IsBootstrapProcessingMode()) fd = FileNameOpenFile(path, O_RDWR | PG_BINARY, 0600); @@ -197,7 +198,7 @@ mdunlink(RelFileNode rnode) char *segpath = (char *) palloc(strlen(path) + 12); int segno; - for (segno = 1; ; segno++) + for (segno = 1;; segno++) { sprintf(segpath, "%s.%d", path, segno); if (unlink(segpath) < 0) @@ -293,11 +294,13 @@ mdopen(Relation reln) if (fd < 0) { + /* - * During bootstrap, there are cases where a system relation will be - * accessed (by internal backend processes) before the bootstrap - * script nominally creates it. Therefore, accept mdopen() as a - * substitute for mdcreate() in bootstrap mode only. (See mdcreate) + * During bootstrap, there are cases where a system relation will + * be accessed (by internal backend processes) before the + * bootstrap script nominally creates it. Therefore, accept + * mdopen() as a substitute for mdcreate() in bootstrap mode only. + * (See mdcreate) */ if (IsBootstrapProcessingMode()) fd = FileNameOpenFile(path, O_RDWR | O_CREAT | O_EXCL | PG_BINARY, 0600); @@ -666,12 +669,13 @@ mdnblocks(Relation reln) if (v->mdfd_chain == (MdfdVec *) NULL) { + /* - * Because we pass O_CREAT, we will create the next segment - * (with zero length) immediately, if the last segment is of - * length REL_SEGSIZE. This is unnecessary but harmless, and - * testing for the case would take more cycles than it seems - * worth. + * Because we pass O_CREAT, we will create the next + * segment (with zero length) immediately, if the last + * segment is of length REL_SEGSIZE. This is unnecessary + * but harmless, and testing for the case would take more + * cycles than it seems worth. */ v->mdfd_chain = _mdfd_openseg(reln, segno, O_CREAT); if (v->mdfd_chain == (MdfdVec *) NULL) @@ -700,8 +704,10 @@ mdtruncate(Relation reln, int nblocks) int curnblk; int fd; MdfdVec *v; + #ifndef LET_OS_MANAGE_FILESIZE int priorblocks; + #endif /* @@ -1004,14 +1010,16 @@ _mdfd_getseg(Relation reln, int blkno) if (v->mdfd_chain == (MdfdVec *) NULL) { + /* - * We will create the next segment only if the target block - * is within it. This prevents Sorcerer's Apprentice syndrome - * if a bug at higher levels causes us to be handed a ridiculously - * large blkno --- otherwise we could create many thousands of - * empty segment files before reaching the "target" block. We - * should never need to create more than one new segment per call, - * so this restriction seems reasonable. + * We will create the next segment only if the target block is + * within it. This prevents Sorcerer's Apprentice syndrome if + * a bug at higher levels causes us to be handed a + * ridiculously large blkno --- otherwise we could create many + * thousands of empty segment files before reaching the + * "target" block. We should never need to create more than + * one new segment per call, so this restriction seems + * reasonable. */ v->mdfd_chain = _mdfd_openseg(reln, i, (segno == 1) ? O_CREAT : 0); diff --git a/src/backend/storage/smgr/smgr.c b/src/backend/storage/smgr/smgr.c index 10d6d6fc480..d19abcd6254 100644 --- a/src/backend/storage/smgr/smgr.c +++ b/src/backend/storage/smgr/smgr.c @@ -11,7 +11,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/storage/smgr/smgr.c,v 1.47 2001/01/24 19:43:08 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/storage/smgr/smgr.c,v 1.48 2001/03/22 03:59:47 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -39,8 +39,8 @@ typedef struct f_smgr char *buffer); int (*smgr_flush) (Relation reln, BlockNumber blocknum, char *buffer); - int (*smgr_blindwrt) (RelFileNode rnode, BlockNumber blkno, - char *buffer, bool dofsync); + int (*smgr_blindwrt) (RelFileNode rnode, BlockNumber blkno, + char *buffer, bool dofsync); int (*smgr_markdirty) (Relation reln, BlockNumber blkno); int (*smgr_blindmarkdirty) (RelFileNode, BlockNumber blkno); int (*smgr_nblocks) (Relation reln); @@ -60,7 +60,7 @@ static f_smgr smgrsw[] = { /* magnetic disk */ {mdinit, NULL, mdcreate, mdunlink, mdextend, mdopen, mdclose, mdread, mdwrite, mdflush, mdblindwrt, mdmarkdirty, mdblindmarkdirty, - mdnblocks, mdtruncate, mdcommit, mdabort, mdsync + mdnblocks, mdtruncate, mdcommit, mdabort, mdsync }, #ifdef STABLE_MEMORY_STORAGE @@ -96,7 +96,7 @@ static int NSmgr = lengthof(smgrsw); * that have been created or deleted in the current transaction. When * a relation is created, we create the physical file immediately, but * remember it so that we can delete the file again if the current - * transaction is aborted. Conversely, a deletion request is NOT + * transaction is aborted. Conversely, a deletion request is NOT * executed immediately, but is just entered in the list. When and if * the transaction commits, we can delete the physical file. * @@ -108,12 +108,12 @@ static int NSmgr = lengthof(smgrsw); typedef struct PendingRelDelete { RelFileNode relnode; /* relation that may need to be deleted */ - int16 which; /* which storage manager? */ - bool atCommit; /* T=delete at commit; F=delete at abort */ - struct PendingRelDelete *next; /* linked-list link */ + int16 which; /* which storage manager? */ + bool atCommit; /* T=delete at commit; F=delete at abort */ + struct PendingRelDelete *next; /* linked-list link */ } PendingRelDelete; -static PendingRelDelete *pendingDeletes = NULL; /* head of linked list */ +static PendingRelDelete *pendingDeletes = NULL; /* head of linked list */ /* @@ -133,7 +133,7 @@ smgrinit() if ((*(smgrsw[i].smgr_init)) () == SM_FAIL) elog(FATAL, "initialization failed on %s: %m", DatumGetCString(DirectFunctionCall1(smgrout, - Int16GetDatum(i)))); + Int16GetDatum(i)))); } } @@ -155,7 +155,7 @@ smgrshutdown(void) if ((*(smgrsw[i].smgr_shutdown)) () == SM_FAIL) elog(FATAL, "shutdown failed on %s: %m", DatumGetCString(DirectFunctionCall1(smgrout, - Int16GetDatum(i)))); + Int16GetDatum(i)))); } } } @@ -213,11 +213,11 @@ smgrunlink(int16 which, Relation reln) /* * NOTE: if the relation was created in this transaction, it will now - * be present in the pending-delete list twice, once with atCommit true - * and once with atCommit false. Hence, it will be physically deleted - * at end of xact in either case (and the other entry will be ignored - * by smgrDoPendingDeletes, so no error will occur). We could instead - * remove the existing list entry and delete the physical file + * be present in the pending-delete list twice, once with atCommit + * true and once with atCommit false. Hence, it will be physically + * deleted at end of xact in either case (and the other entry will be + * ignored by smgrDoPendingDeletes, so no error will occur). We could + * instead remove the existing list entry and delete the physical file * immediately, but for now I'll keep the logic simple. */ @@ -259,7 +259,7 @@ smgropen(int16 which, Relation reln, bool failOK) if (reln->rd_rel->relkind == RELKIND_VIEW) return -1; if ((fd = (*(smgrsw[which].smgr_open)) (reln)) < 0) - if (! failOK) + if (!failOK) elog(ERROR, "cannot open %s: %m", RelationGetRelationName(reln)); return fd; @@ -475,17 +475,20 @@ smgrDoPendingDeletes(bool isCommit) pendingDeletes = pending->next; if (pending->atCommit == isCommit) { + /* * 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). + * any in the commit case, but there can be in the abort + * case). */ DropRelFileNodeBuffers(pending->relnode); + /* * And delete the physical files. * * Note: we treat deletion failure as a NOTICE, not an error, - * because we've already decided to commit or abort the current - * xact. + * because we've already decided to commit or abort the + * current xact. */ if ((*(smgrsw[pending->which].smgr_unlink)) (pending->relnode) == SM_FAIL) elog(NOTICE, "cannot unlink %u/%u: %m", @@ -513,7 +516,7 @@ smgrcommit() if ((*(smgrsw[i].smgr_commit)) () == SM_FAIL) elog(FATAL, "transaction commit failed on %s: %m", DatumGetCString(DirectFunctionCall1(smgrout, - Int16GetDatum(i)))); + Int16GetDatum(i)))); } } @@ -532,7 +535,7 @@ smgrabort() if ((*(smgrsw[i].smgr_abort)) () == SM_FAIL) elog(FATAL, "transaction abort failed on %s: %m", DatumGetCString(DirectFunctionCall1(smgrout, - Int16GetDatum(i)))); + Int16GetDatum(i)))); } } @@ -551,7 +554,7 @@ smgrsync() if ((*(smgrsw[i].smgr_sync)) () == SM_FAIL) elog(STOP, "storage sync failed on %s: %m", DatumGetCString(DirectFunctionCall1(smgrout, - Int16GetDatum(i)))); + Int16GetDatum(i)))); } } @@ -579,8 +582,8 @@ void smgr_undo(XLogRecPtr lsn, XLogRecord *record) { } - + void -smgr_desc(char *buf, uint8 xl_info, char* rec) +smgr_desc(char *buf, uint8 xl_info, char *rec) { } |