diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2014-04-30 17:30:50 -0400 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2014-04-30 17:30:50 -0400 |
| commit | 2d00190495b22e0d0ba351b2cda9c95fb2e3d083 (patch) | |
| tree | 18500aeaf8ea3187f8a22ecb23581b7348316438 /src/include | |
| parent | 0bff398761b5e6119b40550bbe3751f4194dc7a7 (diff) | |
| download | postgresql-2d00190495b22e0d0ba351b2cda9c95fb2e3d083.tar.gz | |
Rationalize common/relpath.[hc].
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.
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/catalog/catalog.h | 12 | ||||
| -rw-r--r-- | src/include/common/relpath.h | 60 | ||||
| -rw-r--r-- | src/include/storage/relfilenode.h | 23 |
3 files changed, 55 insertions, 40 deletions
diff --git a/src/include/catalog/catalog.h b/src/include/catalog/catalog.h index 534a081592..9d63ac22c8 100644 --- a/src/include/catalog/catalog.h +++ b/src/include/catalog/catalog.h @@ -14,13 +14,17 @@ #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); diff --git a/src/include/common/relpath.h b/src/include/common/relpath.h index 23a226d058..cdd9316f08 100644 --- a/src/include/common/relpath.h +++ b/src/include/common/relpath.h @@ -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 @@ -14,29 +14,61 @@ #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 */ diff --git a/src/include/storage/relfilenode.h b/src/include/storage/relfilenode.h index 8616bd3a1e..d5b772ca9f 100644 --- a/src/include/storage/relfilenode.h +++ b/src/include/storage/relfilenode.h @@ -14,31 +14,10 @@ #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 * separately. Note, however, that a "physical" relation is comprised of |
