diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2014-05-15 19:43:37 +0300 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2014-05-15 19:47:48 +0300 |
commit | 00c26b6a60e7ceed29ddae34b0a69fe945c08f81 (patch) | |
tree | 13d80f0ef5a9af0fe6aa548a83e9c5a0b0ba5a6a /src | |
parent | 8f9b9590d79fc1fc1ad08b207401acfdbb0bfac7 (diff) | |
download | postgresql-00c26b6a60e7ceed29ddae34b0a69fe945c08f81.tar.gz postgresql-00c26b6a60e7ceed29ddae34b0a69fe945c08f81.zip |
Fix a couple of bugs in pg_recvlogical output to stdout.
Don't close stdout on SIGHUP. Also, when a SIGHUP is received, close the
file immediately, rather than only after receiving some more data from
the server. Rename a variable, to avoid mentally dealing with double
negatives (not unsynced means synced).
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/pg_basebackup/pg_recvlogical.c | 47 |
1 files changed, 22 insertions, 25 deletions
diff --git a/src/bin/pg_basebackup/pg_recvlogical.c b/src/bin/pg_basebackup/pg_recvlogical.c index 2bd1ad46630..9058c3daa70 100644 --- a/src/bin/pg_basebackup/pg_recvlogical.c +++ b/src/bin/pg_basebackup/pg_recvlogical.c @@ -51,7 +51,7 @@ static int outfd = -1; static volatile sig_atomic_t time_to_abort = false; static volatile sig_atomic_t output_reopen = false; static int64 output_last_fsync = -1; -static bool output_unsynced = false; +static bool output_needs_fsync = false; static XLogRecPtr output_written_lsn = InvalidXLogRecPtr; static XLogRecPtr output_fsync_lsn = InvalidXLogRecPtr; @@ -173,10 +173,10 @@ OutputFsync(int64 now) if (fsync_interval <= 0) return true; - if (!output_unsynced) + if (!output_needs_fsync) return true; - output_unsynced = false; + output_needs_fsync = false; /* Accept EINVAL, in case output is writing to a pipe or similar. */ if (fsync(outfd) != 0 && errno != EINVAL) @@ -304,6 +304,17 @@ StreamLog(void) last_status = now; } + /* got SIGHUP, close output file */ + if (outfd != -1 && output_reopen && strcmp(outfile, "-") != 0) + { + now = feGetCurrentTimestamp(); + if (!OutputFsync(now)) + goto error; + close(outfd); + outfd = -1; + } + output_reopen = false; + r = PQgetCopyData(conn, ©buf, 1); if (r == 0) { @@ -327,7 +338,7 @@ StreamLog(void) ((int64) 1000); /* Compute when we need to wakeup to fsync the output file. */ - if (fsync_interval > 0 && output_unsynced) + if (fsync_interval > 0 && output_needs_fsync) fsync_target = output_last_fsync + (fsync_interval - 1) * ((int64) 1000); @@ -468,28 +479,14 @@ StreamLog(void) output_written_lsn = Max(temp, output_written_lsn); } - /* redirect output to stdout */ - if (outfd == -1 && strcmp(outfile, "-") == 0) - { - outfd = fileno(stdout); - } - - /* got SIGHUP, close output file */ - if (outfd != -1 && output_reopen) - { - now = feGetCurrentTimestamp(); - if (!OutputFsync(now)) - goto error; - close(outfd); - outfd = -1; - output_reopen = false; - } - + /* open the output file, if not open yet */ if (outfd == -1) { - - outfd = open(outfile, O_CREAT | O_APPEND | O_WRONLY | PG_BINARY, - S_IRUSR | S_IWUSR); + if (strcmp(outfile, "-") == 0) + outfd = fileno(stdout); + else + outfd = open(outfile, O_CREAT | O_APPEND | O_WRONLY | PG_BINARY, + S_IRUSR | S_IWUSR); if (outfd == -1) { fprintf(stderr, @@ -503,7 +500,7 @@ StreamLog(void) bytes_written = 0; /* signal that a fsync is needed */ - output_unsynced = true; + output_needs_fsync = true; while (bytes_left) { |