@@ -113,8 +113,14 @@ open_walfile(XLogRecPtr startpoint, uint32 timeline, char *basedir, char *namebu
113113 return f ;
114114}
115115
116+ /*
117+ * Close the current WAL file, and rename it to the correct filename if it's complete.
118+ *
119+ * If segment_complete is true, rename the current WAL file even if we've not
120+ * completed writing the whole segment.
121+ */
116122static bool
117- close_walfile (int walfile , char * basedir , char * walname )
123+ close_walfile (int walfile , char * basedir , char * walname , bool segment_complete )
118124{
119125 off_t currpos = lseek (walfile , 0 , SEEK_CUR );
120126
@@ -141,9 +147,9 @@ close_walfile(int walfile, char *basedir, char *walname)
141147
142148 /*
143149 * Rename the .partial file only if we've completed writing the
144- * whole segment.
150+ * whole segment or segment_complete is true .
145151 */
146- if (currpos == XLOG_SEG_SIZE )
152+ if (currpos == XLOG_SEG_SIZE || segment_complete )
147153 {
148154 char oldfn [MAXPGPATH ];
149155 char newfn [MAXPGPATH ];
@@ -199,11 +205,10 @@ localGetCurrentTimestamp(void)
199205 * All received segments will be written to the directory
200206 * specified by basedir.
201207 *
202- * The segment_finish callback will be called after each segment
203- * has been finished, and the stream_continue callback will be
204- * called every time data is received. If either of these callbacks
205- * return true, the streaming will stop and the function
206- * return. As long as they return false, streaming will continue
208+ * The stream_stop callback will be called every time data
209+ * is received, and whenever a segment is completed. If it returns
210+ * true, the streaming will stop and the function
211+ * return. As long as it returns false, streaming will continue
207212 * indefinitely.
208213 *
209214 * standby_message_timeout controls how often we send a message
@@ -214,7 +219,7 @@ localGetCurrentTimestamp(void)
214219 * Note: The log position *must* be at a log segment start!
215220 */
216221bool
217- ReceiveXlogStream (PGconn * conn , XLogRecPtr startpos , uint32 timeline , char * sysidentifier , char * basedir , segment_finish_callback segment_finish , stream_continue_callback stream_continue , int standby_message_timeout )
222+ ReceiveXlogStream (PGconn * conn , XLogRecPtr startpos , uint32 timeline , char * sysidentifier , char * basedir , stream_stop_callback stream_stop , int standby_message_timeout , bool rename_partial )
218223{
219224 char query [128 ];
220225 char current_walfile_name [MAXPGPATH ];
@@ -288,11 +293,11 @@ ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, char *sysi
288293 /*
289294 * Check if we should continue streaming, or abort at this point.
290295 */
291- if (stream_continue && stream_continue ( ))
296+ if (stream_stop && stream_stop ( blockpos , timeline , false ))
292297 {
293298 if (walfile != -1 )
294299 /* Potential error message is written by close_walfile */
295- return close_walfile (walfile , basedir , current_walfile_name );
300+ return close_walfile (walfile , basedir , current_walfile_name , rename_partial );
296301 return true;
297302 }
298303
@@ -486,20 +491,20 @@ ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, char *sysi
486491 /* Did we reach the end of a WAL segment? */
487492 if (blockpos .xrecoff % XLOG_SEG_SIZE == 0 )
488493 {
489- if (!close_walfile (walfile , basedir , current_walfile_name ))
494+ if (!close_walfile (walfile , basedir , current_walfile_name , false ))
490495 /* Error message written in close_walfile() */
491496 return false;
492497
493498 walfile = -1 ;
494499 xlogoff = 0 ;
495500
496- if (segment_finish != NULL )
501+ if (stream_stop != NULL )
497502 {
498503 /*
499504 * Callback when the segment finished, and return if it
500505 * told us to.
501506 */
502- if (segment_finish (blockpos , timeline ))
507+ if (stream_stop (blockpos , timeline , true ))
503508 return true;
504509 }
505510 }
0 commit comments