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

Commit 99709c9

Browse files
committed
Refactor one use of IDENTIFY_SYSTEM in WAL streaming code of pg_basebackup
0c013e0 has done a large refactoring to unify all the code paths using replication commands, but forgot one code path doing WAL streaming that checks the validity of a cluster connecting to with IDENTIFY_SYSTEM. There is a generic routine able to handle that, so make use of it in this code path. This impacts pg_receivewal and pg_basebackup. Author: Bharath Rupireddy Discussion: https://postgr.es/m/CALj2ACVKKYUMC8GE72Y7BP9g1batrrq3sEwUh+1_i2krWZC_2Q@mail.gmail.com
1 parent 961dd75 commit 99709c9

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

src/bin/pg_basebackup/receivelog.c

+14-18
Original file line numberDiff line numberDiff line change
@@ -482,36 +482,32 @@ ReceiveXlogStream(PGconn *conn, StreamCtl *stream)
482482

483483
if (stream->sysidentifier != NULL)
484484
{
485-
/* Validate system identifier hasn't changed */
486-
res = PQexec(conn, "IDENTIFY_SYSTEM");
487-
if (PQresultStatus(res) != PGRES_TUPLES_OK)
488-
{
489-
pg_log_error("could not send replication command \"%s\": %s",
490-
"IDENTIFY_SYSTEM", PQerrorMessage(conn));
491-
PQclear(res);
492-
return false;
493-
}
494-
if (PQntuples(res) != 1 || PQnfields(res) < 3)
485+
char *sysidentifier = NULL;
486+
TimeLineID servertli;
487+
488+
/*
489+
* Get the server system identifier and timeline, and validate them.
490+
*/
491+
if (!RunIdentifySystem(conn, &sysidentifier, &servertli, NULL, NULL))
495492
{
496-
pg_log_error("could not identify system: got %d rows and %d fields, expected %d rows and %d or more fields",
497-
PQntuples(res), PQnfields(res), 1, 3);
498-
PQclear(res);
493+
pg_free(sysidentifier);
499494
return false;
500495
}
501-
if (strcmp(stream->sysidentifier, PQgetvalue(res, 0, 0)) != 0)
496+
497+
if (strcmp(stream->sysidentifier, sysidentifier) != 0)
502498
{
503499
pg_log_error("system identifier does not match between base backup and streaming connection");
504-
PQclear(res);
500+
pg_free(sysidentifier);
505501
return false;
506502
}
507-
if (stream->timeline > atoi(PQgetvalue(res, 0, 1)))
503+
pg_free(sysidentifier);
504+
505+
if (stream->timeline > servertli)
508506
{
509507
pg_log_error("starting timeline %u is not present in the server",
510508
stream->timeline);
511-
PQclear(res);
512509
return false;
513510
}
514-
PQclear(res);
515511
}
516512

517513
/*

0 commit comments

Comments
 (0)