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

Commit4fd1479

Browse files
committed
walmethods.c/h: Make Walfile a struct, rather than a void *
This makes the curent file position and pathname visible in a genericway, so we no longer need current_walfile_name global variable or theget_current_pos() method. Since that purported to be able to fail butnever actually did, this also lets us get rid of some unnecessaryerror-handling code.One risk of this change is that the get_current_pos() methodpreviously cleared the error indicator, and that will no longer happenwith the new approach. I looked for a way that this could cause problemsand did not find one.The previous code was confused about whether "Walfile" was theimplementation-dependent structure representing a WAL file orwhether it was a pointer to that stucture. Some of the code used itone way, and some in the other. The compiler tolerated that becausevoid * is interchangeable with void **, but now that Walfile is astruct, it's necessary to be consistent. Hence, some references to"Walfile" have been converted to "Walfile *".Discussion:http://postgr.es/m/CA+TgmoZS0Kw98fOoAcGz8B9iDhdqB4Be4e=vDZaJZ5A-xMYBqA@mail.gmail.com
1 parent1fe1d09 commit4fd1479

File tree

3 files changed

+70
-94
lines changed

3 files changed

+70
-94
lines changed

‎src/bin/pg_basebackup/receivelog.c

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@
2525
#include"receivelog.h"
2626
#include"streamutil.h"
2727

28-
/*fd and filename forcurrently open WAL file */
28+
/* currently open WAL file */
2929
staticWalfile*walfile=NULL;
30-
staticcharcurrent_walfile_name[MAXPGPATH]="";
3130
staticboolreportFlushPosition= false;
3231
staticXLogRecPtrlastFlushPosition=InvalidXLogRecPtr;
3332

@@ -82,8 +81,7 @@ mark_file_as_archived(StreamCtl *stream, const char *fname)
8281
* Open a new WAL file in the specified directory.
8382
*
8483
* Returns true if OK; on failure, returns false after printing an error msg.
85-
* On success, 'walfile' is set to the FD for the file, and the base filename
86-
* (without partial_suffix) is stored in 'current_walfile_name'.
84+
* On success, 'walfile' is set to the opened WAL file.
8785
*
8886
* The file will be padded to 16Mb with zeroes.
8987
*/
@@ -94,12 +92,13 @@ open_walfile(StreamCtl *stream, XLogRecPtr startpoint)
9492
char*fn;
9593
ssize_tsize;
9694
XLogSegNosegno;
95+
charwalfile_name[MAXPGPATH];
9796

9897
XLByteToSeg(startpoint,segno,WalSegSz);
99-
XLogFileName(current_walfile_name,stream->timeline,segno,WalSegSz);
98+
XLogFileName(walfile_name,stream->timeline,segno,WalSegSz);
10099

101100
/* Note that this considers the compression used if necessary */
102-
fn=stream->walmethod->get_file_name(current_walfile_name,
101+
fn=stream->walmethod->get_file_name(walfile_name,
103102
stream->partial_suffix);
104103

105104
/*
@@ -126,7 +125,7 @@ open_walfile(StreamCtl *stream, XLogRecPtr startpoint)
126125
if (size==WalSegSz)
127126
{
128127
/* Already padded file. Open it for use */
129-
f=stream->walmethod->open_for_write(current_walfile_name,stream->partial_suffix,0);
128+
f=stream->walmethod->open_for_write(walfile_name,stream->partial_suffix,0);
130129
if (f==NULL)
131130
{
132131
pg_log_error("could not open existing write-ahead log file \"%s\": %s",
@@ -165,7 +164,7 @@ open_walfile(StreamCtl *stream, XLogRecPtr startpoint)
165164

166165
/* No file existed, so create one */
167166

168-
f=stream->walmethod->open_for_write(current_walfile_name,
167+
f=stream->walmethod->open_for_write(walfile_name,
169168
stream->partial_suffix,WalSegSz);
170169
if (f==NULL)
171170
{
@@ -191,27 +190,18 @@ close_walfile(StreamCtl *stream, XLogRecPtr pos)
191190
char*fn;
192191
off_tcurrpos;
193192
intr;
193+
charwalfile_name[MAXPGPATH];
194194

195195
if (walfile==NULL)
196196
return true;
197197

198+
strlcpy(walfile_name,walfile->pathname,MAXPGPATH);
199+
currpos=walfile->currpos;
200+
198201
/* Note that this considers the compression used if necessary */
199-
fn=stream->walmethod->get_file_name(current_walfile_name,
202+
fn=stream->walmethod->get_file_name(walfile_name,
200203
stream->partial_suffix);
201204

202-
currpos=stream->walmethod->get_current_pos(walfile);
203-
204-
if (currpos==-1)
205-
{
206-
pg_log_error("could not determine seek position in file \"%s\": %s",
207-
fn,stream->walmethod->getlasterror());
208-
stream->walmethod->close(walfile,CLOSE_UNLINK);
209-
walfile=NULL;
210-
211-
pg_free(fn);
212-
return false;
213-
}
214-
215205
if (stream->partial_suffix)
216206
{
217207
if (currpos==WalSegSz)
@@ -247,7 +237,7 @@ close_walfile(StreamCtl *stream, XLogRecPtr pos)
247237
if (currpos==WalSegSz&&stream->mark_done)
248238
{
249239
/* writes error message if failed */
250-
if (!mark_file_as_archived(stream,current_walfile_name))
240+
if (!mark_file_as_archived(stream,walfile_name))
251241
return false;
252242
}
253243

@@ -690,7 +680,7 @@ ReceiveXlogStream(PGconn *conn, StreamCtl *stream)
690680
error:
691681
if (walfile!=NULL&&stream->walmethod->close(walfile,CLOSE_NO_RENAME)!=0)
692682
pg_log_error("could not close file \"%s\": %s",
693-
current_walfile_name,stream->walmethod->getlasterror());
683+
walfile->pathname,stream->walmethod->getlasterror());
694684
walfile=NULL;
695685
return false;
696686
}
@@ -777,7 +767,7 @@ HandleCopyStream(PGconn *conn, StreamCtl *stream,
777767
{
778768
if (stream->walmethod->sync(walfile)!=0)
779769
pg_fatal("could not fsync file \"%s\": %s",
780-
current_walfile_name,stream->walmethod->getlasterror());
770+
walfile->pathname,stream->walmethod->getlasterror());
781771
lastFlushPosition=blockpos;
782772

783773
/*
@@ -1024,7 +1014,7 @@ ProcessKeepaliveMsg(PGconn *conn, StreamCtl *stream, char *copybuf, int len,
10241014
*/
10251015
if (stream->walmethod->sync(walfile)!=0)
10261016
pg_fatal("could not fsync file \"%s\": %s",
1027-
current_walfile_name,stream->walmethod->getlasterror());
1017+
walfile->pathname,stream->walmethod->getlasterror());
10281018
lastFlushPosition=blockpos;
10291019
}
10301020

@@ -1092,10 +1082,10 @@ ProcessXLogDataMsg(PGconn *conn, StreamCtl *stream, char *copybuf, int len,
10921082
else
10931083
{
10941084
/* More data in existing segment */
1095-
if (stream->walmethod->get_current_pos(walfile)!=xlogoff)
1085+
if (walfile->currpos!=xlogoff)
10961086
{
10971087
pg_log_error("got WAL data offset %08x, expected %08x",
1098-
xlogoff, (int)stream->walmethod->get_current_pos(walfile));
1088+
xlogoff, (int)walfile->currpos);
10991089
return false;
11001090
}
11011091
}
@@ -1129,7 +1119,7 @@ ProcessXLogDataMsg(PGconn *conn, StreamCtl *stream, char *copybuf, int len,
11291119
bytes_to_write)!=bytes_to_write)
11301120
{
11311121
pg_log_error("could not write %d bytes to WAL file \"%s\": %s",
1132-
bytes_to_write,current_walfile_name,
1122+
bytes_to_write,walfile->pathname,
11331123
stream->walmethod->getlasterror());
11341124
return false;
11351125
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp