mirror of
https://github.com/postgres/postgres.git
synced 2025-11-10 17:42:29 +03:00
Report catalog_xmin separately in hot_standby_feedback
If the upstream walsender is using a physical replication slot, store the catalog_xmin in the slot's catalog_xmin field. If the upstream doesn't use a slot and has only a PGPROC entry behaviour doesn't change, as we store the combined xmin and catalog_xmin in the PGPROC entry. Author: Craig Ringer
This commit is contained in:
@@ -1175,8 +1175,8 @@ XLogWalRcvSendHSFeedback(bool immed)
|
||||
{
|
||||
TimestampTz now;
|
||||
TransactionId nextXid;
|
||||
uint32 nextEpoch;
|
||||
TransactionId xmin;
|
||||
uint32 xmin_epoch, catalog_xmin_epoch;
|
||||
TransactionId xmin, catalog_xmin;
|
||||
static TimestampTz sendTime = 0;
|
||||
/* initially true so we always send at least one feedback message */
|
||||
static bool master_has_standby_xmin = true;
|
||||
@@ -1221,29 +1221,54 @@ XLogWalRcvSendHSFeedback(bool immed)
|
||||
* everything else has been checked.
|
||||
*/
|
||||
if (hot_standby_feedback)
|
||||
xmin = GetOldestXmin(NULL, PROCARRAY_FLAGS_DEFAULT);
|
||||
{
|
||||
TransactionId slot_xmin;
|
||||
|
||||
/*
|
||||
* Usually GetOldestXmin() would include both global replication slot
|
||||
* xmin and catalog_xmin in its calculations, but we want to derive
|
||||
* separate values for each of those. So we ask for an xmin that
|
||||
* excludes the catalog_xmin.
|
||||
*/
|
||||
xmin = GetOldestXmin(NULL,
|
||||
PROCARRAY_FLAGS_DEFAULT|PROCARRAY_SLOTS_XMIN);
|
||||
|
||||
ProcArrayGetReplicationSlotXmin(&slot_xmin, &catalog_xmin);
|
||||
|
||||
if (TransactionIdIsValid(slot_xmin) &&
|
||||
TransactionIdPrecedes(slot_xmin, xmin))
|
||||
xmin = slot_xmin;
|
||||
}
|
||||
else
|
||||
{
|
||||
xmin = InvalidTransactionId;
|
||||
catalog_xmin = InvalidTransactionId;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get epoch and adjust if nextXid and oldestXmin are different sides of
|
||||
* the epoch boundary.
|
||||
*/
|
||||
GetNextXidAndEpoch(&nextXid, &nextEpoch);
|
||||
GetNextXidAndEpoch(&nextXid, &xmin_epoch);
|
||||
catalog_xmin_epoch = xmin_epoch;
|
||||
if (nextXid < xmin)
|
||||
nextEpoch--;
|
||||
xmin_epoch --;
|
||||
if (nextXid < catalog_xmin)
|
||||
catalog_xmin_epoch --;
|
||||
|
||||
elog(DEBUG2, "sending hot standby feedback xmin %u epoch %u",
|
||||
xmin, nextEpoch);
|
||||
elog(DEBUG2, "sending hot standby feedback xmin %u epoch %u catalog_xmin %u catalog_xmin_epoch %u",
|
||||
xmin, xmin_epoch, catalog_xmin, catalog_xmin_epoch);
|
||||
|
||||
/* Construct the message and send it. */
|
||||
resetStringInfo(&reply_message);
|
||||
pq_sendbyte(&reply_message, 'h');
|
||||
pq_sendint64(&reply_message, GetCurrentTimestamp());
|
||||
pq_sendint(&reply_message, xmin, 4);
|
||||
pq_sendint(&reply_message, nextEpoch, 4);
|
||||
pq_sendint(&reply_message, xmin_epoch, 4);
|
||||
pq_sendint(&reply_message, catalog_xmin, 4);
|
||||
pq_sendint(&reply_message, catalog_xmin_epoch, 4);
|
||||
walrcv_send(wrconn, reply_message.data, reply_message.len);
|
||||
if (TransactionIdIsValid(xmin))
|
||||
if (TransactionIdIsValid(xmin) || TransactionIdIsValid(catalog_xmin))
|
||||
master_has_standby_xmin = true;
|
||||
else
|
||||
master_has_standby_xmin = false;
|
||||
|
||||
Reference in New Issue
Block a user