Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 38c83c9

Browse files
committed
Refactor receivelog.c parameters
Much cruft had accumulated over time with a large number of parameters passed down between functions very deep. With this refactoring, instead introduce a StreamCtl structure that holds the parameters, and pass around a pointer to this structure instead. This makes it much easier to add or remove fields that are needed deeper down in the implementation without having to modify every function header in the file. Patch by me after much nagging from Andres Reviewed by Craig Ringer and Daniel Gustafsson
1 parent 73e7e49 commit 38c83c9

File tree

4 files changed

+136
-136
lines changed

4 files changed

+136
-136
lines changed

src/bin/pg_basebackup/pg_basebackup.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -372,10 +372,20 @@ typedef struct
372372
static int
373373
LogStreamerMain(logstreamer_param *param)
374374
{
375-
if (!ReceiveXlogStream(param->bgconn, param->startptr, param->timeline,
376-
param->sysidentifier, param->xlogdir,
377-
reached_end_position, standby_message_timeout,
378-
NULL, false, true))
375+
StreamCtl stream;
376+
377+
MemSet(&stream, sizeof(stream), 0);
378+
stream.startpos = param->startptr;
379+
stream.timeline = param->timeline;
380+
stream.sysidentifier = param->sysidentifier;
381+
stream.stream_stop = reached_end_position;
382+
stream.standby_message_timeout = standby_message_timeout;
383+
stream.synchronous = false;
384+
stream.mark_done = true;
385+
stream.basedir = param->xlogdir;
386+
stream.partial_suffix = NULL;
387+
388+
if (!ReceiveXlogStream(param->bgconn, &stream))
379389

380390
/*
381391
* Any errors will already have been reported in the function process,

src/bin/pg_basebackup/pg_receivexlog.c

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,11 @@ FindStreamingStart(uint32 *tli)
276276
static void
277277
StreamLog(void)
278278
{
279-
XLogRecPtr startpos,
280-
serverpos;
281-
TimeLineID starttli,
282-
servertli;
279+
XLogRecPtr serverpos;
280+
TimeLineID servertli;
281+
StreamCtl stream;
282+
283+
MemSet(&stream, 0, sizeof(stream));
283284

284285
/*
285286
* Connect in replication mode to the server
@@ -311,30 +312,35 @@ StreamLog(void)
311312
/*
312313
* Figure out where to start streaming.
313314
*/
314-
startpos = FindStreamingStart(&starttli);
315-
if (startpos == InvalidXLogRecPtr)
315+
stream.startpos = FindStreamingStart(&stream.timeline);
316+
if (stream.startpos == InvalidXLogRecPtr)
316317
{
317-
startpos = serverpos;
318-
starttli = servertli;
318+
stream.startpos = serverpos;
319+
stream.timeline = servertli;
319320
}
320321

321322
/*
322323
* Always start streaming at the beginning of a segment
323324
*/
324-
startpos -= startpos % XLOG_SEG_SIZE;
325+
stream.startpos -= stream.startpos % XLOG_SEG_SIZE;
325326

326327
/*
327328
* Start the replication
328329
*/
329330
if (verbose)
330331
fprintf(stderr,
331332
_("%s: starting log streaming at %X/%X (timeline %u)\n"),
332-
progname, (uint32) (startpos >> 32), (uint32) startpos,
333-
starttli);
333+
progname, (uint32) (stream.startpos >> 32), (uint32) stream.startpos,
334+
stream.timeline);
335+
336+
stream.stream_stop = stop_streaming;
337+
stream.standby_message_timeout = standby_message_timeout;
338+
stream.synchronous = synchronous;
339+
stream.mark_done = false;
340+
stream.basedir = basedir;
341+
stream.partial_suffix = ".partial";
334342

335-
ReceiveXlogStream(conn, startpos, starttli, NULL, basedir,
336-
stop_streaming, standby_message_timeout, ".partial",
337-
synchronous, false);
343+
ReceiveXlogStream(conn, &stream);
338344

339345
PQfinish(conn);
340346
conn = NULL;

0 commit comments

Comments
 (0)