Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2d00190

Browse files
committed
Rationalize common/relpath.[hc].
Commit a730183 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.
1 parent 0bff398 commit 2d00190

File tree

22 files changed

+173
-163
lines changed

22 files changed

+173
-163
lines changed

contrib/pg_xlogdump/pg_xlogdump.c

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "access/xlogreader.h"
2020
#include "access/transam.h"
2121
#include "common/fe_memutils.h"
22-
#include "common/relpath.h"
2322
#include "getopt_long.h"
2423
#include "rmgrdesc.h"
2524

doc/src/sgml/func.sgml

+11-9
Original file line numberDiff line numberDiff line change
@@ -16847,7 +16847,7 @@ postgres=# SELECT * FROM pg_xlogfile_name_offset(pg_stop_backup());
1684716847
<entry><type>bigint</type></entry>
1684816848
<entry>
1684916849
Disk space used by the specified fork (<literal>'main'</literal>,
16850-
<literal>'fsm'</literal> or <literal>'vm'</>)
16850+
<literal>'fsm'</literal>, <literal>'vm'</>, or <literal>'init'</>)
1685116851
of the specified table or index
1685216852
</entry>
1685316853
</row>
@@ -16951,14 +16951,16 @@ postgres=# SELECT * FROM pg_xlogfile_name_offset(pg_stop_backup());
1695116951

1695216952
<para>
1695316953
<function>pg_relation_size</> accepts the OID or name of a table, index or
16954-
toast table, and returns the on-disk size in bytes. Specifying
16955-
<literal>'main'</literal> or leaving out the second argument returns the
16956-
size of the main data fork of the relation. Specifying
16957-
<literal>'fsm'</literal> returns the size of the
16958-
Free Space Map (see <xref linkend="storage-fsm">) associated with the
16959-
relation. Specifying <literal>'vm'</literal> returns the size of the
16960-
Visibility Map (see <xref linkend="storage-vm">) associated with the
16961-
relation. Note that this function shows the size of only one fork;
16954+
toast table, and returns the on-disk size in bytes.
16955+
Specifying <literal>'main'</literal> or leaving out the second argument
16956+
returns the size of the main data fork of the relation.
16957+
Specifying <literal>'fsm'</literal> returns the size of the Free Space
16958+
Map (see <xref linkend="storage-fsm">) associated with the relation.
16959+
Specifying <literal>'vm'</literal> returns the size of the Visibility
16960+
Map (see <xref linkend="storage-vm">) associated with the relation.
16961+
Specifying <literal>'init'</literal> returns the size of the
16962+
initialization fork, if any, associated with the relation.
16963+
Note that this function shows the size of only one fork;
1696216964
for most purposes it is more convenient to use the higher-level
1696316965
functions <function>pg_total_relation_size</> or
1696416966
<function>pg_table_size</>.

src/backend/access/rmgrdesc/smgrdesc.c

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
#include "catalog/catalog.h"
1818
#include "catalog/storage_xlog.h"
19-
#include "common/relpath.h"
2019

2120

2221
void

src/backend/access/rmgrdesc/xactdesc.c

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
#include "access/xact.h"
1818
#include "catalog/catalog.h"
19-
#include "common/relpath.h"
2019
#include "storage/sinval.h"
2120
#include "utils/timestamp.h"
2221

src/backend/access/rmgrdesc/xlogdesc.c

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "access/xlog.h"
1818
#include "access/xlog_internal.h"
1919
#include "catalog/pg_control.h"
20-
#include "common/relpath.h"
2120
#include "utils/guc.h"
2221
#include "utils/timestamp.h"
2322

src/backend/access/transam/xlogutils.c

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "access/xlog.h"
2121
#include "access/xlogutils.h"
2222
#include "catalog/catalog.h"
23-
#include "common/relpath.h"
2423
#include "storage/smgr.h"
2524
#include "utils/guc.h"
2625
#include "utils/hsearch.h"

src/backend/catalog/catalog.c

-51
Original file line numberDiff line numberDiff line change
@@ -37,64 +37,13 @@
3737
#include "catalog/pg_shseclabel.h"
3838
#include "catalog/pg_tablespace.h"
3939
#include "catalog/toasting.h"
40-
#include "common/relpath.h"
4140
#include "miscadmin.h"
4241
#include "storage/fd.h"
4342
#include "utils/fmgroids.h"
4443
#include "utils/rel.h"
4544
#include "utils/tqual.h"
4645

4746

48-
49-
/*
50-
* forkname_to_number - look up fork number by name
51-
*/
52-
ForkNumber
53-
forkname_to_number(char *forkName)
54-
{
55-
ForkNumber forkNum;
56-
57-
for (forkNum = 0; forkNum <= MAX_FORKNUM; forkNum++)
58-
if (strcmp(forkNames[forkNum], forkName) == 0)
59-
return forkNum;
60-
61-
ereport(ERROR,
62-
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
63-
errmsg("invalid fork name"),
64-
errhint("Valid fork names are \"main\", \"fsm\", and \"vm\".")));
65-
return InvalidForkNumber; /* keep compiler quiet */
66-
}
67-
68-
/*
69-
* GetDatabasePath - construct path to a database dir
70-
*
71-
* Result is a palloc'd string.
72-
*
73-
* XXX this must agree with relpath()!
74-
*/
75-
char *
76-
GetDatabasePath(Oid dbNode, Oid spcNode)
77-
{
78-
if (spcNode == GLOBALTABLESPACE_OID)
79-
{
80-
/* Shared system relations live in {datadir}/global */
81-
Assert(dbNode == 0);
82-
return pstrdup("global");
83-
}
84-
else if (spcNode == DEFAULTTABLESPACE_OID)
85-
{
86-
/* The default tablespace is {datadir}/base */
87-
return psprintf("base/%u", dbNode);
88-
}
89-
else
90-
{
91-
/* All other tablespaces are accessed via symlinks */
92-
return psprintf("pg_tblspc/%u/%s/%u",
93-
spcNode, TABLESPACE_VERSION_DIRECTORY, dbNode);
94-
}
95-
}
96-
97-
9847
/*
9948
* IsSystemRelation
10049
* True iff the relation is either a system catalog or toast table.

src/backend/commands/tablecmds.c

-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
#include "commands/tablespace.h"
5252
#include "commands/trigger.h"
5353
#include "commands/typecmds.h"
54-
#include "common/relpath.h"
5554
#include "executor/executor.h"
5655
#include "foreign/foreign.h"
5756
#include "miscadmin.h"

src/backend/commands/tablespace.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
#include "commands/tablecmds.h"
6969
#include "commands/tablespace.h"
7070
#include "commands/user.h"
71-
#include "common/relpath.h"
7271
#include "miscadmin.h"
7372
#include "postmaster/bgwriter.h"
7473
#include "storage/fd.h"
@@ -278,11 +277,11 @@ CreateTableSpace(CreateTableSpaceStmt *stmt)
278277

279278
/*
280279
* Check that location isn't too long. Remember that we're going to append
281-
* 'PG_XXX/<dboid>/<relid>.<nnn>'. FYI, we never actually reference the
282-
* whole path, but mkdir() uses the first two parts.
280+
* 'PG_XXX/<dboid>/<relid>_<fork>.<nnn>'. FYI, we never actually
281+
* reference the whole path here, but mkdir() uses the first two parts.
283282
*/
284283
if (strlen(location) + 1 + strlen(TABLESPACE_VERSION_DIRECTORY) + 1 +
285-
OIDCHARS + 1 + OIDCHARS + 1 + OIDCHARS > MAXPGPATH)
284+
OIDCHARS + 1 + OIDCHARS + 1 + FORKNAMECHARS + 1 + OIDCHARS > MAXPGPATH)
286285
ereport(ERROR,
287286
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
288287
errmsg("tablespace location \"%s\" is too long",

src/backend/replication/basebackup.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
#include <time.h>
1919

2020
#include "access/xlog_internal.h" /* for pg_start/stop_backup */
21+
#include "catalog/catalog.h"
2122
#include "catalog/pg_type.h"
22-
#include "common/relpath.h"
2323
#include "lib/stringinfo.h"
2424
#include "libpq/libpq.h"
2525
#include "libpq/pqformat.h"

src/backend/replication/logical/reorderbuffer.c

+2-9
Original file line numberDiff line numberDiff line change
@@ -50,28 +50,20 @@
5050
#include <unistd.h>
5151
#include <sys/stat.h>
5252

53-
#include "miscadmin.h"
54-
5553
#include "access/rewriteheap.h"
5654
#include "access/transam.h"
5755
#include "access/tuptoaster.h"
5856
#include "access/xact.h"
59-
6057
#include "catalog/catalog.h"
61-
62-
#include "common/relpath.h"
63-
6458
#include "lib/binaryheap.h"
65-
59+
#include "miscadmin.h"
6660
#include "replication/logical.h"
6761
#include "replication/reorderbuffer.h"
6862
#include "replication/slot.h"
6963
#include "replication/snapbuild.h" /* just for SnapBuildSnapDecRefcount */
70-
7164
#include "storage/bufmgr.h"
7265
#include "storage/fd.h"
7366
#include "storage/sinval.h"
74-
7567
#include "utils/builtins.h"
7668
#include "utils/combocid.h"
7769
#include "utils/memdebug.h"
@@ -80,6 +72,7 @@
8072
#include "utils/relfilenodemap.h"
8173
#include "utils/tqual.h"
8274

75+
8376
/* entry for a hash table we use to map from xid to our transaction state */
8477
typedef struct ReorderBufferTXNByIdEnt
8578
{

src/backend/storage/buffer/bufmgr.c

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535

3636
#include "catalog/catalog.h"
3737
#include "catalog/storage.h"
38-
#include "common/relpath.h"
3938
#include "executor/instrument.h"
4039
#include "miscadmin.h"
4140
#include "pg_trace.h"

src/backend/storage/buffer/localbuf.c

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "postgres.h"
1717

1818
#include "catalog/catalog.h"
19-
#include "common/relpath.h"
2019
#include "executor/instrument.h"
2120
#include "storage/buf_internals.h"
2221
#include "storage/bufmgr.h"

src/backend/storage/file/fd.c

-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
#include "access/xact.h"
7272
#include "catalog/catalog.h"
7373
#include "catalog/pg_tablespace.h"
74-
#include "common/relpath.h"
7574
#include "pgstat.h"
7675
#include "storage/fd.h"
7776
#include "storage/ipc.h"

src/backend/storage/smgr/md.c

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include "miscadmin.h"
2929
#include "access/xlog.h"
3030
#include "catalog/catalog.h"
31-
#include "common/relpath.h"
3231
#include "portability/instr_time.h"
3332
#include "postmaster/bgwriter.h"
3433
#include "storage/fd.h"

src/backend/utils/adt/dbsize.c

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include "catalog/pg_tablespace.h"
2222
#include "commands/dbcommands.h"
2323
#include "commands/tablespace.h"
24-
#include "common/relpath.h"
2524
#include "miscadmin.h"
2625
#include "storage/fd.h"
2726
#include "utils/acl.h"

src/backend/utils/adt/misc.c

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "catalog/pg_tablespace.h"
2626
#include "catalog/pg_type.h"
2727
#include "commands/dbcommands.h"
28-
#include "common/relpath.h"
2928
#include "funcapi.h"
3029
#include "miscadmin.h"
3130
#include "parser/keywords.h"

src/backend/utils/cache/relcache.c

-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
#include "catalog/schemapg.h"
5757
#include "catalog/storage.h"
5858
#include "commands/trigger.h"
59-
#include "common/relpath.h"
6059
#include "miscadmin.h"
6160
#include "optimizer/clauses.h"
6261
#include "optimizer/planmain.h"

0 commit comments

Comments
 (0)