From 6fa24d975e21435bda6f929e3d9ba5bdbe78fa5d Mon Sep 17 00:00:00 2001 From: Thomas Munro Date: Tue, 30 Apr 2019 22:11:03 +1200 Subject: [PATCH 02/14] Move tablespace dir creation from smgr.c to md.c. For undo logs, we don't need to create tablespace directories when opening a relation, because that is managed automatically by undolog.c. Author: Thomas Munro --- src/backend/storage/smgr/md.c | 14 ++++++++++++++ src/backend/storage/smgr/smgr.c | 14 -------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/backend/storage/smgr/md.c b/src/backend/storage/smgr/md.c index 6c576ed..4c9d448 100644 --- a/src/backend/storage/smgr/md.c +++ b/src/backend/storage/smgr/md.c @@ -28,6 +28,7 @@ #include "miscadmin.h" #include "access/xlogutils.h" #include "access/xlog.h" +#include "commands/tablespace.h" #include "pgstat.h" #include "postmaster/bgwriter.h" #include "storage/fd.h" @@ -196,6 +197,19 @@ mdcreate(SMgrRelation reln, ForkNumber forkNum, bool isRedo) Assert(reln->md_num_open_segs[forkNum] == 0); + /* + * 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.node.spcNode, + reln->smgr_rnode.node.dbNode, + isRedo); + path = relpath(reln->smgr_rnode, forkNum); fd = PathNameOpenFile(path, O_RDWR | O_CREAT | O_EXCL | PG_BINARY); diff --git a/src/backend/storage/smgr/smgr.c b/src/backend/storage/smgr/smgr.c index 26281fa..4ba07a0 100644 --- a/src/backend/storage/smgr/smgr.c +++ b/src/backend/storage/smgr/smgr.c @@ -17,7 +17,6 @@ */ #include "postgres.h" -#include "commands/tablespace.h" #include "lib/ilist.h" #include "storage/bufmgr.h" #include "storage/ipc.h" @@ -343,19 +342,6 @@ smgrcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo) if (isRedo && reln->md_num_open_segs[forknum] > 0) 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.node.spcNode, - reln->smgr_rnode.node.dbNode, - isRedo); - smgrsw[reln->smgr_which].smgr_create(reln, forknum, isRedo); } -- 1.8.3.1