Rationalize common/relpath.[hc].
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 30 Apr 2014 21:30:50 +0000 (17:30 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 30 Apr 2014 21:30:50 +0000 (17:30 -0400)
Commit a73018392636ce832b09b5c31f6ad1f18a4643ea created rather a mess by
putting dependencies on backend-only include files into include/common.
We really shouldn't do that.  To clean it up:

* Move TABLESPACE_VERSION_DIRECTORY back to its longtime home in
catalog/catalog.h.  We won't consider this symbol part of the FE/BE API.

* Push enum ForkNumber from relfilenode.h into relpath.h.  We'll consider
relpath.h as the source of truth for fork numbers, since relpath.c was
already partially serving that function, and anyway relfilenode.h was
kind of a random place for that enum.

* So, relfilenode.h now includes relpath.h rather than vice-versa.  This
direction of dependency is fine.  (That allows most, but not quite all,
of the existing explicit #includes of relpath.h to go away again.)

* Push forkname_to_number from catalog.c to relpath.c, just to centralize
fork number stuff a bit better.

* Push GetDatabasePath from catalog.c to relpath.c; it was rather odd
that the previous commit didn't keep this together with relpath().

* To avoid needing relfilenode.h in common/, redefine the underlying
function (now called GetRelationPath) as taking separate OID arguments,
and make the APIs using RelFileNode or RelFileNodeBackend into macro
wrappers.  (The macros have a potential multiple-eval risk, but none of
the existing call sites have an issue with that; one of them had such a
risk already anyway.)

* Fix failure to follow the directions when "init" fork type was added;
specifically, the errhint in forkname_to_number wasn't updated, and neither
was the SGML documentation for pg_relation_size().

* Fix tablespace-path-too-long check in CreateTableSpace() to account for
fork-name component of maximum-length pathnames.  This requires putting
FORKNAMECHARS into a header file, but it was rather useless (and
actually unreferenced) where it was.

The last couple of items are potentially back-patchable bug fixes,
if anyone is sufficiently excited about them; but personally I'm not.

Per a gripe from Christoph Berg about how include/common wasn't
self-contained.

22 files changed:
contrib/pg_xlogdump/pg_xlogdump.c
doc/src/sgml/func.sgml
src/backend/access/rmgrdesc/smgrdesc.c
src/backend/access/rmgrdesc/xactdesc.c
src/backend/access/rmgrdesc/xlogdesc.c
src/backend/access/transam/xlogutils.c
src/backend/catalog/catalog.c
src/backend/commands/tablecmds.c
src/backend/commands/tablespace.c
src/backend/replication/basebackup.c
src/backend/replication/logical/reorderbuffer.c
src/backend/storage/buffer/bufmgr.c
src/backend/storage/buffer/localbuf.c
src/backend/storage/file/fd.c
src/backend/storage/smgr/md.c
src/backend/utils/adt/dbsize.c
src/backend/utils/adt/misc.c
src/backend/utils/cache/relcache.c
src/common/relpath.c
src/include/catalog/catalog.h
src/include/common/relpath.h
src/include/storage/relfilenode.h

index 3fb9099649d72a627de305e5b713c6f9ae644779..31b5d7589aa3a25766b048fa871e1e7f267cb32b 100644 (file)
@@ -19,7 +19,6 @@
 #include "access/xlogreader.h"
 #include "access/transam.h"
 #include "common/fe_memutils.h"
-#include "common/relpath.h"
 #include "getopt_long.h"
 #include "rmgrdesc.h"
 
index 3a83ab2216ce6629b33e97fff9d1a042787338f1..d04dd747af8631c80160ce5871d4f63e36575360 100644 (file)
@@ -16847,7 +16847,7 @@ postgres=# SELECT * FROM pg_xlogfile_name_offset(pg_stop_backup());
        <entry><type>bigint</type></entry>
        <entry>
         Disk space used by the specified fork (<literal>'main'</literal>,
-        <literal>'fsm'</literal> or <literal>'vm'</>)
+        <literal>'fsm'</literal>, <literal>'vm'</>, or <literal>'init'</>)
         of the specified table or index
        </entry>
       </row>
@@ -16951,14 +16951,16 @@ postgres=# SELECT * FROM pg_xlogfile_name_offset(pg_stop_backup());
 
    <para>
     <function>pg_relation_size</> accepts the OID or name of a table, index or
-    toast table, and returns the on-disk size in bytes. Specifying
-    <literal>'main'</literal> or leaving out the second argument returns the
-    size of the main data fork of the relation. Specifying
-    <literal>'fsm'</literal> returns the size of the
-    Free Space Map (see <xref linkend="storage-fsm">) associated with the
-    relation. Specifying <literal>'vm'</literal> returns the size of the
-    Visibility Map (see <xref linkend="storage-vm">) associated with the
-    relation.  Note that this function shows the size of only one fork;
+    toast table, and returns the on-disk size in bytes.
+    Specifying <literal>'main'</literal> or leaving out the second argument
+    returns the size of the main data fork of the relation.
+    Specifying <literal>'fsm'</literal> returns the size of the Free Space
+    Map (see <xref linkend="storage-fsm">) associated with the relation.
+    Specifying <literal>'vm'</literal> returns the size of the Visibility
+    Map (see <xref linkend="storage-vm">) associated with the relation.
+    Specifying <literal>'init'</literal> returns the size of the
+    initialization fork, if any, associated with the relation.
+    Note that this function shows the size of only one fork;
     for most purposes it is more convenient to use the higher-level
     functions <function>pg_total_relation_size</> or
     <function>pg_table_size</>.
index 2e451a9ea8d4f11e4cf52f4cb3004e54246a5994..aa72d4c4c3a6dd27dfc14c3c47acbe6451aa1468 100644 (file)
@@ -16,7 +16,6 @@
 
 #include "catalog/catalog.h"
 #include "catalog/storage_xlog.h"
-#include "common/relpath.h"
 
 
 void
index e8fabc174e28ff679a0f3cbbd323f0b7db92bbb8..7c43d4c06fdcd4358e53e2a8409412e7097342ed 100644 (file)
@@ -16,7 +16,6 @@
 
 #include "access/xact.h"
 #include "catalog/catalog.h"
-#include "common/relpath.h"
 #include "storage/sinval.h"
 #include "utils/timestamp.h"
 
index cc9a472e1fa75df386e4a75f3ee20997c730eac7..e3d7b6681f3d3b3fba17f4d55ac34d028279c988 100644 (file)
@@ -17,7 +17,6 @@
 #include "access/xlog.h"
 #include "access/xlog_internal.h"
 #include "catalog/pg_control.h"
-#include "common/relpath.h"
 #include "utils/guc.h"
 #include "utils/timestamp.h"
 
index 05e74de92119fadbaad275ecaac40981d79ed971..b7829ff4c6ddce25e2ffcbde9858acf8dbfc5377 100644 (file)
@@ -20,7 +20,6 @@
 #include "access/xlog.h"
 #include "access/xlogutils.h"
 #include "catalog/catalog.h"
-#include "common/relpath.h"
 #include "storage/smgr.h"
 #include "utils/guc.h"
 #include "utils/hsearch.h"
index 282e0b9ae8cba5a023f23157aeb9a0ccdeac9afd..3ec360c2be55f4acea7e87fd48388205902fa47c 100644 (file)
@@ -37,7 +37,6 @@
 #include "catalog/pg_shseclabel.h"
 #include "catalog/pg_tablespace.h"
 #include "catalog/toasting.h"
-#include "common/relpath.h"
 #include "miscadmin.h"
 #include "storage/fd.h"
 #include "utils/fmgroids.h"
 #include "utils/tqual.h"
 
 
-
-/*
- * forkname_to_number - look up fork number by name
- */
-ForkNumber
-forkname_to_number(char *forkName)
-{
-   ForkNumber  forkNum;
-
-   for (forkNum = 0; forkNum <= MAX_FORKNUM; forkNum++)
-       if (strcmp(forkNames[forkNum], forkName) == 0)
-           return forkNum;
-
-   ereport(ERROR,
-           (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-            errmsg("invalid fork name"),
-            errhint("Valid fork names are \"main\", \"fsm\", and \"vm\".")));
-   return InvalidForkNumber;   /* keep compiler quiet */
-}
-
-/*
- * GetDatabasePath         - construct path to a database dir
- *
- * Result is a palloc'd string.
- *
- * XXX this must agree with relpath()!
- */
-char *
-GetDatabasePath(Oid dbNode, Oid spcNode)
-{
-   if (spcNode == GLOBALTABLESPACE_OID)
-   {
-       /* Shared system relations live in {datadir}/global */
-       Assert(dbNode == 0);
-       return pstrdup("global");
-   }
-   else if (spcNode == DEFAULTTABLESPACE_OID)
-   {
-       /* The default tablespace is {datadir}/base */
-       return psprintf("base/%u", dbNode);
-   }
-   else
-   {
-       /* All other tablespaces are accessed via symlinks */
-       return psprintf("pg_tblspc/%u/%s/%u",
-                       spcNode, TABLESPACE_VERSION_DIRECTORY, dbNode);
-   }
-}
-
-
 /*
  * IsSystemRelation
  *     True iff the relation is either a system catalog or toast table.
index f5ae98ff80e99d407f7e9158cb867c54997e5bf7..619aa78d809c0f018a081700a3243ce2d313da35 100644 (file)
@@ -51,7 +51,6 @@
 #include "commands/tablespace.h"
 #include "commands/trigger.h"
 #include "commands/typecmds.h"
-#include "common/relpath.h"
 #include "executor/executor.h"
 #include "foreign/foreign.h"
 #include "miscadmin.h"
index 9421dc2e4e0b6f0a0079cd7181bc84fbc95654f9..357e6e1974112a84c63df0eb7de37e9f8fd14d09 100644 (file)
@@ -68,7 +68,6 @@
 #include "commands/tablecmds.h"
 #include "commands/tablespace.h"
 #include "commands/user.h"
-#include "common/relpath.h"
 #include "miscadmin.h"
 #include "postmaster/bgwriter.h"
 #include "storage/fd.h"
@@ -278,11 +277,11 @@ CreateTableSpace(CreateTableSpaceStmt *stmt)
 
    /*
     * Check that location isn't too long. Remember that we're going to append
-    * 'PG_XXX/<dboid>/<relid>.<nnn>'.  FYI, we never actually reference the
-    * whole path, but mkdir() uses the first two parts.
+    * 'PG_XXX/<dboid>/<relid>_<fork>.<nnn>'.  FYI, we never actually
+    * reference the whole path here, but mkdir() uses the first two parts.
     */
    if (strlen(location) + 1 + strlen(TABLESPACE_VERSION_DIRECTORY) + 1 +
-       OIDCHARS + 1 + OIDCHARS + 1 + OIDCHARS > MAXPGPATH)
+       OIDCHARS + 1 + OIDCHARS + 1 + FORKNAMECHARS + 1 + OIDCHARS > MAXPGPATH)
        ereport(ERROR,
                (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
                 errmsg("tablespace location \"%s\" is too long",
index f611f591b61180d114982d5106896012a8589838..42e66f2fed7cd7e68734f319bf23d0d88333845b 100644 (file)
@@ -18,8 +18,8 @@
 #include <time.h>
 
 #include "access/xlog_internal.h"      /* for pg_start/stop_backup */
+#include "catalog/catalog.h"
 #include "catalog/pg_type.h"
-#include "common/relpath.h"
 #include "lib/stringinfo.h"
 #include "libpq/libpq.h"
 #include "libpq/pqformat.h"
index 4493930eda0a40df78979ead57ed3d7dd98c330e..a89099b50366c585c3fcb324bf8e58cf857ee1e8 100644 (file)
 #include <unistd.h>
 #include <sys/stat.h>
 
-#include "miscadmin.h"
-
 #include "access/rewriteheap.h"
 #include "access/transam.h"
 #include "access/tuptoaster.h"
 #include "access/xact.h"
-
 #include "catalog/catalog.h"
-
-#include "common/relpath.h"
-
 #include "lib/binaryheap.h"
-
+#include "miscadmin.h"
 #include "replication/logical.h"
 #include "replication/reorderbuffer.h"
 #include "replication/slot.h"
 #include "replication/snapbuild.h" /* just for SnapBuildSnapDecRefcount */
-
 #include "storage/bufmgr.h"
 #include "storage/fd.h"
 #include "storage/sinval.h"
-
 #include "utils/builtins.h"
 #include "utils/combocid.h"
 #include "utils/memdebug.h"
@@ -80,6 +72,7 @@
 #include "utils/relfilenodemap.h"
 #include "utils/tqual.h"
 
+
 /* entry for a hash table we use to map from xid to our transaction state */
 typedef struct ReorderBufferTXNByIdEnt
 {
index 4e46ddbba29c19daee7483684cbaf2c65303e52c..246f31bfe14eb73093e1ff4013349c06a00f16e8 100644 (file)
@@ -35,7 +35,6 @@
 
 #include "catalog/catalog.h"
 #include "catalog/storage.h"
-#include "common/relpath.h"
 #include "executor/instrument.h"
 #include "miscadmin.h"
 #include "pg_trace.h"
index 054aff717c785b042f990cf6f95669fbf2b14afe..62adc1ce6bab3fb6a3f2d957f1a6c37e008d86bc 100644 (file)
@@ -16,7 +16,6 @@
 #include "postgres.h"
 
 #include "catalog/catalog.h"
-#include "common/relpath.h"
 #include "executor/instrument.h"
 #include "storage/buf_internals.h"
 #include "storage/bufmgr.h"
index 42dbe87ca4bd5e8440661e018f48b05dcb4a1d87..0560bf9d72b1f27d3455cad716365db29350f5b8 100644 (file)
@@ -71,7 +71,6 @@
 #include "access/xact.h"
 #include "catalog/catalog.h"
 #include "catalog/pg_tablespace.h"
-#include "common/relpath.h"
 #include "pgstat.h"
 #include "storage/fd.h"
 #include "storage/ipc.h"
index 8133a337f7b53dc8c312674942df7d7c49031145..921861b0bd504209c40cee775110875182844d4b 100644 (file)
@@ -28,7 +28,6 @@
 #include "miscadmin.h"
 #include "access/xlog.h"
 #include "catalog/catalog.h"
-#include "common/relpath.h"
 #include "portability/instr_time.h"
 #include "postmaster/bgwriter.h"
 #include "storage/fd.h"
index 78fe4688226aa181c6b4c240e2a3a67698def320..68ab0e190616ab09983a2ae750bdf9957d5138a5 100644 (file)
@@ -21,7 +21,6 @@
 #include "catalog/pg_tablespace.h"
 #include "commands/dbcommands.h"
 #include "commands/tablespace.h"
-#include "common/relpath.h"
 #include "miscadmin.h"
 #include "storage/fd.h"
 #include "utils/acl.h"
index e3893db658534377326a4ee5d98004d6c7a0ab5e..241f738d608bdf868d3891a7c37a163ef968f7b7 100644 (file)
@@ -25,7 +25,6 @@
 #include "catalog/pg_tablespace.h"
 #include "catalog/pg_type.h"
 #include "commands/dbcommands.h"
-#include "common/relpath.h"
 #include "funcapi.h"
 #include "miscadmin.h"
 #include "parser/keywords.h"
index c8cea028d4e67a8af5d144cc6bbfe4268ad63425..c947bff4fca6f68ec139ae3eda6ccd15791e8e21 100644 (file)
@@ -56,7 +56,6 @@
 #include "catalog/schemapg.h"
 #include "catalog/storage.h"
 #include "commands/trigger.h"
-#include "common/relpath.h"
 #include "miscadmin.h"
 #include "optimizer/clauses.h"
 #include "optimizer/planmain.h"
index fbb5de6922b8082467c95350fdbbba56fc2722cd..fc8b2732eaa7cccc381e2cc13030fedd59562049 100644 (file)
@@ -1,6 +1,8 @@
 /*-------------------------------------------------------------------------
  * relpath.c
- *     Shared frontend/backend code to find out pathnames of relation files
+ *     Shared frontend/backend code to compute pathnames of relation files
+ *
+ * This module also contains some logic associated with fork names.
  *
  * Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
 #include "postgres_fe.h"
 #endif
 
+#include "catalog/catalog.h"
 #include "catalog/pg_tablespace.h"
 #include "common/relpath.h"
 #include "storage/backendid.h"
 
-#define FORKNAMECHARS  4       /* max chars for a fork name */
 
 /*
  * Lookup table of fork name by fork number.
  *
- * If you add a new entry, remember to update the errhint below, and the
- * documentation for pg_relation_size(). Also keep FORKNAMECHARS above
- * up-to-date.
+ * If you add a new entry, remember to update the errhint in
+ * forkname_to_number() below, and update the SGML documentation for
+ * pg_relation_size().
  */
 const char *const forkNames[] = {
    "main",                     /* MAIN_FORKNUM */
@@ -36,6 +38,32 @@ const char *const forkNames[] = {
    "init"                      /* INIT_FORKNUM */
 };
 
+/*
+ * forkname_to_number - look up fork number by name
+ *
+ * In backend, we throw an error for no match; in frontend, we just
+ * return InvalidForkNumber.
+ */
+ForkNumber
+forkname_to_number(const char *forkName)
+{
+   ForkNumber  forkNum;
+
+   for (forkNum = 0; forkNum <= MAX_FORKNUM; forkNum++)
+       if (strcmp(forkNames[forkNum], forkName) == 0)
+           return forkNum;
+
+#ifndef FRONTEND
+   ereport(ERROR,
+           (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+            errmsg("invalid fork name"),
+            errhint("Valid fork names are \"main\", \"fsm\", "
+                    "\"vm\", and \"init\".")));
+#endif
+
+   return InvalidForkNumber;
+}
+
 /*
  * forkname_chars
  *     We use this to figure out whether a filename could be a relation
@@ -63,80 +91,117 @@ forkname_chars(const char *str, ForkNumber *fork)
            return len;
        }
    }
+   if (fork)
+       *fork = InvalidForkNumber;
    return 0;
 }
 
+
+/*
+ * GetDatabasePath - construct path to a database directory
+ *
+ * Result is a palloc'd string.
+ *
+ * XXX this must agree with GetRelationPath()!
+ */
+char *
+GetDatabasePath(Oid dbNode, Oid spcNode)
+{
+   if (spcNode == GLOBALTABLESPACE_OID)
+   {
+       /* Shared system relations live in {datadir}/global */
+       Assert(dbNode == 0);
+       return pstrdup("global");
+   }
+   else if (spcNode == DEFAULTTABLESPACE_OID)
+   {
+       /* The default tablespace is {datadir}/base */
+       return psprintf("base/%u", dbNode);
+   }
+   else
+   {
+       /* All other tablespaces are accessed via symlinks */
+       return psprintf("pg_tblspc/%u/%s/%u",
+                       spcNode, TABLESPACE_VERSION_DIRECTORY, dbNode);
+   }
+}
+
 /*
- * relpathbackend - construct path to a relation's file
+ * GetRelationPath - construct path to a relation's file
  *
  * Result is a palloc'd string.
+ *
+ * Note: ideally, backendId would be declared as type BackendId, but relpath.h
+ * would have to include a backend-only header to do that; doesn't seem worth
+ * the trouble considering BackendId is just int anyway.
  */
 char *
-relpathbackend(RelFileNode rnode, BackendId backend, ForkNumber forknum)
+GetRelationPath(Oid dbNode, Oid spcNode, Oid relNode,
+               int backendId, ForkNumber forkNumber)
 {
    char       *path;
 
-   if (rnode.spcNode == GLOBALTABLESPACE_OID)
+   if (spcNode == GLOBALTABLESPACE_OID)
    {
        /* Shared system relations live in {datadir}/global */
-       Assert(rnode.dbNode == 0);
-       Assert(backend == InvalidBackendId);
-       if (forknum != MAIN_FORKNUM)
+       Assert(dbNode == 0);
+       Assert(backendId == InvalidBackendId);
+       if (forkNumber != MAIN_FORKNUM)
            path = psprintf("global/%u_%s",
-                    rnode.relNode, forkNames[forknum]);
+                           relNode, forkNames[forkNumber]);
        else
-           path = psprintf("global/%u", rnode.relNode);
+           path = psprintf("global/%u", relNode);
    }
-   else if (rnode.spcNode == DEFAULTTABLESPACE_OID)
+   else if (spcNode == DEFAULTTABLESPACE_OID)
    {
        /* The default tablespace is {datadir}/base */
-       if (backend == InvalidBackendId)
+       if (backendId == InvalidBackendId)
        {
-           if (forknum != MAIN_FORKNUM)
+           if (forkNumber != MAIN_FORKNUM)
                path = psprintf("base/%u/%u_%s",
-                        rnode.dbNode, rnode.relNode,
-                        forkNames[forknum]);
+                               dbNode, relNode,
+                               forkNames[forkNumber]);
            else
                path = psprintf("base/%u/%u",
-                        rnode.dbNode, rnode.relNode);
+                               dbNode, relNode);
        }
        else
        {
-           if (forknum != MAIN_FORKNUM)
+           if (forkNumber != MAIN_FORKNUM)
                path = psprintf("base/%u/t%d_%u_%s",
-                        rnode.dbNode, backend, rnode.relNode,
-                        forkNames[forknum]);
+                               dbNode, backendId, relNode,
+                               forkNames[forkNumber]);
            else
                path = psprintf("base/%u/t%d_%u",
-                        rnode.dbNode, backend, rnode.relNode);
+                               dbNode, backendId, relNode);
        }
    }
    else
    {
        /* All other tablespaces are accessed via symlinks */
-       if (backend == InvalidBackendId)
+       if (backendId == InvalidBackendId)
        {
-           if (forknum != MAIN_FORKNUM)
+           if (forkNumber != MAIN_FORKNUM)
                path = psprintf("pg_tblspc/%u/%s/%u/%u_%s",
-                        rnode.spcNode, TABLESPACE_VERSION_DIRECTORY,
-                        rnode.dbNode, rnode.relNode,
-                        forkNames[forknum]);
+                               spcNode, TABLESPACE_VERSION_DIRECTORY,
+                               dbNode, relNode,
+                               forkNames[forkNumber]);
            else
                path = psprintf("pg_tblspc/%u/%s/%u/%u",
-                        rnode.spcNode, TABLESPACE_VERSION_DIRECTORY,
-                        rnode.dbNode, rnode.relNode);
+                               spcNode, TABLESPACE_VERSION_DIRECTORY,
+                               dbNode, relNode);
        }
        else
        {
-           if (forknum != MAIN_FORKNUM)
+           if (forkNumber != MAIN_FORKNUM)
                path = psprintf("pg_tblspc/%u/%s/%u/t%d_%u_%s",
-                        rnode.spcNode, TABLESPACE_VERSION_DIRECTORY,
-                        rnode.dbNode, backend, rnode.relNode,
-                        forkNames[forknum]);
+                               spcNode, TABLESPACE_VERSION_DIRECTORY,
+                               dbNode, backendId, relNode,
+                               forkNames[forkNumber]);
            else
                path = psprintf("pg_tblspc/%u/%s/%u/t%d_%u",
-                        rnode.spcNode, TABLESPACE_VERSION_DIRECTORY,
-                        rnode.dbNode, backend, rnode.relNode);
+                               spcNode, TABLESPACE_VERSION_DIRECTORY,
+                               dbNode, backendId, relNode);
        }
    }
    return path;
index 534a08159209c46365654fbb93b964bfb44d560c..9d63ac22c8e81cf9a7c1b53f8377c5e12ab9e4c6 100644 (file)
 #ifndef CATALOG_H
 #define CATALOG_H
 
+/*
+ * 'pgrminclude ignore' needed here because CppAsString2() does not throw
+ * an error if the symbol is not defined.
+ */
+#include "catalog/catversion.h" /* pgrminclude ignore */
 #include "catalog/pg_class.h"
-#include "storage/relfilenode.h"
 #include "utils/relcache.h"
 
-extern ForkNumber forkname_to_number(char *forkName);
-
-extern char *GetDatabasePath(Oid dbNode, Oid spcNode);
+#define OIDCHARS       10      /* max chars printed by %u */
+#define TABLESPACE_VERSION_DIRECTORY   "PG_" PG_MAJORVERSION "_" \
+                                   CppAsString2(CATALOG_VERSION_NO)
 
 
 extern bool IsSystemRelation(Relation relation);
index 23a226d058e80afff5447e1eea4c6e217d2133fc..cdd9316f08b5ae67dab0c32cbea2adc5e927a363 100644 (file)
@@ -1,7 +1,7 @@
 /*-------------------------------------------------------------------------
  *
  * relpath.h
- *     Declarations for relpath() and friends
+ *     Declarations for GetRelationPath() and friends
  *
  * Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
 #define RELPATH_H
 
 /*
- * 'pgrminclude ignore' needed here because CppAsString2() does not throw
- * an error if the symbol is not defined.
+ * Stuff for fork names.
+ *
+ * The physical storage of a relation consists of one or more forks.
+ * The main fork is always created, but in addition to that there can be
+ * additional forks for storing various metadata. ForkNumber is used when
+ * we need to refer to a specific fork in a relation.
  */
-#include "catalog/catversion.h" /* pgrminclude ignore */
-#include "storage/relfilenode.h"
+typedef enum ForkNumber
+{
+   InvalidForkNumber = -1,
+   MAIN_FORKNUM = 0,
+   FSM_FORKNUM,
+   VISIBILITYMAP_FORKNUM,
+   INIT_FORKNUM
+
+   /*
+    * NOTE: if you add a new fork, change MAX_FORKNUM and possibly
+    * FORKNAMECHARS below, and update the forkNames array in
+    * src/common/relpath.c
+    */
+} ForkNumber;
 
+#define MAX_FORKNUM        INIT_FORKNUM
 
-#define OIDCHARS       10      /* max chars printed by %u */
-#define TABLESPACE_VERSION_DIRECTORY   "PG_" PG_MAJORVERSION "_" \
-                                   CppAsString2(CATALOG_VERSION_NO)
+#define FORKNAMECHARS  4       /* max chars for a fork name */
 
 extern const char *const forkNames[];
 
+extern ForkNumber forkname_to_number(const char *forkName);
 extern int forkname_chars(const char *str, ForkNumber *fork);
-extern char *relpathbackend(RelFileNode rnode, BackendId backend,
-              ForkNumber forknum);
 
-/* First argument is a RelFileNodeBackend */
-#define relpath(rnode, forknum) \
-       relpathbackend((rnode).node, (rnode).backend, (forknum))
+/*
+ * Stuff for computing filesystem pathnames for relations.
+ */
+extern char *GetDatabasePath(Oid dbNode, Oid spcNode);
+
+extern char *GetRelationPath(Oid dbNode, Oid spcNode, Oid relNode,
+               int backendId, ForkNumber forkNumber);
+
+/*
+ * Wrapper macros for GetRelationPath. Beware of multiple
+ * evaluation of the RelFileNode or RelFileNodeBackend argument!
+ */
+
+/* First argument is a RelFileNode */
+#define relpathbackend(rnode, backend, forknum) \
+   GetRelationPath((rnode).dbNode, (rnode).spcNode, (rnode).relNode, \
+                   backend, forknum)
 
 /* First argument is a RelFileNode */
 #define relpathperm(rnode, forknum) \
-       relpathbackend((rnode), InvalidBackendId, (forknum))
+   relpathbackend(rnode, InvalidBackendId, forknum)
+
+/* First argument is a RelFileNodeBackend */
+#define relpath(rnode, forknum) \
+   relpathbackend((rnode).node, (rnode).backend, forknum)
 
 #endif   /* RELPATH_H */
index 8616bd3a1ecd9f6b39d272327418c90d9a1abd89..d5b772ca9f678b2e82b6a282c253d5b75b9cefba 100644 (file)
 #ifndef RELFILENODE_H
 #define RELFILENODE_H
 
+#include "common/relpath.h"
 #include "storage/backendid.h"
 
-/*
- * The physical storage of a relation consists of one or more forks. The
- * main fork is always created, but in addition to that there can be
- * additional forks for storing various metadata. ForkNumber is used when
- * we need to refer to a specific fork in a relation.
- */
-typedef enum ForkNumber
-{
-   InvalidForkNumber = -1,
-   MAIN_FORKNUM = 0,
-   FSM_FORKNUM,
-   VISIBILITYMAP_FORKNUM,
-   INIT_FORKNUM
-
-   /*
-    * NOTE: if you add a new fork, change MAX_FORKNUM below and update the
-    * forkNames array in src/common/relpath.c
-    */
-} ForkNumber;
-
-#define MAX_FORKNUM        INIT_FORKNUM
-
 /*
  * RelFileNode must provide all that we need to know to physically access
  * a relation, with the exception of the backend ID, which can be provided