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

Commit8aa88dc

Browse files
michaelpqpull[bot]
authored andcommitted
Define PG_REPLSLOT_DIR for path pg_replslot/ in data folder
This commit replaces most of the hardcoded values of "pg_replslot" by anew PG_REPLSLOT_DIR #define. This makes the style more consistent withthe existing PG_STAT_TMP_DIR, for example. More places will follow asimilar change.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 parent4f86338 commit8aa88dc

File tree

6 files changed

+41
-35
lines changed

6 files changed

+41
-35
lines changed

‎src/backend/backup/basebackup.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include"port.h"
3737
#include"postmaster/syslogger.h"
3838
#include"postmaster/walsummarizer.h"
39+
#include"replication/slot.h"
3940
#include"replication/walsender.h"
4041
#include"replication/walsender_private.h"
4142
#include"storage/bufpage.h"
@@ -161,7 +162,7 @@ static const char *const excludeDirContents[] =
161162
* even if the intention is to restore to another primary. See backup.sgml
162163
* for a more detailed description.
163164
*/
164-
"pg_replslot",
165+
PG_REPLSLOT_DIR,
165166

166167
/* Contents removed on startup, see dsm_cleanup_for_mmap(). */
167168
PG_DYNSHMEM_DIR,

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4595,9 +4595,9 @@ ReorderBufferCleanupSerializedTXNs(const char *slotname)
45954595
DIR*spill_dir;
45964596
structdirent*spill_de;
45974597
structstatstatbuf;
4598-
charpath[MAXPGPATH*2+12];
4598+
charpath[MAXPGPATH*2+sizeof(PG_REPLSLOT_DIR)];
45994599

4600-
sprintf(path,"pg_replslot/%s",slotname);
4600+
sprintf(path,"%s/%s",PG_REPLSLOT_DIR,slotname);
46014601

46024602
/* we're only handling directories here, skip if it's not ours */
46034603
if (lstat(path,&statbuf)==0&& !S_ISDIR(statbuf.st_mode))
@@ -4610,14 +4610,14 @@ ReorderBufferCleanupSerializedTXNs(const char *slotname)
46104610
if (strncmp(spill_de->d_name,"xid",3)==0)
46114611
{
46124612
snprintf(path,sizeof(path),
4613-
"pg_replslot/%s/%s",slotname,
4613+
"%s/%s/%s",PG_REPLSLOT_DIR,slotname,
46144614
spill_de->d_name);
46154615

46164616
if (unlink(path)!=0)
46174617
ereport(ERROR,
46184618
(errcode_for_file_access(),
4619-
errmsg("could not remove file \"%s\" during removal ofpg_replslot/%s/xid*: %m",
4620-
path,slotname)));
4619+
errmsg("could not remove file \"%s\" during removal of%s/%s/xid*: %m",
4620+
path,PG_REPLSLOT_DIR,slotname)));
46214621
}
46224622
}
46234623
FreeDir(spill_dir);
@@ -4636,7 +4636,8 @@ ReorderBufferSerializedPath(char *path, ReplicationSlot *slot, TransactionId xid
46364636

46374637
XLogSegNoOffsetToRecPtr(segno,0,wal_segment_size,recptr);
46384638

4639-
snprintf(path,MAXPGPATH,"pg_replslot/%s/xid-%u-lsn-%X-%X.spill",
4639+
snprintf(path,MAXPGPATH,"%s/%s/xid-%u-lsn-%X-%X.spill",
4640+
PG_REPLSLOT_DIR,
46404641
NameStr(MyReplicationSlot->data.name),
46414642
xid,LSN_FORMAT_ARGS(recptr));
46424643
}
@@ -4651,8 +4652,8 @@ StartupReorderBuffer(void)
46514652
DIR*logical_dir;
46524653
structdirent*logical_de;
46534654

4654-
logical_dir=AllocateDir("pg_replslot");
4655-
while ((logical_de=ReadDir(logical_dir,"pg_replslot"))!=NULL)
4655+
logical_dir=AllocateDir(PG_REPLSLOT_DIR);
4656+
while ((logical_de=ReadDir(logical_dir,PG_REPLSLOT_DIR))!=NULL)
46564657
{
46574658
if (strcmp(logical_de->d_name,".")==0||
46584659
strcmp(logical_de->d_name,"..")==0)

‎src/backend/replication/slot.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
* on standbys (to support cascading setups). The requirement that slots be
2121
* usable on standbys precludes storing them in the system catalogs.
2222
*
23-
* Each replication slot gets its own directory inside the$PGDATA/pg_replslot
24-
*directory.Inside that directory the state file will contain the slot's
25-
* own data. Additional data can be stored alongside that file if required.
26-
* While the server is running, the state data is also cached in memory for
27-
* efficiency.
23+
* Each replication slot gets its own directory inside thedirectory
24+
*$PGDATA / PG_REPLSLOT_DIR.Inside that directory the state file will
25+
*contain the slot'sown data.Additional data can be stored alongside that
26+
*file if required.While the server is running, the state data is also
27+
*cached in memory forefficiency.
2828
*
2929
* ReplicationSlotAllocationLock must be taken in exclusive mode to allocate
3030
* or free a slot. ReplicationSlotControlLock must be taken in shared mode
@@ -916,8 +916,8 @@ ReplicationSlotDropPtr(ReplicationSlot *slot)
916916
LWLockAcquire(ReplicationSlotAllocationLock,LW_EXCLUSIVE);
917917

918918
/* Generate pathnames. */
919-
sprintf(path,"pg_replslot/%s",NameStr(slot->data.name));
920-
sprintf(tmppath,"pg_replslot/%s.tmp",NameStr(slot->data.name));
919+
sprintf(path,"%s/%s",PG_REPLSLOT_DIR,NameStr(slot->data.name));
920+
sprintf(tmppath,"%s/%s.tmp",PG_REPLSLOT_DIR,NameStr(slot->data.name));
921921

922922
/*
923923
* Rename the slot directory on disk, so that we'll no longer recognize
@@ -938,7 +938,7 @@ ReplicationSlotDropPtr(ReplicationSlot *slot)
938938
*/
939939
START_CRIT_SECTION();
940940
fsync_fname(tmppath, true);
941-
fsync_fname("pg_replslot", true);
941+
fsync_fname(PG_REPLSLOT_DIR, true);
942942
END_CRIT_SECTION();
943943
}
944944
else
@@ -1016,7 +1016,7 @@ ReplicationSlotSave(void)
10161016

10171017
Assert(MyReplicationSlot!=NULL);
10181018

1019-
sprintf(path,"pg_replslot/%s",NameStr(MyReplicationSlot->data.name));
1019+
sprintf(path,"%s/%s",PG_REPLSLOT_DIR,NameStr(MyReplicationSlot->data.name));
10201020
SaveSlotToPath(MyReplicationSlot,path,ERROR);
10211021
}
10221022

@@ -1881,7 +1881,7 @@ CheckPointReplicationSlots(bool is_shutdown)
18811881
continue;
18821882

18831883
/* save the slot to disk, locking is handled in SaveSlotToPath() */
1884-
sprintf(path,"pg_replslot/%s",NameStr(s->data.name));
1884+
sprintf(path,"%s/%s",PG_REPLSLOT_DIR,NameStr(s->data.name));
18851885

18861886
/*
18871887
* Slot's data is not flushed each time the confirmed_flush LSN is
@@ -1922,17 +1922,17 @@ StartupReplicationSlots(void)
19221922
elog(DEBUG1,"starting up replication slots");
19231923

19241924
/* restore all slots by iterating over all on-disk entries */
1925-
replication_dir=AllocateDir("pg_replslot");
1926-
while ((replication_de=ReadDir(replication_dir,"pg_replslot"))!=NULL)
1925+
replication_dir=AllocateDir(PG_REPLSLOT_DIR);
1926+
while ((replication_de=ReadDir(replication_dir,PG_REPLSLOT_DIR))!=NULL)
19271927
{
1928-
charpath[MAXPGPATH+12];
1928+
charpath[MAXPGPATH+sizeof(PG_REPLSLOT_DIR)];
19291929
PGFileTypede_type;
19301930

19311931
if (strcmp(replication_de->d_name,".")==0||
19321932
strcmp(replication_de->d_name,"..")==0)
19331933
continue;
19341934

1935-
snprintf(path,sizeof(path),"pg_replslot/%s",replication_de->d_name);
1935+
snprintf(path,sizeof(path),"%s/%s",PG_REPLSLOT_DIR,replication_de->d_name);
19361936
de_type=get_dirent_type(path,replication_de, false,DEBUG1);
19371937

19381938
/* we're only creating directories here, skip if it's not our's */
@@ -1949,7 +1949,7 @@ StartupReplicationSlots(void)
19491949
path)));
19501950
continue;
19511951
}
1952-
fsync_fname("pg_replslot", true);
1952+
fsync_fname(PG_REPLSLOT_DIR, true);
19531953
continue;
19541954
}
19551955

@@ -1987,8 +1987,8 @@ CreateSlotOnDisk(ReplicationSlot *slot)
19871987
* takes out the lock, if we'd take the lock here, we'd deadlock.
19881988
*/
19891989

1990-
sprintf(path,"pg_replslot/%s",NameStr(slot->data.name));
1991-
sprintf(tmppath,"pg_replslot/%s.tmp",NameStr(slot->data.name));
1990+
sprintf(path,"%s/%s",PG_REPLSLOT_DIR,NameStr(slot->data.name));
1991+
sprintf(tmppath,"%s/%s.tmp",PG_REPLSLOT_DIR,NameStr(slot->data.name));
19921992

19931993
/*
19941994
* It's just barely possible that some previous effort to create or drop a
@@ -2027,7 +2027,7 @@ CreateSlotOnDisk(ReplicationSlot *slot)
20272027
START_CRIT_SECTION();
20282028

20292029
fsync_fname(path, true);
2030-
fsync_fname("pg_replslot", true);
2030+
fsync_fname(PG_REPLSLOT_DIR, true);
20312031

20322032
END_CRIT_SECTION();
20332033
}
@@ -2170,7 +2170,7 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
21702170

21712171
fsync_fname(path, false);
21722172
fsync_fname(dir, true);
2173-
fsync_fname("pg_replslot", true);
2173+
fsync_fname(PG_REPLSLOT_DIR, true);
21742174

21752175
END_CRIT_SECTION();
21762176

@@ -2195,8 +2195,8 @@ RestoreSlotFromDisk(const char *name)
21952195
{
21962196
ReplicationSlotOnDiskcp;
21972197
inti;
2198-
charslotdir[MAXPGPATH+12];
2199-
charpath[MAXPGPATH+22];
2198+
charslotdir[MAXPGPATH+sizeof(PG_REPLSLOT_DIR)];
2199+
charpath[MAXPGPATH+sizeof(PG_REPLSLOT_DIR)+10];
22002200
intfd;
22012201
boolrestored= false;
22022202
intreadBytes;
@@ -2205,7 +2205,7 @@ RestoreSlotFromDisk(const char *name)
22052205
/* no need to lock here, no concurrent access allowed yet */
22062206

22072207
/* delete temp file if it exists */
2208-
sprintf(slotdir,"pg_replslot/%s",name);
2208+
sprintf(slotdir,"%s/%s",PG_REPLSLOT_DIR,name);
22092209
sprintf(path,"%s/state.tmp",slotdir);
22102210
if (unlink(path)<0&&errno!=ENOENT)
22112211
ereport(PANIC,
@@ -2332,7 +2332,7 @@ RestoreSlotFromDisk(const char *name)
23322332
(errmsg("could not remove directory \"%s\"",
23332333
slotdir)));
23342334
}
2335-
fsync_fname("pg_replslot", true);
2335+
fsync_fname(PG_REPLSLOT_DIR, true);
23362336
return;
23372337
}
23382338

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ pg_ls_logicalmapdir(PG_FUNCTION_ARGS)
708708
}
709709

710710
/*
711-
* Function to return the list of files in thepg_replslot/<replication_slot>
711+
* Function to return the list of files in thePG_REPLSLOT_DIR/<slot_name>
712712
* directory.
713713
*/
714714
Datum
@@ -728,6 +728,7 @@ pg_ls_replslotdir(PG_FUNCTION_ARGS)
728728
errmsg("replication slot \"%s\" does not exist",
729729
slotname)));
730730

731-
snprintf(path,sizeof(path),"pg_replslot/%s",slotname);
731+
snprintf(path,sizeof(path),"%s/%s",PG_REPLSLOT_DIR,slotname);
732+
732733
returnpg_ls_dir_files(fcinfo,path, false);
733734
}

‎src/bin/pg_rewind/filemap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static const char *const excludeDirContents[] =
9797
* even if the intention is to restore to another primary. See backup.sgml
9898
* for a more detailed description.
9999
*/
100-
"pg_replslot",
100+
"pg_replslot",/* defined as PG_REPLSLOT_DIR */
101101

102102
/* Contents removed on startup, see dsm_cleanup_for_mmap(). */
103103
"pg_dynshmem",/* defined as PG_DYNSHMEM_DIR */

‎src/include/replication/slot.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
#include"storage/spin.h"
1818
#include"replication/walreceiver.h"
1919

20+
/* directory to store replication slot data in */
21+
#definePG_REPLSLOT_DIR "pg_replslot"
22+
2023
/*
2124
* Behaviour of replication slots, upon release or crash.
2225
*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp