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

Commit 6b020d2

Browse files
committed
Fix pg_basebackup for keepalive messages
Teach pg_basebackup in streaming mode to deal with keepalive messages. Also change the order of checks to complain at the message rather than block size when a new message is introduced. In passing, switch to using sizeof() instead of hardcoded sizes for WAL protocol structs.
1 parent db49517 commit 6b020d2

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

src/bin/pg_basebackup/receivelog.c

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@
3333
#include <unistd.h>
3434

3535

36-
/* Size of the streaming replication protocol header */
37-
#define STREAMING_HEADER_SIZE (1+8+8+8)
36+
/* Size of the streaming replication protocol headers */
37+
#define STREAMING_HEADER_SIZE (1+sizeof(WalDataMessageHeader))
38+
#define STREAMING_KEEPALIVE_SIZE (1+sizeof(PrimaryKeepaliveMessage))
3839

3940
const XLogRecPtr InvalidXLogRecPtr = {0, 0};
4041

@@ -374,18 +375,33 @@ ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, char *sysi
374375
progname, PQerrorMessage(conn));
375376
return false;
376377
}
377-
if (r < STREAMING_HEADER_SIZE + 1)
378+
if (copybuf[0] == 'k')
378379
{
379-
fprintf(stderr, _("%s: streaming header too small: %i\n"),
380-
progname, r);
381-
return false;
380+
/*
381+
* keepalive message, sent in 9.2 and newer. We just ignore
382+
* this message completely, but need to forward past it
383+
* in our reading.
384+
*/
385+
if (r != STREAMING_KEEPALIVE_SIZE)
386+
{
387+
fprintf(stderr, _("%s: keepalive message is incorrect size: %i\n"),
388+
progname, r);
389+
return false;
390+
}
391+
continue;
382392
}
383-
if (copybuf[0] != 'w')
393+
else if (copybuf[0] != 'w')
384394
{
385395
fprintf(stderr, _("%s: unrecognized streaming header: \"%c\"\n"),
386396
progname, copybuf[0]);
387397
return false;
388398
}
399+
if (r < STREAMING_HEADER_SIZE + 1)
400+
{
401+
fprintf(stderr, _("%s: streaming header too small: %i\n"),
402+
progname, r);
403+
return false;
404+
}
389405

390406
/* Extract WAL location for this block */
391407
memcpy(&blockpos, copybuf + 1, 8);

0 commit comments

Comments
 (0)