Hi, This trivial patch moves a misplaced tablespace.c call from smgr.c into the newly created storage.c. This is appropriate because smgr.c is supposed to be bare metal, and storage.c has the high-level calls.
-- Alvaro Herrera http://www.CommandPrompt.com/ PostgreSQL Replication, Consulting, Custom Development, 24x7 support
Index: src/backend/access/heap/visibilitymap.c =================================================================== RCS file: /home/alvherre/Code/cvs/pgsql/src/backend/access/heap/visibilitymap.c,v retrieving revision 1.3 diff -c -p -r1.3 visibilitymap.c *** src/backend/access/heap/visibilitymap.c 1 Jan 2009 17:23:35 -0000 1.3 --- src/backend/access/heap/visibilitymap.c 15 Jan 2009 13:03:31 -0000 *************** *** 88,97 **** #include "postgres.h" #include "access/visibilitymap.h" #include "storage/bufmgr.h" #include "storage/bufpage.h" #include "storage/lmgr.h" - #include "storage/smgr.h" #include "utils/inval.h" /*#define TRACE_VISIBILITYMAP */ --- 88,97 ---- #include "postgres.h" #include "access/visibilitymap.h" + #include "catalog/storage.h" #include "storage/bufmgr.h" #include "storage/bufpage.h" #include "storage/lmgr.h" #include "utils/inval.h" /*#define TRACE_VISIBILITYMAP */ *************** vm_extend(Relation rel, BlockNumber vm_n *** 454,460 **** if ((rel->rd_vm_nblocks == 0 || rel->rd_vm_nblocks == InvalidBlockNumber) && !smgrexists(rel->rd_smgr, VISIBILITYMAP_FORKNUM)) { ! smgrcreate(rel->rd_smgr, VISIBILITYMAP_FORKNUM, false); vm_nblocks_now = 0; } else --- 454,460 ---- if ((rel->rd_vm_nblocks == 0 || rel->rd_vm_nblocks == InvalidBlockNumber) && !smgrexists(rel->rd_smgr, VISIBILITYMAP_FORKNUM)) { ! StorageCreate(rel->rd_smgr, VISIBILITYMAP_FORKNUM, false); vm_nblocks_now = 0; } else Index: src/backend/access/transam/xlogutils.c =================================================================== RCS file: /home/alvherre/Code/cvs/pgsql/src/backend/access/transam/xlogutils.c,v retrieving revision 1.66 diff -c -p -r1.66 xlogutils.c *** src/backend/access/transam/xlogutils.c 1 Jan 2009 17:23:36 -0000 1.66 --- src/backend/access/transam/xlogutils.c 15 Jan 2009 12:14:42 -0000 *************** XLogReadBufferExtended(RelFileNode rnode *** 273,279 **** * filesystem loses an inode during a crash. Better to write the data * until we are actually told to delete the file.) */ ! smgrcreate(smgr, forknum, true); lastblock = smgrnblocks(smgr, forknum); --- 273,279 ---- * filesystem loses an inode during a crash. Better to write the data * until we are actually told to delete the file.) */ ! StorageCreate(smgr, forknum, true); lastblock = smgrnblocks(smgr, forknum); Index: src/backend/catalog/storage.c =================================================================== RCS file: /home/alvherre/Code/cvs/pgsql/src/backend/catalog/storage.c,v retrieving revision 1.4 diff -c -p -r1.4 storage.c *** src/backend/catalog/storage.c 4 Jan 2009 14:59:22 -0000 1.4 --- src/backend/catalog/storage.c 15 Jan 2009 13:14:26 -0000 *************** *** 24,29 **** --- 24,30 ---- #include "access/xlogutils.h" #include "catalog/catalog.h" #include "catalog/storage.h" + #include "commands/tablespace.h" #include "storage/freespace.h" #include "storage/smgr.h" #include "utils/memutils.h" *************** RelationCreateStorage(RelFileNode rnode, *** 104,110 **** SMgrRelation srel; srel = smgropen(rnode); ! smgrcreate(srel, MAIN_FORKNUM, false); if (!istemp) { --- 105,111 ---- SMgrRelation srel; srel = smgropen(rnode); ! StorageCreate(srel, MAIN_FORKNUM, false); if (!istemp) { *************** RelationCreateStorage(RelFileNode rnode, *** 134,139 **** --- 135,171 ---- } /* + * StorageCreate + * + * Given an already-created (but presumably unused) SMgrRelation, + * cause the underlying disk file or other storage for the fork + * to be created. + * + * This is the non-transactional, low-level counterpart to + * RelationCreateStorage. + */ + void + StorageCreate(SMgrRelation srel, ForkNumber forknum, bool isRedo) + { + /* + * Exit quickly in WAL replay mode if we've already opened the file. + * If it's open, it surely must exist. + */ + if (isRedo && srel->md_fd[forknum] != NULL) + return; + + /* + * We may be using the target table space for the first time in this + * database, so create a per-database subdirectory if needed. + */ + TablespaceCreateDbspace(srel->smgr_rnode.spcNode, + srel->smgr_rnode.dbNode, + isRedo); + + smgrcreate(srel, forknum, isRedo); + } + + /* * RelationDropStorage * Schedule unlinking of physical storage at transaction commit. */ *************** smgr_redo(XLogRecPtr lsn, XLogRecord *re *** 407,413 **** SMgrRelation reln; reln = smgropen(xlrec->rnode); ! smgrcreate(reln, MAIN_FORKNUM, true); } else if (info == XLOG_SMGR_TRUNCATE) { --- 439,445 ---- SMgrRelation reln; reln = smgropen(xlrec->rnode); ! StorageCreate(reln, MAIN_FORKNUM, true); } else if (info == XLOG_SMGR_TRUNCATE) { *************** smgr_redo(XLogRecPtr lsn, XLogRecord *re *** 422,428 **** * XLogOpenRelation, we prefer to recreate the rel and replay the log * as best we can until the drop is seen. */ ! smgrcreate(reln, MAIN_FORKNUM, true); smgrtruncate(reln, MAIN_FORKNUM, xlrec->blkno, false); --- 454,460 ---- * XLogOpenRelation, we prefer to recreate the rel and replay the log * as best we can until the drop is seen. */ ! StorageCreate(reln, MAIN_FORKNUM, true); smgrtruncate(reln, MAIN_FORKNUM, xlrec->blkno, false); Index: src/backend/commands/tablecmds.c =================================================================== RCS file: /home/alvherre/Code/cvs/pgsql/src/backend/commands/tablecmds.c,v retrieving revision 1.277 diff -c -p -r1.277 tablecmds.c *** src/backend/commands/tablecmds.c 12 Jan 2009 08:54:26 -0000 1.277 --- src/backend/commands/tablecmds.c 15 Jan 2009 13:05:00 -0000 *************** *** 65,71 **** #include "rewrite/rewriteHandler.h" #include "storage/bufmgr.h" #include "storage/lmgr.h" - #include "storage/smgr.h" #include "utils/acl.h" #include "utils/builtins.h" #include "utils/fmgroids.h" --- 65,70 ---- *************** ATExecSetTableSpace(Oid tableOid, Oid ne *** 6622,6628 **** { if (smgrexists(rel->rd_smgr, forkNum)) { ! smgrcreate(dstrel, forkNum, false); copy_relation_data(rel->rd_smgr, dstrel, forkNum, rel->rd_istemp); } } --- 6621,6627 ---- { if (smgrexists(rel->rd_smgr, forkNum)) { ! StorageCreate(dstrel, forkNum, false); copy_relation_data(rel->rd_smgr, dstrel, forkNum, rel->rd_istemp); } } Index: src/backend/storage/freespace/freespace.c =================================================================== RCS file: /home/alvherre/Code/cvs/pgsql/src/backend/storage/freespace/freespace.c,v retrieving revision 1.71 diff -c -p -r1.71 freespace.c *** src/backend/storage/freespace/freespace.c 1 Jan 2009 17:23:47 -0000 1.71 --- src/backend/storage/freespace/freespace.c 15 Jan 2009 13:03:10 -0000 *************** *** 25,37 **** #include "access/htup.h" #include "access/xlogutils.h" #include "storage/bufpage.h" #include "storage/bufmgr.h" #include "storage/freespace.h" #include "storage/fsm_internals.h" #include "storage/lmgr.h" #include "storage/lwlock.h" - #include "storage/smgr.h" #include "utils/rel.h" #include "utils/inval.h" #include "miscadmin.h" --- 25,37 ---- #include "access/htup.h" #include "access/xlogutils.h" + #include "catalog/storage.h" #include "storage/bufpage.h" #include "storage/bufmgr.h" #include "storage/freespace.h" #include "storage/fsm_internals.h" #include "storage/lmgr.h" #include "storage/lwlock.h" #include "utils/rel.h" #include "utils/inval.h" #include "miscadmin.h" *************** fsm_extend(Relation rel, BlockNumber fsm *** 564,570 **** if ((rel->rd_fsm_nblocks == 0 || rel->rd_fsm_nblocks == InvalidBlockNumber) && !smgrexists(rel->rd_smgr, FSM_FORKNUM)) { ! smgrcreate(rel->rd_smgr, FSM_FORKNUM, false); fsm_nblocks_now = 0; } else --- 564,570 ---- if ((rel->rd_fsm_nblocks == 0 || rel->rd_fsm_nblocks == InvalidBlockNumber) && !smgrexists(rel->rd_smgr, FSM_FORKNUM)) { ! StorageCreate(rel->rd_smgr, FSM_FORKNUM, false); fsm_nblocks_now = 0; } else Index: src/backend/storage/smgr/smgr.c =================================================================== RCS file: /home/alvherre/Code/cvs/pgsql/src/backend/storage/smgr/smgr.c,v retrieving revision 1.116 diff -c -p -r1.116 smgr.c *** src/backend/storage/smgr/smgr.c 12 Jan 2009 05:10:44 -0000 1.116 --- src/backend/storage/smgr/smgr.c 15 Jan 2009 12:15:24 -0000 *************** *** 19,25 **** #include "access/xlogutils.h" #include "catalog/catalog.h" - #include "commands/tablespace.h" #include "storage/bufmgr.h" #include "storage/ipc.h" #include "storage/smgr.h" --- 19,24 ---- *************** smgrclosenode(RelFileNode rnode) *** 281,310 **** * * If isRedo is true, it is okay for the underlying file to exist * already because we are in a WAL replay sequence. */ void smgrcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo) { - /* - * Exit quickly in WAL replay mode if we've already opened the file. - * If it's open, it surely must exist. - */ - if (isRedo && reln->md_fd[forknum] != NULL) - return; - - /* - * We may be using the target table space for the first time in this - * 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. - */ - TablespaceCreateDbspace(reln->smgr_rnode.spcNode, - reln->smgr_rnode.dbNode, - isRedo); - (*(smgrsw[reln->smgr_which].smgr_create)) (reln, forknum, isRedo); } --- 280,291 ---- * * If isRedo is true, it is okay for the underlying file to exist * already because we are in a WAL replay sequence. + * + * This shouldn't be called directly -- see StorageCreate instead. */ void smgrcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo) { (*(smgrsw[reln->smgr_which].smgr_create)) (reln, forknum, isRedo); } Index: src/include/catalog/storage.h =================================================================== RCS file: /home/alvherre/Code/cvs/pgsql/src/include/catalog/storage.h,v retrieving revision 1.3 diff -c -p -r1.3 storage.h *** src/include/catalog/storage.h 1 Jan 2009 17:23:58 -0000 1.3 --- src/include/catalog/storage.h 15 Jan 2009 13:02:33 -0000 *************** *** 14,25 **** #ifndef STORAGE_H #define STORAGE_H - #include "access/xlog.h" #include "lib/stringinfo.h" ! #include "storage/block.h" ! #include "storage/relfilenode.h" #include "utils/relcache.h" extern void RelationCreateStorage(RelFileNode rnode, bool istemp); extern void RelationDropStorage(Relation rel); extern void RelationTruncate(Relation rel, BlockNumber nblocks); --- 14,25 ---- #ifndef STORAGE_H #define STORAGE_H #include "lib/stringinfo.h" ! #include "storage/smgr.h" #include "utils/relcache.h" + + extern void StorageCreate(SMgrRelation srel, ForkNumber forknum, bool isRedo); extern void RelationCreateStorage(RelFileNode rnode, bool istemp); extern void RelationDropStorage(Relation rel); extern void RelationTruncate(Relation rel, BlockNumber nblocks);
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers