mirror of
https://github.com/postgres/postgres.git
synced 2025-05-02 11:44:50 +03:00
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.
This commit is contained in:
parent
db49517c62
commit
6b020d228b
@ -33,8 +33,9 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
|
||||||
/* Size of the streaming replication protocol header */
|
/* Size of the streaming replication protocol headers */
|
||||||
#define STREAMING_HEADER_SIZE (1+8+8+8)
|
#define STREAMING_HEADER_SIZE (1+sizeof(WalDataMessageHeader))
|
||||||
|
#define STREAMING_KEEPALIVE_SIZE (1+sizeof(PrimaryKeepaliveMessage))
|
||||||
|
|
||||||
const XLogRecPtr InvalidXLogRecPtr = {0, 0};
|
const XLogRecPtr InvalidXLogRecPtr = {0, 0};
|
||||||
|
|
||||||
@ -374,18 +375,33 @@ ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, char *sysi
|
|||||||
progname, PQerrorMessage(conn));
|
progname, PQerrorMessage(conn));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (copybuf[0] == 'k')
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* keepalive message, sent in 9.2 and newer. We just ignore
|
||||||
|
* this message completely, but need to forward past it
|
||||||
|
* in our reading.
|
||||||
|
*/
|
||||||
|
if (r != STREAMING_KEEPALIVE_SIZE)
|
||||||
|
{
|
||||||
|
fprintf(stderr, _("%s: keepalive message is incorrect size: %i\n"),
|
||||||
|
progname, r);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if (copybuf[0] != 'w')
|
||||||
|
{
|
||||||
|
fprintf(stderr, _("%s: unrecognized streaming header: \"%c\"\n"),
|
||||||
|
progname, copybuf[0]);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (r < STREAMING_HEADER_SIZE + 1)
|
if (r < STREAMING_HEADER_SIZE + 1)
|
||||||
{
|
{
|
||||||
fprintf(stderr, _("%s: streaming header too small: %i\n"),
|
fprintf(stderr, _("%s: streaming header too small: %i\n"),
|
||||||
progname, r);
|
progname, r);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (copybuf[0] != 'w')
|
|
||||||
{
|
|
||||||
fprintf(stderr, _("%s: unrecognized streaming header: \"%c\"\n"),
|
|
||||||
progname, copybuf[0]);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Extract WAL location for this block */
|
/* Extract WAL location for this block */
|
||||||
memcpy(&blockpos, copybuf + 1, 8);
|
memcpy(&blockpos, copybuf + 1, 8);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user