Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc39afc3

Browse files
committed
Define PG_LOGICAL_DIR for path pg_logical/ in data folder
This is similar to2065ddf, but this time for pg_logical/ itselfand its contents, like the paths for snapshots, mappings or origincheckpoints.Author: Bertrand DrouvotReviewed-by: Ashutosh Bapat, Yugo Nagata, Michael PaquierDiscussion:https://postgr.es/m/ZryVvjqS9SnV1GPP@ip-10-97-1-34.eu-west-3.compute.internal
1 parent2065ddf commitc39afc3

File tree

6 files changed

+46
-31
lines changed

6 files changed

+46
-31
lines changed

‎src/backend/access/heap/rewriteheap.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -961,8 +961,8 @@ logical_rewrite_log_mapping(RewriteState state, TransactionId xid,
961961
dboid=MyDatabaseId;
962962

963963
snprintf(path,MAXPGPATH,
964-
"pg_logical/mappings/"LOGICAL_REWRITE_FORMAT,
965-
dboid,relid,
964+
"%s/"LOGICAL_REWRITE_FORMAT,
965+
PG_LOGICAL_MAPPINGS_DIR,dboid,relid,
966966
LSN_FORMAT_ARGS(state->rs_begin_lsn),
967967
xid,GetCurrentTransactionId());
968968

@@ -1081,8 +1081,8 @@ heap_xlog_logical_rewrite(XLogReaderState *r)
10811081
xlrec= (xl_heap_rewrite_mapping*)XLogRecGetData(r);
10821082

10831083
snprintf(path,MAXPGPATH,
1084-
"pg_logical/mappings/"LOGICAL_REWRITE_FORMAT,
1085-
xlrec->mapped_db,xlrec->mapped_rel,
1084+
"%s/"LOGICAL_REWRITE_FORMAT,
1085+
PG_LOGICAL_MAPPINGS_DIR,xlrec->mapped_db,xlrec->mapped_rel,
10861086
LSN_FORMAT_ARGS(xlrec->start_lsn),
10871087
xlrec->mapped_xid,XLogRecGetXid(r));
10881088

@@ -1158,7 +1158,7 @@ CheckPointLogicalRewriteHeap(void)
11581158
XLogRecPtrredo;
11591159
DIR*mappings_dir;
11601160
structdirent*mapping_de;
1161-
charpath[MAXPGPATH+20];
1161+
charpath[MAXPGPATH+sizeof(PG_LOGICAL_MAPPINGS_DIR)];
11621162

11631163
/*
11641164
* We start of with a minimum of the last redo pointer. No new decoding
@@ -1173,8 +1173,8 @@ CheckPointLogicalRewriteHeap(void)
11731173
if (cutoff!=InvalidXLogRecPtr&&redo<cutoff)
11741174
cutoff=redo;
11751175

1176-
mappings_dir=AllocateDir("pg_logical/mappings");
1177-
while ((mapping_de=ReadDir(mappings_dir,"pg_logical/mappings"))!=NULL)
1176+
mappings_dir=AllocateDir(PG_LOGICAL_MAPPINGS_DIR);
1177+
while ((mapping_de=ReadDir(mappings_dir,PG_LOGICAL_MAPPINGS_DIR))!=NULL)
11781178
{
11791179
Oiddboid;
11801180
Oidrelid;
@@ -1189,7 +1189,7 @@ CheckPointLogicalRewriteHeap(void)
11891189
strcmp(mapping_de->d_name,"..")==0)
11901190
continue;
11911191

1192-
snprintf(path,sizeof(path),"pg_logical/mappings/%s",mapping_de->d_name);
1192+
snprintf(path,sizeof(path),"%s/%s",PG_LOGICAL_MAPPINGS_DIR,mapping_de->d_name);
11931193
de_type=get_dirent_type(path,mapping_de, false,DEBUG1);
11941194

11951195
if (de_type!=PGFILETYPE_ERROR&&de_type!=PGFILETYPE_REG)
@@ -1249,5 +1249,5 @@ CheckPointLogicalRewriteHeap(void)
12491249
FreeDir(mappings_dir);
12501250

12511251
/* persist directory entries to disk */
1252-
fsync_fname("pg_logical/mappings", true);
1252+
fsync_fname(PG_LOGICAL_MAPPINGS_DIR, true);
12531253
}

‎src/backend/replication/logical/origin.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@
9595
#include"utils/snapmgr.h"
9696
#include"utils/syscache.h"
9797

98+
/* paths for replication origin checkpoint files */
99+
#definePG_REPLORIGIN_CHECKPOINT_FILENAME PG_LOGICAL_DIR "/replorigin_checkpoint"
100+
#definePG_REPLORIGIN_CHECKPOINT_TMPFILE PG_REPLORIGIN_CHECKPOINT_FILENAME ".tmp"
101+
98102
/*
99103
* Replay progress of a single remote node.
100104
*/
@@ -572,8 +576,8 @@ ReplicationOriginShmemInit(void)
572576
void
573577
CheckPointReplicationOrigin(void)
574578
{
575-
constchar*tmppath="pg_logical/replorigin_checkpoint.tmp";
576-
constchar*path="pg_logical/replorigin_checkpoint";
579+
constchar*tmppath=PG_REPLORIGIN_CHECKPOINT_TMPFILE;
580+
constchar*path=PG_REPLORIGIN_CHECKPOINT_FILENAME;
577581
inttmpfd;
578582
inti;
579583
uint32magic=REPLICATION_STATE_MAGIC;
@@ -698,7 +702,7 @@ CheckPointReplicationOrigin(void)
698702
void
699703
StartupReplicationOrigin(void)
700704
{
701-
constchar*path="pg_logical/replorigin_checkpoint";
705+
constchar*path=PG_REPLORIGIN_CHECKPOINT_FILENAME;
702706
intfd;
703707
intreadBytes;
704708
uint32magic=REPLICATION_STATE_MAGIC;

‎src/backend/replication/logical/reorderbuffer.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5081,7 +5081,7 @@ ApplyLogicalMappingFile(HTAB *tuplecid_data, Oid relid, const char *fname)
50815081
intreadBytes;
50825082
LogicalRewriteMappingDatamap;
50835083

5084-
sprintf(path,"pg_logical/mappings/%s",fname);
5084+
sprintf(path,"%s/%s",PG_LOGICAL_MAPPINGS_DIR,fname);
50855085
fd=OpenTransientFile(path,O_RDONLY |PG_BINARY);
50865086
if (fd<0)
50875087
ereport(ERROR,
@@ -5197,8 +5197,8 @@ UpdateLogicalMappings(HTAB *tuplecid_data, Oid relid, Snapshot snapshot)
51975197
ListCell*file;
51985198
Oiddboid=IsSharedRelation(relid) ?InvalidOid :MyDatabaseId;
51995199

5200-
mapping_dir=AllocateDir("pg_logical/mappings");
5201-
while ((mapping_de=ReadDir(mapping_dir,"pg_logical/mappings"))!=NULL)
5200+
mapping_dir=AllocateDir(PG_LOGICAL_MAPPINGS_DIR);
5201+
while ((mapping_de=ReadDir(mapping_dir,PG_LOGICAL_MAPPINGS_DIR))!=NULL)
52025202
{
52035203
Oidf_dboid;
52045204
Oidf_relid;

‎src/backend/replication/logical/snapbuild.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,7 +1654,8 @@ SnapBuildSerialize(SnapBuild *builder, XLogRecPtr lsn)
16541654
* unless the user used pg_resetwal or similar. If a user did so, there's
16551655
* no hope continuing to decode anyway.
16561656
*/
1657-
sprintf(path,"pg_logical/snapshots/%X-%X.snap",
1657+
sprintf(path,"%s/%X-%X.snap",
1658+
PG_LOGICAL_SNAPSHOTS_DIR,
16581659
LSN_FORMAT_ARGS(lsn));
16591660

16601661
/*
@@ -1681,7 +1682,7 @@ SnapBuildSerialize(SnapBuild *builder, XLogRecPtr lsn)
16811682
* be safely on disk.
16821683
*/
16831684
fsync_fname(path, false);
1684-
fsync_fname("pg_logical/snapshots", true);
1685+
fsync_fname(PG_LOGICAL_SNAPSHOTS_DIR, true);
16851686

16861687
builder->last_serialized_snapshot=lsn;
16871688
gotoout;
@@ -1697,7 +1698,8 @@ SnapBuildSerialize(SnapBuild *builder, XLogRecPtr lsn)
16971698
elog(DEBUG1,"serializing snapshot to %s",path);
16981699

16991700
/* to make sure only we will write to this tempfile, include pid */
1700-
sprintf(tmppath,"pg_logical/snapshots/%X-%X.snap.%d.tmp",
1701+
sprintf(tmppath,"%s/%X-%X.snap.%d.tmp",
1702+
PG_LOGICAL_SNAPSHOTS_DIR,
17011703
LSN_FORMAT_ARGS(lsn),MyProcPid);
17021704

17031705
/*
@@ -1818,7 +1820,7 @@ SnapBuildSerialize(SnapBuild *builder, XLogRecPtr lsn)
18181820
(errcode_for_file_access(),
18191821
errmsg("could not close file \"%s\": %m",tmppath)));
18201822

1821-
fsync_fname("pg_logical/snapshots", true);
1823+
fsync_fname(PG_LOGICAL_SNAPSHOTS_DIR, true);
18221824

18231825
/*
18241826
* We may overwrite the work from some other backend, but that's ok, our
@@ -1834,7 +1836,7 @@ SnapBuildSerialize(SnapBuild *builder, XLogRecPtr lsn)
18341836

18351837
/* make sure we persist */
18361838
fsync_fname(path, false);
1837-
fsync_fname("pg_logical/snapshots", true);
1839+
fsync_fname(PG_LOGICAL_SNAPSHOTS_DIR, true);
18381840

18391841
/*
18401842
* Now there's no way we can lose the dumped state anymore, remember this
@@ -1871,7 +1873,8 @@ SnapBuildRestore(SnapBuild *builder, XLogRecPtr lsn)
18711873
if (builder->state==SNAPBUILD_CONSISTENT)
18721874
return false;
18731875

1874-
sprintf(path,"pg_logical/snapshots/%X-%X.snap",
1876+
sprintf(path,"%s/%X-%X.snap",
1877+
PG_LOGICAL_SNAPSHOTS_DIR,
18751878
LSN_FORMAT_ARGS(lsn));
18761879

18771880
fd=OpenTransientFile(path,O_RDONLY |PG_BINARY);
@@ -1892,7 +1895,7 @@ SnapBuildRestore(SnapBuild *builder, XLogRecPtr lsn)
18921895
* ----
18931896
*/
18941897
fsync_fname(path, false);
1895-
fsync_fname("pg_logical/snapshots", true);
1898+
fsync_fname(PG_LOGICAL_SNAPSHOTS_DIR, true);
18961899

18971900

18981901
/* read statically sized portion of snapshot */
@@ -2074,7 +2077,7 @@ CheckPointSnapBuild(void)
20742077
XLogRecPtrredo;
20752078
DIR*snap_dir;
20762079
structdirent*snap_de;
2077-
charpath[MAXPGPATH+21];
2080+
charpath[MAXPGPATH+sizeof(PG_LOGICAL_SNAPSHOTS_DIR)];
20782081

20792082
/*
20802083
* We start off with a minimum of the last redo pointer. No new
@@ -2090,8 +2093,8 @@ CheckPointSnapBuild(void)
20902093
if (redo<cutoff)
20912094
cutoff=redo;
20922095

2093-
snap_dir=AllocateDir("pg_logical/snapshots");
2094-
while ((snap_de=ReadDir(snap_dir,"pg_logical/snapshots"))!=NULL)
2096+
snap_dir=AllocateDir(PG_LOGICAL_SNAPSHOTS_DIR);
2097+
while ((snap_de=ReadDir(snap_dir,PG_LOGICAL_SNAPSHOTS_DIR))!=NULL)
20952098
{
20962099
uint32hi;
20972100
uint32lo;
@@ -2102,7 +2105,7 @@ CheckPointSnapBuild(void)
21022105
strcmp(snap_de->d_name,"..")==0)
21032106
continue;
21042107

2105-
snprintf(path,sizeof(path),"pg_logical/snapshots/%s",snap_de->d_name);
2108+
snprintf(path,sizeof(path),"%s/%s",PG_LOGICAL_SNAPSHOTS_DIR,snap_de->d_name);
21062109
de_type=get_dirent_type(path,snap_de, false,DEBUG1);
21072110

21082111
if (de_type!=PGFILETYPE_ERROR&&de_type!=PGFILETYPE_REG)
@@ -2162,7 +2165,8 @@ SnapBuildSnapshotExists(XLogRecPtr lsn)
21622165
intret;
21632166
structstatstat_buf;
21642167

2165-
sprintf(path,"pg_logical/snapshots/%X-%X.snap",
2168+
sprintf(path,"%s/%X-%X.snap",
2169+
PG_LOGICAL_SNAPSHOTS_DIR,
21662170
LSN_FORMAT_ARGS(lsn));
21672171

21682172
ret=stat(path,&stat_buf);

‎src/backend/utils/adt/genfile.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -690,21 +690,23 @@ pg_ls_archive_statusdir(PG_FUNCTION_ARGS)
690690
}
691691

692692
/*
693-
* Function to return the list of files in the pg_logical/snapshots directory.
693+
* Function to return the list of files in the PG_LOGICAL_SNAPSHOTS_DIR
694+
* directory.
694695
*/
695696
Datum
696697
pg_ls_logicalsnapdir(PG_FUNCTION_ARGS)
697698
{
698-
returnpg_ls_dir_files(fcinfo,"pg_logical/snapshots", false);
699+
returnpg_ls_dir_files(fcinfo,PG_LOGICAL_SNAPSHOTS_DIR, false);
699700
}
700701

701702
/*
702-
* Function to return the list of files in the pg_logical/mappings directory.
703+
* Function to return the list of files in the PG_LOGICAL_MAPPINGS_DIR
704+
* directory.
703705
*/
704706
Datum
705707
pg_ls_logicalmapdir(PG_FUNCTION_ARGS)
706708
{
707-
returnpg_ls_dir_files(fcinfo,"pg_logical/mappings", false);
709+
returnpg_ls_dir_files(fcinfo,PG_LOGICAL_MAPPINGS_DIR, false);
708710
}
709711

710712
/*

‎src/include/replication/reorderbuffer.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
#include"utils/snapshot.h"
1919
#include"utils/timestamp.h"
2020

21+
/* paths for logical decoding data (relative to installation's $PGDATA) */
22+
#definePG_LOGICAL_DIR"pg_logical"
23+
#definePG_LOGICAL_MAPPINGS_DIRPG_LOGICAL_DIR "/mappings"
24+
#definePG_LOGICAL_SNAPSHOTS_DIRPG_LOGICAL_DIR "/snapshots"
25+
2126
/* GUC variables */
2227
externPGDLLIMPORTintlogical_decoding_work_mem;
2328
externPGDLLIMPORTintdebug_logical_replication_streaming;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp