Commit 38c83c9b authored by Magnus Hagander's avatar Magnus Hagander

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
parent 73e7e49d
......@@ -372,10 +372,20 @@ typedef struct
static int
LogStreamerMain(logstreamer_param *param)
{
if (!ReceiveXlogStream(param->bgconn, param->startptr, param->timeline,
param->sysidentifier, param->xlogdir,
reached_end_position, standby_message_timeout,
NULL, false, true))
StreamCtl stream;
MemSet(&stream, sizeof(stream), 0);
stream.startpos = param->startptr;
stream.timeline = param->timeline;
stream.sysidentifier = param->sysidentifier;
stream.stream_stop = reached_end_position;
stream.standby_message_timeout = standby_message_timeout;
stream.synchronous = false;
stream.mark_done = true;
stream.basedir = param->xlogdir;
stream.partial_suffix = NULL;
if (!ReceiveXlogStream(param->bgconn, &stream))
/*
* Any errors will already have been reported in the function process,
......
......@@ -276,10 +276,11 @@ FindStreamingStart(uint32 *tli)
static void
StreamLog(void)
{
XLogRecPtr startpos,
serverpos;
TimeLineID starttli,
servertli;
XLogRecPtr serverpos;
TimeLineID servertli;
StreamCtl stream;
MemSet(&stream, 0, sizeof(stream));
/*
* Connect in replication mode to the server
......@@ -311,17 +312,17 @@ StreamLog(void)
/*
* Figure out where to start streaming.
*/
startpos = FindStreamingStart(&starttli);
if (startpos == InvalidXLogRecPtr)
stream.startpos = FindStreamingStart(&stream.timeline);
if (stream.startpos == InvalidXLogRecPtr)
{
startpos = serverpos;
starttli = servertli;
stream.startpos = serverpos;
stream.timeline = servertli;
}
/*
* Always start streaming at the beginning of a segment
*/
startpos -= startpos % XLOG_SEG_SIZE;
stream.startpos -= stream.startpos % XLOG_SEG_SIZE;
/*
* Start the replication
......@@ -329,12 +330,17 @@ StreamLog(void)
if (verbose)
fprintf(stderr,
_("%s: starting log streaming at %X/%X (timeline %u)\n"),
progname, (uint32) (startpos >> 32), (uint32) startpos,
starttli);
progname, (uint32) (stream.startpos >> 32), (uint32) stream.startpos,
stream.timeline);
stream.stream_stop = stop_streaming;
stream.standby_message_timeout = standby_message_timeout;
stream.synchronous = synchronous;
stream.mark_done = false;
stream.basedir = basedir;
stream.partial_suffix = ".partial";
ReceiveXlogStream(conn, startpos, starttli, NULL, basedir,
stop_streaming, standby_message_timeout, ".partial",
synchronous, false);
ReceiveXlogStream(conn, &stream);
PQfinish(conn);
conn = NULL;
......
This diff is collapsed.
......@@ -22,16 +22,31 @@
*/
typedef bool (*stream_stop_callback) (XLogRecPtr segendpos, uint32 timeline, bool segment_finished);
/*
* Global parameters when receiving xlog stream. For details about the individual fields,
* see the function comment for ReceiveXlogStream().
*/
typedef struct StreamCtl
{
XLogRecPtr startpos; /* Start position for streaming */
TimeLineID timeline; /* Timeline to stream data from */
char *sysidentifier; /* Validate this system identifier and
* timeline */
int standby_message_timeout; /* Send status messages this
* often */
bool synchronous; /* Flush data on write */
bool mark_done; /* Mark segment as done in generated archive */
stream_stop_callback stream_stop; /* Stop streaming when returns true */
char *basedir; /* Received segments written to this dir */
char *partial_suffix; /* Suffix appended to partially received files */
} StreamCtl;
extern bool CheckServerVersionForStreaming(PGconn *conn);
extern bool ReceiveXlogStream(PGconn *conn,
XLogRecPtr startpos,
uint32 timeline,
char *sysidentifier,
char *basedir,
stream_stop_callback stream_stop,
int standby_message_timeout,
char *partial_suffix,
bool synchronous,
bool mark_done);
StreamCtl *stream);
#endif /* RECEIVELOG_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment