mirror of
https://github.com/postgres/postgres.git
synced 2025-08-05 07:41:25 +03:00
Fix CheckPointReplicationSlots() with max_replication_slots == 0
ca307d5cec
made CheckPointReplicationSlots() unconditionally call
ReplicationSlotsComputeRequiredLSN(). It causes an assertion trap when
max_replication_slots equals 0. This commit makes
CheckPointReplicationSlots() call ReplicationSlotsComputeRequiredLSN() only
when at least one slot gets its last_saved_restart_lsn updated. That avoids
an assert trap and also saves some cycles when no one slot has
last_saved_restart_lsn updated.
Based on ideas from Dilip Kumar <dilipbalaut@gmail.com> and
Hayato Kuroda <kuroda.hayato@fujitsu.com>.
Reported-by: Zhijie Hou <houzj.fnst@fujitsu.com>
Discussion: https://postgr.es/m/OS0PR01MB5716BB506AF934376FF3A8BB947BA%40OS0PR01MB5716.jpnprd01.prod.outlook.com
This commit is contained in:
@@ -2079,6 +2079,7 @@ void
|
|||||||
CheckPointReplicationSlots(bool is_shutdown)
|
CheckPointReplicationSlots(bool is_shutdown)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
bool last_saved_restart_lsn_updated = false;
|
||||||
|
|
||||||
elog(DEBUG1, "performing replication slot checkpoint");
|
elog(DEBUG1, "performing replication slot checkpoint");
|
||||||
|
|
||||||
@@ -2123,14 +2124,22 @@ CheckPointReplicationSlots(bool is_shutdown)
|
|||||||
SpinLockRelease(&s->mutex);
|
SpinLockRelease(&s->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Track if we're going to update slot's last_saved_restart_lsn. We
|
||||||
|
* need this to know if we need to recompute the required LSN.
|
||||||
|
*/
|
||||||
|
if (s->last_saved_restart_lsn != s->data.restart_lsn)
|
||||||
|
last_saved_restart_lsn_updated = true;
|
||||||
|
|
||||||
SaveSlotToPath(s, path, LOG);
|
SaveSlotToPath(s, path, LOG);
|
||||||
}
|
}
|
||||||
LWLockRelease(ReplicationSlotAllocationLock);
|
LWLockRelease(ReplicationSlotAllocationLock);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Recompute the required LSN as SaveSlotToPath() updated
|
* Recompute the required LSN if SaveSlotToPath() updated
|
||||||
* last_saved_restart_lsn for slots.
|
* last_saved_restart_lsn for any slot.
|
||||||
*/
|
*/
|
||||||
|
if (last_saved_restart_lsn_updated)
|
||||||
ReplicationSlotsComputeRequiredLSN();
|
ReplicationSlotsComputeRequiredLSN();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user