diff options
author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2012-07-31 10:09:16 -0400 |
---|---|---|
committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2012-07-31 11:02:21 -0400 |
commit | 65f33352494cccf70ab512c5c6d1637b31a13364 (patch) | |
tree | e924bc7fcf7277ec277ec78ffae39d9263e9bfc3 /src/bin/pg_basebackup/receivelog.c | |
parent | 776bdc4c5c019a9556a6622a01a406c6c0fec4c9 (diff) |
pg_basebackup: stylistic adjustments
The most user-visible part of this is to change the long options
--statusint and --noloop to --status-interval and --no-loop,
respectively, per discussion.
Also, consistently enclose file names in double quotes, per our
conventions; and consistently use the term "transaction log file" to
talk about WAL segments. (Someday we may need to go over this
terminology and make it consistent across the whole source code.)
Finally, reflow the code to better fit in 80 columns, and have pgindent
fix it up some more.
Diffstat (limited to 'src/bin/pg_basebackup/receivelog.c')
-rw-r--r-- | src/bin/pg_basebackup/receivelog.c | 92 |
1 files changed, 58 insertions, 34 deletions
diff --git a/src/bin/pg_basebackup/receivelog.c b/src/bin/pg_basebackup/receivelog.c index c5b08fcc7ae..3b464123b34 100644 --- a/src/bin/pg_basebackup/receivelog.c +++ b/src/bin/pg_basebackup/receivelog.c @@ -41,7 +41,7 @@ const XLogRecPtr InvalidXLogRecPtr = {0, 0}; /* fd for currently open WAL file */ -static int walfile = -1; +static int walfile = -1; /* @@ -52,7 +52,8 @@ static int walfile = -1; * The file will be padded to 16Mb with zeroes. */ static int -open_walfile(XLogRecPtr startpoint, uint32 timeline, char *basedir, char *namebuf) +open_walfile(XLogRecPtr startpoint, uint32 timeline, char *basedir, + char *namebuf) { int f; char fn[MAXPGPATH]; @@ -67,7 +68,8 @@ open_walfile(XLogRecPtr startpoint, uint32 timeline, char *basedir, char *namebu f = open(fn, O_WRONLY | O_CREAT | PG_BINARY, S_IRUSR | S_IWUSR); if (f == -1) { - fprintf(stderr, _("%s: could not open WAL segment %s: %s\n"), + fprintf(stderr, + _("%s: could not open transaction log file \"%s\": %s\n"), progname, fn, strerror(errno)); return -1; } @@ -78,7 +80,8 @@ open_walfile(XLogRecPtr startpoint, uint32 timeline, char *basedir, char *namebu */ if (fstat(f, &statbuf) != 0) { - fprintf(stderr, _("%s: could not stat WAL segment %s: %s\n"), + fprintf(stderr, + _("%s: could not stat transaction log file \"%s\": %s\n"), progname, fn, strerror(errno)); close(f); return -1; @@ -87,7 +90,8 @@ open_walfile(XLogRecPtr startpoint, uint32 timeline, char *basedir, char *namebu return f; /* File is open and ready to use */ if (statbuf.st_size != 0) { - fprintf(stderr, _("%s: WAL segment %s is %d bytes, should be 0 or %d\n"), + fprintf(stderr, + _("%s: transaction log file \"%s\" has %d bytes, should be 0 or %d\n"), progname, fn, (int) statbuf.st_size, XLogSegSize); close(f); return -1; @@ -99,7 +103,8 @@ open_walfile(XLogRecPtr startpoint, uint32 timeline, char *basedir, char *namebu { if (write(f, zerobuf, XLOG_BLCKSZ) != XLOG_BLCKSZ) { - fprintf(stderr, _("%s: could not pad WAL segment %s: %s\n"), + fprintf(stderr, + _("%s: could not pad transaction log file \"%s\": %s\n"), progname, fn, strerror(errno)); free(zerobuf); close(f); @@ -111,7 +116,8 @@ open_walfile(XLogRecPtr startpoint, uint32 timeline, char *basedir, char *namebu if (lseek(f, SEEK_SET, 0) != 0) { - fprintf(stderr, _("%s: could not seek back to beginning of WAL segment %s: %s\n"), + fprintf(stderr, + _("%s: could not seek to beginning of transaction log file \"%s\": %s\n"), progname, fn, strerror(errno)); close(f); return -1; @@ -120,7 +126,8 @@ open_walfile(XLogRecPtr startpoint, uint32 timeline, char *basedir, char *namebu } /* - * Close the current WAL file, and rename it to the correct filename if it's complete. + * Close the current WAL file, and rename it to the correct filename if it's + * complete. * * If segment_complete is true, rename the current WAL file even if we've not * completed writing the whole segment. @@ -132,21 +139,22 @@ close_walfile(char *basedir, char *walname, bool segment_complete) if (currpos == -1) { - fprintf(stderr, _("%s: could not get current position in file %s: %s\n"), + fprintf(stderr, + _("%s: could not determine seek position in file \"%s\": %s\n"), progname, walname, strerror(errno)); return false; } if (fsync(walfile) != 0) { - fprintf(stderr, _("%s: could not fsync file %s: %s\n"), + fprintf(stderr, _("%s: could not fsync file \"%s\": %s\n"), progname, walname, strerror(errno)); return false; } if (close(walfile) != 0) { - fprintf(stderr, _("%s: could not close file %s: %s\n"), + fprintf(stderr, _("%s: could not close file \"%s\": %s\n"), progname, walname, strerror(errno)); walfile = -1; return false; @@ -166,13 +174,14 @@ close_walfile(char *basedir, char *walname, bool segment_complete) snprintf(newfn, sizeof(newfn), "%s/%s", basedir, walname); if (rename(oldfn, newfn) != 0) { - fprintf(stderr, _("%s: could not rename file %s: %s\n"), + fprintf(stderr, _("%s: could not rename file \"%s\": %s\n"), progname, walname, strerror(errno)); return false; } } else - fprintf(stderr, _("%s: not renaming %s, segment is not complete.\n"), + fprintf(stderr, + _("%s: not renaming \"%s\", segment is not complete.\n"), progname, walname); return true; @@ -272,7 +281,10 @@ localTimestampDifferenceExceeds(TimestampTz start_time, * Note: The log position *must* be at a log segment start! */ bool -ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, char *sysidentifier, char *basedir, stream_stop_callback stream_stop, int standby_message_timeout, bool rename_partial) +ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, + char *sysidentifier, char *basedir, + stream_stop_callback stream_stop, + int standby_message_timeout, bool rename_partial) { char query[128]; char current_walfile_name[MAXPGPATH]; @@ -287,27 +299,33 @@ ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, char *sysi res = PQexec(conn, "IDENTIFY_SYSTEM"); if (PQresultStatus(res) != PGRES_TUPLES_OK) { - fprintf(stderr, _("%s: could not identify system: %s\n"), - progname, PQerrorMessage(conn)); + fprintf(stderr, + _("%s: could not send replication command \"%s\": %s"), + progname, "IDENTIFY_SYSTEM", PQerrorMessage(conn)); PQclear(res); return false; } if (PQnfields(res) != 3 || PQntuples(res) != 1) { - fprintf(stderr, _("%s: could not identify system, got %d rows and %d fields\n"), - progname, PQntuples(res), PQnfields(res)); + fprintf(stderr, + _("%s: could not identify system: got %d rows and %d fields, expected %d rows and %d fields\n"), + progname, PQntuples(res), PQnfields(res), 1, 3); PQclear(res); return false; } if (strcmp(sysidentifier, PQgetvalue(res, 0, 0)) != 0) { - fprintf(stderr, _("%s: system identifier does not match between base backup and streaming connection\n"), progname); + fprintf(stderr, + _("%s: system identifier does not match between base backup and streaming connection\n"), + progname); PQclear(res); return false; } if (timeline != atoi(PQgetvalue(res, 0, 1))) { - fprintf(stderr, _("%s: timeline does not match between base backup and streaming connection\n"), progname); + fprintf(stderr, + _("%s: timeline does not match between base backup and streaming connection\n"), + progname); PQclear(res); return false; } @@ -319,8 +337,8 @@ ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, char *sysi res = PQexec(conn, query); if (PQresultStatus(res) != PGRES_COPY_BOTH) { - fprintf(stderr, _("%s: could not start replication: %s\n"), - progname, PQresultErrorMessage(res)); + fprintf(stderr, _("%s: could not send replication command \"%s\": %s"), + progname, "START_REPLICATION", PQresultErrorMessage(res)); PQclear(res); return false; } @@ -348,7 +366,8 @@ ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, char *sysi */ if (stream_stop && stream_stop(blockpos, timeline, false)) { - if (walfile != -1 && !close_walfile(basedir, current_walfile_name, rename_partial)) + if (walfile != -1 && !close_walfile(basedir, current_walfile_name, + rename_partial)) /* Potential error message is written by close_walfile */ goto error; return true; @@ -364,8 +383,9 @@ ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, char *sysi { /* Time to send feedback! */ char replybuf[sizeof(StandbyReplyMessage) + 1]; - StandbyReplyMessage *replymsg = (StandbyReplyMessage *) (replybuf + 1); + StandbyReplyMessage *replymsg; + replymsg = (StandbyReplyMessage *) (replybuf + 1); replymsg->write = blockpos; replymsg->flush = InvalidXLogRecPtr; replymsg->apply = InvalidXLogRecPtr; @@ -433,7 +453,8 @@ ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, char *sysi /* Else there is actually data on the socket */ if (PQconsumeInput(conn) == 0) { - fprintf(stderr, _("%s: could not receive data from WAL stream: %s\n"), + fprintf(stderr, + _("%s: could not receive data from WAL stream: %s"), progname, PQerrorMessage(conn)); goto error; } @@ -444,7 +465,7 @@ ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, char *sysi break; if (r == -2) { - fprintf(stderr, _("%s: could not read copy data: %s\n"), + fprintf(stderr, _("%s: could not read COPY data: %s"), progname, PQerrorMessage(conn)); goto error; } @@ -456,7 +477,8 @@ ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, char *sysi */ if (r != STREAMING_KEEPALIVE_SIZE) { - fprintf(stderr, _("%s: keepalive message is incorrect size: %d\n"), + fprintf(stderr, + _("%s: keepalive message has incorrect size %d\n"), progname, r); goto error; } @@ -488,7 +510,8 @@ ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, char *sysi /* No file open yet */ if (xlogoff != 0) { - fprintf(stderr, _("%s: received xlog record for offset %u with no file open\n"), + fprintf(stderr, + _("%s: received transaction log record for offset %u with no file open\n"), progname, xlogoff); goto error; } @@ -499,7 +522,8 @@ ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, char *sysi /* XXX: store seek value don't reseek all the time */ if (lseek(walfile, 0, SEEK_CUR) != xlogoff) { - fprintf(stderr, _("%s: got WAL data offset %08x, expected %08x\n"), + fprintf(stderr, + _("%s: got WAL data offset %08x, expected %08x\n"), progname, xlogoff, (int) lseek(walfile, 0, SEEK_CUR)); goto error; } @@ -534,10 +558,9 @@ ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, char *sysi copybuf + STREAMING_HEADER_SIZE + bytes_written, bytes_to_write) != bytes_to_write) { - fprintf(stderr, _("%s: could not write %u bytes to WAL file %s: %s\n"), - progname, - bytes_to_write, - current_walfile_name, + fprintf(stderr, + _("%s: could not write %u bytes to WAL file \"%s\": %s\n"), + progname, bytes_to_write, current_walfile_name, strerror(errno)); goto error; } @@ -581,7 +604,8 @@ ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, char *sysi res = PQgetResult(conn); if (PQresultStatus(res) != PGRES_COMMAND_OK) { - fprintf(stderr, _("%s: unexpected termination of replication stream: %s\n"), + fprintf(stderr, + _("%s: unexpected termination of replication stream: %s"), progname, PQresultErrorMessage(res)); goto error; } |