@@ -113,8 +113,14 @@ open_walfile(XLogRecPtr startpoint, uint32 timeline, char *basedir, char *namebu
113
113
return f ;
114
114
}
115
115
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
+ */
116
122
static bool
117
- close_walfile (int walfile , char * basedir , char * walname )
123
+ close_walfile (int walfile , char * basedir , char * walname , bool segment_complete )
118
124
{
119
125
off_t currpos = lseek (walfile , 0 , SEEK_CUR );
120
126
@@ -141,9 +147,9 @@ close_walfile(int walfile, char *basedir, char *walname)
141
147
142
148
/*
143
149
* Rename the .partial file only if we've completed writing the
144
- * whole segment.
150
+ * whole segment or segment_complete is true .
145
151
*/
146
- if (currpos == XLOG_SEG_SIZE )
152
+ if (currpos == XLOG_SEG_SIZE || segment_complete )
147
153
{
148
154
char oldfn [MAXPGPATH ];
149
155
char newfn [MAXPGPATH ];
@@ -199,11 +205,10 @@ localGetCurrentTimestamp(void)
199
205
* All received segments will be written to the directory
200
206
* specified by basedir.
201
207
*
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
207
212
* indefinitely.
208
213
*
209
214
* standby_message_timeout controls how often we send a message
@@ -214,7 +219,7 @@ localGetCurrentTimestamp(void)
214
219
* Note: The log position *must* be at a log segment start!
215
220
*/
216
221
bool
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 )
218
223
{
219
224
char query [128 ];
220
225
char current_walfile_name [MAXPGPATH ];
@@ -288,11 +293,11 @@ ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, char *sysi
288
293
/*
289
294
* Check if we should continue streaming, or abort at this point.
290
295
*/
291
- if (stream_continue && stream_continue ( ))
296
+ if (stream_stop && stream_stop ( blockpos , timeline , false ))
292
297
{
293
298
if (walfile != -1 )
294
299
/* 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 );
296
301
return true;
297
302
}
298
303
@@ -486,20 +491,20 @@ ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, char *sysi
486
491
/* Did we reach the end of a WAL segment? */
487
492
if (blockpos .xrecoff % XLOG_SEG_SIZE == 0 )
488
493
{
489
- if (!close_walfile (walfile , basedir , current_walfile_name ))
494
+ if (!close_walfile (walfile , basedir , current_walfile_name , false ))
490
495
/* Error message written in close_walfile() */
491
496
return false;
492
497
493
498
walfile = -1 ;
494
499
xlogoff = 0 ;
495
500
496
- if (segment_finish != NULL )
501
+ if (stream_stop != NULL )
497
502
{
498
503
/*
499
504
* Callback when the segment finished, and return if it
500
505
* told us to.
501
506
*/
502
- if (segment_finish (blockpos , timeline ))
507
+ if (stream_stop (blockpos , timeline , true ))
503
508
return true;
504
509
}
505
510
}
0 commit comments