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

Commitb935eb7

Browse files
committed
Fix reversed check of return value from sync
While at it also update the comments in walmethods.h to make it lesslikely for mistakes like this to appear in the future (thanks to Tom forimprovements to the comments).And finally, in passing change the return type of walmethod.getlasterrorto being const, also per suggestion from Tom.
1 parent587d62d commitb935eb7

File tree

3 files changed

+51
-4
lines changed

3 files changed

+51
-4
lines changed

‎src/bin/pg_basebackup/receivelog.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,11 @@ open_walfile(StreamCtl *stream, XLogRecPtr startpoint)
132132
}
133133

134134
/* fsync file in case of a previous crash */
135-
if (!stream->walmethod->sync(f))
135+
if (stream->walmethod->sync(f)!=0)
136136
{
137+
fprintf(stderr,
138+
_("%s: could not sync existing transaction log file \"%s\": %s\n"),
139+
progname,fn,stream->walmethod->getlasterror());
137140
stream->walmethod->close(f,CLOSE_UNLINK);
138141
return false;
139142
}

‎src/bin/pg_basebackup/walmethods.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ typedef struct DirectoryMethodFile
6161
#endif
6262
}DirectoryMethodFile;
6363

64-
staticchar*
64+
staticconstchar*
6565
dir_getlasterror(void)
6666
{
6767
/* Directory method always sets errno, so just use strerror */
@@ -406,7 +406,7 @@ static TarMethodData *tar_data = NULL;
406406
#definetar_clear_error() tar_data->lasterror[0] = '\0'
407407
#definetar_set_error(msg) strlcpy(tar_data->lasterror, msg, sizeof(tar_data->lasterror))
408408

409-
staticchar*
409+
staticconstchar*
410410
tar_getlasterror(void)
411411
{
412412
/*

‎src/bin/pg_basebackup/walmethods.h

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,63 @@ typedef enum
1919
CLOSE_NO_RENAME
2020
}WalCloseMethod;
2121

22+
/*
23+
* A WalWriteMethod structure represents the different methods used
24+
* to write the streaming WAL as it's received.
25+
*
26+
* All methods that have a failure return indicator will set state
27+
* allowing the getlasterror() method to return a suitable message.
28+
* Commonly, errno is this state (or part of it); so callers must take
29+
* care not to clobber errno between a failed method call and use of
30+
* getlasterror() to retrieve the message.
31+
*/
2232
typedefstructWalWriteMethodWalWriteMethod;
2333
structWalWriteMethod
2434
{
35+
/*
36+
* Open a target file. Returns Walfile, or NULL if open failed. If a temp
37+
* suffix is specified, a file with that name will be opened, and then
38+
* automatically renamed in close(). If pad_to_size is specified, the file
39+
* will be padded with NUL up to that size, if supported by the Walmethod.
40+
*/
2541
Walfile(*open_for_write) (constchar*pathname,constchar*temp_suffix,size_tpad_to_size);
42+
43+
/*
44+
* Close an open Walfile, using one or more methods for handling automatic
45+
* unlinking etc. Returns 0 on success, other values for error.
46+
*/
2647
int(*close) (Walfilef,WalCloseMethodmethod);
48+
49+
/* Check if a file exist */
2750
bool(*existsfile) (constchar*pathname);
51+
52+
/* Return the size of a file, or -1 on failure. */
2853
ssize_t(*get_file_size) (constchar*pathname);
2954

55+
/*
56+
* Write count number of bytes to the file, and return the number of bytes
57+
* actually written or -1 for error.
58+
*/
3059
ssize_t(*write) (Walfilef,constvoid*buf,size_tcount);
60+
61+
/* Return the current position in a file or -1 on error */
3162
off_t(*get_current_pos) (Walfilef);
63+
64+
/*
65+
* fsync the contents of the specified file. Returns 0 on success.
66+
*/
3267
int(*sync) (Walfilef);
68+
69+
/*
70+
* Clean up the Walmethod, closing any shared resources. For methods like
71+
* tar, this includes writing updated headers. Returns true if the
72+
* close/write/sync of shared resources succeeded, otherwise returns false
73+
* (but the resources are still closed).
74+
*/
3375
bool(*finish) (void);
34-
char*(*getlasterror) (void);
76+
77+
/* Return a text for the last error in this Walfile */
78+
constchar*(*getlasterror) (void);
3579
};
3680

3781
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp