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

Commit534b6f3

Browse files
committed
Use an enum instead of two bools to indicate wal inclusion in base backups
This makes the code easier to read as it becomes more explicit what thedifferent allowed combinations really are.Suggested by Michael Paquier
1 parent7c3abe3 commit534b6f3

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

‎src/bin/pg_basebackup/pg_basebackup.c

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ typedef struct TablespaceList
6161
*/
6262
#defineMINIMUM_VERSION_FOR_PG_WAL100000
6363

64+
/*
65+
* Different ways to include WAL
66+
*/
67+
typedefenum
68+
{
69+
NO_WAL,
70+
FETCH_WAL,
71+
STREAM_WAL
72+
}IncludeWal;
73+
6474
/* Global options */
6575
staticchar*basedir=NULL;
6676
staticTablespaceListtablespace_dirs= {NULL,NULL};
@@ -71,8 +81,7 @@ static bool noclean = false;
7181
staticboolshowprogress= false;
7282
staticintverbose=0;
7383
staticintcompresslevel=0;
74-
staticboolincludewal= true;
75-
staticboolstreamwal= true;
84+
staticIncludeWalincludewal=STREAM_WAL;
7685
staticboolfastcheckpoint= false;
7786
staticboolwriterecoveryconf= false;
7887
staticbooldo_sync= true;
@@ -1697,7 +1706,7 @@ BaseBackup(void)
16971706
* If WAL streaming was requested, also check that the server is new
16981707
* enough for that.
16991708
*/
1700-
if (streamwal&& !CheckServerVersionForStreaming(conn))
1709+
if (includewal==STREAM_WAL&& !CheckServerVersionForStreaming(conn))
17011710
{
17021711
/*
17031712
* Error message already written in CheckServerVersionForStreaming(),
@@ -1731,9 +1740,9 @@ BaseBackup(void)
17311740
psprintf("BASE_BACKUP LABEL '%s' %s %s %s %s %s %s",
17321741
escaped_label,
17331742
showprogress ?"PROGRESS" :"",
1734-
includewal&& !streamwal ?"WAL" :"",
1743+
includewal==FETCH_WAL ?"WAL" :"",
17351744
fastcheckpoint ?"FAST" :"",
1736-
includewal ?"NOWAIT" :"",
1745+
includewal==NO_WAL?"" :"NOWAIT",
17371746
maxrate_clause ?maxrate_clause :"",
17381747
format=='t' ?"TABLESPACE_MAP" :"");
17391748

@@ -1776,7 +1785,7 @@ BaseBackup(void)
17761785
PQclear(res);
17771786
MemSet(xlogend,0,sizeof(xlogend));
17781787

1779-
if (verbose&&includewal)
1788+
if (verbose&&includewal!=NO_WAL)
17801789
fprintf(stderr,_("transaction log start point: %s on timeline %u\n"),
17811790
xlogstart,starttli);
17821791

@@ -1833,7 +1842,7 @@ BaseBackup(void)
18331842
* If we're streaming WAL, start the streaming session before we start
18341843
* receiving the actual data chunks.
18351844
*/
1836-
if (streamwal)
1845+
if (includewal==STREAM_WAL)
18371846
{
18381847
if (verbose)
18391848
fprintf(stderr,_("%s: starting background WAL receiver\n"),
@@ -1879,7 +1888,7 @@ BaseBackup(void)
18791888
disconnect_and_exit(1);
18801889
}
18811890
strlcpy(xlogend,PQgetvalue(res,0,0),sizeof(xlogend));
1882-
if (verbose&&includewal)
1891+
if (verbose&&includewal!=NO_WAL)
18831892
fprintf(stderr,"transaction log end point: %s\n",xlogend);
18841893
PQclear(res);
18851894

@@ -2117,20 +2126,17 @@ main(int argc, char **argv)
21172126
if (strcmp(optarg,"n")==0||
21182127
strcmp(optarg,"none")==0)
21192128
{
2120-
includewal= false;
2121-
streamwal= false;
2129+
includewal=NO_WAL;
21222130
}
21232131
elseif (strcmp(optarg,"f")==0||
21242132
strcmp(optarg,"fetch")==0)
21252133
{
2126-
includewal= true;
2127-
streamwal= false;
2134+
includewal=FETCH_WAL;
21282135
}
21292136
elseif (strcmp(optarg,"s")==0||
21302137
strcmp(optarg,"stream")==0)
21312138
{
2132-
includewal= true;
2133-
streamwal= true;
2139+
includewal=STREAM_WAL;
21342140
}
21352141
else
21362142
{
@@ -2261,7 +2267,7 @@ main(int argc, char **argv)
22612267
exit(1);
22622268
}
22632269

2264-
if (format=='t'&&streamwal&&strcmp(basedir,"-")==0)
2270+
if (format=='t'&&includewal==STREAM_WAL&&strcmp(basedir,"-")==0)
22652271
{
22662272
fprintf(stderr,
22672273
_("%s: cannot stream transaction logs in tar mode to stdout\n"),
@@ -2271,7 +2277,7 @@ main(int argc, char **argv)
22712277
exit(1);
22722278
}
22732279

2274-
if (replication_slot&&!streamwal)
2280+
if (replication_slot&&includewal!=STREAM_WAL)
22752281
{
22762282
fprintf(stderr,
22772283
_("%s: replication slots can only be used with WAL streaming\n"),

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp