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

Commit066bc21

Browse files
committed
Simplify do_pg_start_backup's API by opening pg_tblspc internally.
do_pg_start_backup() expects its callers to pass in an open DIR pointerfor the pg_tblspc directory, but there's no apparent advantage in that.It complicates the callers without adding any flexibility, and there's norobustness advantage, since we surely have to be prepared for errors duringthe scan of pg_tblspc anyway. In fact, by holding an extra kernel resourceduring operations like the preliminary checkpoint, we might be makingthings a fraction more failure-prone not less. Hence, remove that argumentand open the directory just for the duration of the actual scan.Discussion:https://postgr.es/m/28752.1512413887@sss.pgh.pa.us
1 parent561885d commit066bc21

File tree

4 files changed

+11
-31
lines changed

4 files changed

+11
-31
lines changed

‎src/backend/access/transam/xlog.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10206,7 +10206,7 @@ XLogFileNameP(TimeLineID tli, XLogSegNo segno)
1020610206
*/
1020710207
XLogRecPtr
1020810208
do_pg_start_backup(constchar*backupidstr,boolfast,TimeLineID*starttli_p,
10209-
StringInfolabelfile,DIR*tblspcdir,List**tablespaces,
10209+
StringInfolabelfile,List**tablespaces,
1021010210
StringInfotblspcmapfile,boolinfotbssize,
1021110211
boolneedtblspcmapfile)
1021210212
{
@@ -10297,6 +10297,7 @@ do_pg_start_backup(const char *backupidstr, bool fast, TimeLineID *starttli_p,
1029710297
PG_ENSURE_ERROR_CLEANUP(pg_start_backup_callback, (Datum)BoolGetDatum(exclusive));
1029810298
{
1029910299
boolgotUniqueStartpoint= false;
10300+
DIR*tblspcdir;
1030010301
structdirent*de;
1030110302
tablespaceinfo*ti;
1030210303
intdatadirpathlen;
@@ -10428,6 +10429,7 @@ do_pg_start_backup(const char *backupidstr, bool fast, TimeLineID *starttli_p,
1042810429
datadirpathlen=strlen(DataDir);
1042910430

1043010431
/* Collect information about all tablespaces */
10432+
tblspcdir=AllocateDir("pg_tblspc");
1043110433
while ((de=ReadDir(tblspcdir,"pg_tblspc"))!=NULL)
1043210434
{
1043310435
charfullpath[MAXPGPATH+10];
@@ -10476,7 +10478,6 @@ do_pg_start_backup(const char *backupidstr, bool fast, TimeLineID *starttli_p,
1047610478
appendStringInfoChar(&buflinkpath,*s++);
1047710479
}
1047810480

10479-
1048010481
/*
1048110482
* Relpath holds the relative path of the tablespace directory
1048210483
* when it's located within PGDATA, or NULL if it's located
@@ -10511,6 +10512,7 @@ do_pg_start_backup(const char *backupidstr, bool fast, TimeLineID *starttli_p,
1051110512
errmsg("tablespaces are not supported on this platform")));
1051210513
#endif
1051310514
}
10515+
FreeDir(tblspcdir);
1051410516

1051510517
/*
1051610518
* Construct backup label file

‎src/backend/access/transam/xlogfuncs.c

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ pg_start_backup(PG_FUNCTION_ARGS)
7575
boolexclusive=PG_GETARG_BOOL(2);
7676
char*backupidstr;
7777
XLogRecPtrstartpoint;
78-
DIR*dir;
7978
SessionBackupStatestatus=get_backup_status();
8079

8180
backupidstr=text_to_cstring(backupid);
@@ -85,18 +84,10 @@ pg_start_backup(PG_FUNCTION_ARGS)
8584
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
8685
errmsg("a backup is already in progress in this session")));
8786

88-
/* Make sure we can open the directory with tablespaces in it */
89-
dir=AllocateDir("pg_tblspc");
90-
if (!dir)
91-
ereport(ERROR,
92-
(errcode_for_file_access(),
93-
errmsg("could not open directory \"%s\": %m",
94-
"pg_tblspc")));
95-
9687
if (exclusive)
9788
{
9889
startpoint=do_pg_start_backup(backupidstr,fast,NULL,NULL,
99-
dir,NULL,NULL, false, true);
90+
NULL,NULL, false, true);
10091
}
10192
else
10293
{
@@ -112,13 +103,11 @@ pg_start_backup(PG_FUNCTION_ARGS)
112103
MemoryContextSwitchTo(oldcontext);
113104

114105
startpoint=do_pg_start_backup(backupidstr,fast,NULL,label_file,
115-
dir,NULL,tblspc_map_file, false, true);
106+
NULL,tblspc_map_file, false, true);
116107

117108
before_shmem_exit(nonexclusive_base_backup_cleanup, (Datum)0);
118109
}
119110

120-
FreeDir(dir);
121-
122111
PG_RETURN_LSN(startpoint);
123112
}
124113

‎src/backend/replication/basebackup.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static int64 _tarWriteDir(const char *pathbuf, int basepathlen, struct stat *sta
6464
staticvoidsend_int8_string(StringInfoData*buf,int64intval);
6565
staticvoidSendBackupHeader(List*tablespaces);
6666
staticvoidbase_backup_cleanup(intcode,Datumarg);
67-
staticvoidperform_base_backup(basebackup_options*opt,DIR*tblspcdir);
67+
staticvoidperform_base_backup(basebackup_options*opt);
6868
staticvoidparse_basebackup_options(List*options,basebackup_options*opt);
6969
staticvoidSendXlogRecPtrResult(XLogRecPtrptr,TimeLineIDtli);
7070
staticintcompareWalFileNames(constvoid*a,constvoid*b);
@@ -188,7 +188,7 @@ base_backup_cleanup(int code, Datum arg)
188188
* clobbered by longjmp" from stupider versions of gcc.
189189
*/
190190
staticvoid
191-
perform_base_backup(basebackup_options*opt,DIR*tblspcdir)
191+
perform_base_backup(basebackup_options*opt)
192192
{
193193
XLogRecPtrstartptr;
194194
TimeLineIDstarttli;
@@ -207,7 +207,7 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir)
207207
tblspc_map_file=makeStringInfo();
208208

209209
startptr=do_pg_start_backup(opt->label,opt->fastcheckpoint,&starttli,
210-
labelfile,tblspcdir,&tablespaces,
210+
labelfile,&tablespaces,
211211
tblspc_map_file,
212212
opt->progress,opt->sendtblspcmapfile);
213213

@@ -690,7 +690,6 @@ parse_basebackup_options(List *options, basebackup_options *opt)
690690
void
691691
SendBaseBackup(BaseBackupCmd*cmd)
692692
{
693-
DIR*dir;
694693
basebackup_optionsopt;
695694

696695
parse_basebackup_options(cmd->options,&opt);
@@ -706,17 +705,7 @@ SendBaseBackup(BaseBackupCmd *cmd)
706705
set_ps_display(activitymsg, false);
707706
}
708707

709-
/* Make sure we can open the directory with tablespaces in it */
710-
dir=AllocateDir("pg_tblspc");
711-
if (!dir)
712-
ereport(ERROR,
713-
(errcode_for_file_access(),
714-
errmsg("could not open directory \"%s\": %m",
715-
"pg_tblspc")));
716-
717-
perform_base_backup(&opt,dir);
718-
719-
FreeDir(dir);
708+
perform_base_backup(&opt);
720709
}
721710

722711
staticvoid

‎src/include/access/xlog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ typedef enum SessionBackupState
310310
}SessionBackupState;
311311

312312
externXLogRecPtrdo_pg_start_backup(constchar*backupidstr,boolfast,
313-
TimeLineID*starttli_p,StringInfolabelfile,DIR*tblspcdir,
313+
TimeLineID*starttli_p,StringInfolabelfile,
314314
List**tablespaces,StringInfotblspcmapfile,boolinfotbssize,
315315
boolneedtblspcmapfile);
316316
externXLogRecPtrdo_pg_stop_backup(char*labelfile,boolwaitforarchive,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp