@@ -41,8 +41,8 @@ static PGresult *HandleCopyStream(PGconn *conn, StreamCtl *stream,
41
41
XLogRecPtr * stoppos );
42
42
static int CopyStreamPoll (PGconn * conn , long timeout_ms );
43
43
static int CopyStreamReceive (PGconn * conn , long timeout , char * * buffer );
44
- static bool ProcessKeepaliveMsg (PGconn * conn , char * copybuf , int len ,
45
- XLogRecPtr blockpos , int64 * last_status );
44
+ static bool ProcessKeepaliveMsg (PGconn * conn , StreamCtl * stream , char * copybuf ,
45
+ int len , XLogRecPtr blockpos , int64 * last_status );
46
46
static bool ProcessXLogDataMsg (PGconn * conn , StreamCtl * stream , char * copybuf , int len ,
47
47
XLogRecPtr * blockpos );
48
48
static PGresult * HandleEndOfCopyStream (PGconn * conn , StreamCtl * stream , char * copybuf ,
@@ -56,7 +56,7 @@ static bool ReadEndOfStreamingResult(PGresult *res, XLogRecPtr *startpos,
56
56
uint32 * timeline );
57
57
58
58
static bool
59
- mark_file_as_archived (const char * basedir , const char * fname )
59
+ mark_file_as_archived (const char * basedir , const char * fname , bool do_sync )
60
60
{
61
61
int fd ;
62
62
static char tmppath [MAXPGPATH ];
@@ -74,10 +74,10 @@ mark_file_as_archived(const char *basedir, const char *fname)
74
74
75
75
close (fd );
76
76
77
- if (fsync_fname (tmppath , false, progname ) != 0 )
77
+ if (do_sync && fsync_fname (tmppath , false, progname ) != 0 )
78
78
return false;
79
79
80
- if (fsync_parent_path (tmppath , progname ) != 0 )
80
+ if (do_sync && fsync_parent_path (tmppath , progname ) != 0 )
81
81
return false;
82
82
83
83
return true;
@@ -134,9 +134,9 @@ open_walfile(StreamCtl *stream, XLogRecPtr startpoint)
134
134
* fsync, in case of a previous crash between padding and fsyncing the
135
135
* file.
136
136
*/
137
- if (fsync_fname (fn , false, progname ) != 0 )
137
+ if (stream -> do_sync && fsync_fname (fn , false, progname ) != 0 )
138
138
return false;
139
- if (fsync_parent_path (fn , progname ) != 0 )
139
+ if (stream -> do_sync && fsync_parent_path (fn , progname ) != 0 )
140
140
return false;
141
141
142
142
return true;
@@ -173,9 +173,9 @@ open_walfile(StreamCtl *stream, XLogRecPtr startpoint)
173
173
* using synchronous mode, where the file is modified and fsynced
174
174
* in-place, without a directory fsync.
175
175
*/
176
- if (fsync_fname (fn , false, progname ) != 0 )
176
+ if (stream -> do_sync && fsync_fname (fn , false, progname ) != 0 )
177
177
return false;
178
- if (fsync_parent_path (fn , progname ) != 0 )
178
+ if (stream -> do_sync && fsync_parent_path (fn , progname ) != 0 )
179
179
return false;
180
180
181
181
if (lseek (f , SEEK_SET , 0 ) != 0 )
@@ -212,7 +212,7 @@ close_walfile(StreamCtl *stream, XLogRecPtr pos)
212
212
return false;
213
213
}
214
214
215
- if (fsync (walfile ) != 0 )
215
+ if (stream -> do_sync && fsync (walfile ) != 0 )
216
216
{
217
217
fprintf (stderr , _ ("%s: could not fsync file \"%s\": %s\n" ),
218
218
progname , current_walfile_name , strerror (errno ));
@@ -258,7 +258,8 @@ close_walfile(StreamCtl *stream, XLogRecPtr pos)
258
258
if (currpos == XLOG_SEG_SIZE && stream -> mark_done )
259
259
{
260
260
/* writes error message if failed */
261
- if (!mark_file_as_archived (stream -> basedir , current_walfile_name ))
261
+ if (!mark_file_as_archived (stream -> basedir , current_walfile_name ,
262
+ stream -> do_sync ))
262
263
return false;
263
264
}
264
265
@@ -378,7 +379,8 @@ writeTimeLineHistoryFile(StreamCtl *stream, char *filename, char *content)
378
379
if (stream -> mark_done )
379
380
{
380
381
/* writes error message if failed */
381
- if (!mark_file_as_archived (stream -> basedir , histfname ))
382
+ if (!mark_file_as_archived (stream -> basedir , histfname ,
383
+ stream -> do_sync ))
382
384
return false;
383
385
}
384
386
@@ -836,7 +838,7 @@ HandleCopyStream(PGconn *conn, StreamCtl *stream,
836
838
*/
837
839
if (stream -> synchronous && lastFlushPosition < blockpos && walfile != -1 )
838
840
{
839
- if (fsync (walfile ) != 0 )
841
+ if (stream -> do_sync && fsync (walfile ) != 0 )
840
842
{
841
843
fprintf (stderr , _ ("%s: could not fsync file \"%s\": %s\n" ),
842
844
progname , current_walfile_name , strerror (errno ));
@@ -890,7 +892,7 @@ HandleCopyStream(PGconn *conn, StreamCtl *stream,
890
892
/* Check the message type. */
891
893
if (copybuf [0 ] == 'k' )
892
894
{
893
- if (!ProcessKeepaliveMsg (conn , copybuf , r , blockpos ,
895
+ if (!ProcessKeepaliveMsg (conn , stream , copybuf , r , blockpos ,
894
896
& last_status ))
895
897
goto error ;
896
898
}
@@ -1043,7 +1045,7 @@ CopyStreamReceive(PGconn *conn, long timeout, char **buffer)
1043
1045
* Process the keepalive message.
1044
1046
*/
1045
1047
static bool
1046
- ProcessKeepaliveMsg (PGconn * conn , char * copybuf , int len ,
1048
+ ProcessKeepaliveMsg (PGconn * conn , StreamCtl * stream , char * copybuf , int len ,
1047
1049
XLogRecPtr blockpos , int64 * last_status )
1048
1050
{
1049
1051
int pos ;
@@ -1079,7 +1081,7 @@ ProcessKeepaliveMsg(PGconn *conn, char *copybuf, int len,
1079
1081
* data has been successfully replicated or not, at the normal
1080
1082
* shutdown of the server.
1081
1083
*/
1082
- if (fsync (walfile ) != 0 )
1084
+ if (stream -> do_sync && fsync (walfile ) != 0 )
1083
1085
{
1084
1086
fprintf (stderr , _ ("%s: could not fsync file \"%s\": %s\n" ),
1085
1087
progname , current_walfile_name , strerror (errno ));
0 commit comments