@@ -41,8 +41,8 @@ static PGresult *HandleCopyStream(PGconn *conn, StreamCtl *stream,
4141 XLogRecPtr * stoppos );
4242static int CopyStreamPoll (PGconn * conn , long timeout_ms );
4343static 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 );
4646static bool ProcessXLogDataMsg (PGconn * conn , StreamCtl * stream , char * copybuf , int len ,
4747 XLogRecPtr * blockpos );
4848static PGresult * HandleEndOfCopyStream (PGconn * conn , StreamCtl * stream , char * copybuf ,
@@ -56,7 +56,7 @@ static bool ReadEndOfStreamingResult(PGresult *res, XLogRecPtr *startpos,
5656 uint32 * timeline );
5757
5858static 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 )
6060{
6161 int fd ;
6262 static char tmppath [MAXPGPATH ];
@@ -74,10 +74,10 @@ mark_file_as_archived(const char *basedir, const char *fname)
7474
7575 close (fd );
7676
77- if (fsync_fname (tmppath , false, progname ) != 0 )
77+ if (do_sync && fsync_fname (tmppath , false, progname ) != 0 )
7878 return false;
7979
80- if (fsync_parent_path (tmppath , progname ) != 0 )
80+ if (do_sync && fsync_parent_path (tmppath , progname ) != 0 )
8181 return false;
8282
8383 return true;
@@ -134,9 +134,9 @@ open_walfile(StreamCtl *stream, XLogRecPtr startpoint)
134134 * fsync, in case of a previous crash between padding and fsyncing the
135135 * file.
136136 */
137- if (fsync_fname (fn , false, progname ) != 0 )
137+ if (stream -> do_sync && fsync_fname (fn , false, progname ) != 0 )
138138 return false;
139- if (fsync_parent_path (fn , progname ) != 0 )
139+ if (stream -> do_sync && fsync_parent_path (fn , progname ) != 0 )
140140 return false;
141141
142142 return true;
@@ -173,9 +173,9 @@ open_walfile(StreamCtl *stream, XLogRecPtr startpoint)
173173 * using synchronous mode, where the file is modified and fsynced
174174 * in-place, without a directory fsync.
175175 */
176- if (fsync_fname (fn , false, progname ) != 0 )
176+ if (stream -> do_sync && fsync_fname (fn , false, progname ) != 0 )
177177 return false;
178- if (fsync_parent_path (fn , progname ) != 0 )
178+ if (stream -> do_sync && fsync_parent_path (fn , progname ) != 0 )
179179 return false;
180180
181181 if (lseek (f , SEEK_SET , 0 ) != 0 )
@@ -212,7 +212,7 @@ close_walfile(StreamCtl *stream, XLogRecPtr pos)
212212 return false;
213213 }
214214
215- if (fsync (walfile ) != 0 )
215+ if (stream -> do_sync && fsync (walfile ) != 0 )
216216 {
217217 fprintf (stderr , _ ("%s: could not fsync file \"%s\": %s\n" ),
218218 progname , current_walfile_name , strerror (errno ));
@@ -258,7 +258,8 @@ close_walfile(StreamCtl *stream, XLogRecPtr pos)
258258 if (currpos == XLOG_SEG_SIZE && stream -> mark_done )
259259 {
260260 /* 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 ))
262263 return false;
263264 }
264265
@@ -378,7 +379,8 @@ writeTimeLineHistoryFile(StreamCtl *stream, char *filename, char *content)
378379 if (stream -> mark_done )
379380 {
380381 /* 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 ))
382384 return false;
383385 }
384386
@@ -836,7 +838,7 @@ HandleCopyStream(PGconn *conn, StreamCtl *stream,
836838 */
837839 if (stream -> synchronous && lastFlushPosition < blockpos && walfile != -1 )
838840 {
839- if (fsync (walfile ) != 0 )
841+ if (stream -> do_sync && fsync (walfile ) != 0 )
840842 {
841843 fprintf (stderr , _ ("%s: could not fsync file \"%s\": %s\n" ),
842844 progname , current_walfile_name , strerror (errno ));
@@ -890,7 +892,7 @@ HandleCopyStream(PGconn *conn, StreamCtl *stream,
890892 /* Check the message type. */
891893 if (copybuf [0 ] == 'k' )
892894 {
893- if (!ProcessKeepaliveMsg (conn , copybuf , r , blockpos ,
895+ if (!ProcessKeepaliveMsg (conn , stream , copybuf , r , blockpos ,
894896 & last_status ))
895897 goto error ;
896898 }
@@ -1043,7 +1045,7 @@ CopyStreamReceive(PGconn *conn, long timeout, char **buffer)
10431045 * Process the keepalive message.
10441046 */
10451047static bool
1046- ProcessKeepaliveMsg (PGconn * conn , char * copybuf , int len ,
1048+ ProcessKeepaliveMsg (PGconn * conn , StreamCtl * stream , char * copybuf , int len ,
10471049 XLogRecPtr blockpos , int64 * last_status )
10481050{
10491051 int pos ;
@@ -1079,7 +1081,7 @@ ProcessKeepaliveMsg(PGconn *conn, char *copybuf, int len,
10791081 * data has been successfully replicated or not, at the normal
10801082 * shutdown of the server.
10811083 */
1082- if (fsync (walfile ) != 0 )
1084+ if (stream -> do_sync && fsync (walfile ) != 0 )
10831085 {
10841086 fprintf (stderr , _ ("%s: could not fsync file \"%s\": %s\n" ),
10851087 progname , current_walfile_name , strerror (errno ));
0 commit comments