From 254316f5a240621ea417329bd26320c53e283020 Mon Sep 17 00:00:00 2001 From: Magnus Hagander Date: Mon, 6 Aug 2012 13:53:46 +0200 Subject: [PATCH] Complain with proper error message if streaming stops prematurely In particular, with a controlled shutdown of the master, pg_basebackup with streaming log could terminate without an error message, even though the backup is not consistent. In passing, fix a few cases where walfile wasn't properly set to -1 after closing. Fujii Masao --- src/bin/pg_basebackup/receivelog.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/bin/pg_basebackup/receivelog.c b/src/bin/pg_basebackup/receivelog.c index c91cf1bbe8..5e7445626f 100644 --- a/src/bin/pg_basebackup/receivelog.c +++ b/src/bin/pg_basebackup/receivelog.c @@ -611,11 +611,20 @@ ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, } PQclear(res); + /* Complain if we've not reached stop point yet */ + if (stream_stop != NULL && !stream_stop(blockpos, timeline, false)) + { + fprintf(stderr, _("%s: replication stream was terminated before stop point\n"), + progname); + goto error; + } + if (copybuf != NULL) PQfreemem(copybuf); if (walfile != -1 && close(walfile) != 0) fprintf(stderr, _("%s: could not close file %s: %s\n"), progname, current_walfile_name, strerror(errno)); + walfile = -1; return true; error: @@ -624,5 +633,6 @@ error: if (walfile != -1 && close(walfile) != 0) fprintf(stderr, _("%s: could not close file %s: %s\n"), progname, current_walfile_name, strerror(errno)); + walfile = -1; return false; }