Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7195c80

Browse files
committed
Fix CheckPointReplicationSlots() with max_replication_slots == 0
ca307d5 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 <[email protected]> and Hayato Kuroda <[email protected]>. Reported-by: Zhijie Hou <[email protected]> Discussion: https://postgr.es/m/OS0PR01MB5716BB506AF934376FF3A8BB947BA%40OS0PR01MB5716.jpnprd01.prod.outlook.com
1 parent 94e2e15 commit 7195c80

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/backend/replication/slot.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2079,6 +2079,7 @@ void
20792079
CheckPointReplicationSlots(bool is_shutdown)
20802080
{
20812081
int i;
2082+
bool last_saved_restart_lsn_updated = false;
20822083

20832084
elog(DEBUG1, "performing replication slot checkpoint");
20842085

@@ -2123,15 +2124,23 @@ CheckPointReplicationSlots(bool is_shutdown)
21232124
SpinLockRelease(&s->mutex);
21242125
}
21252126

2127+
/*
2128+
* Track if we're going to update slot's last_saved_restart_lsn. We
2129+
* need this to know if we need to recompute the required LSN.
2130+
*/
2131+
if (s->last_saved_restart_lsn != s->data.restart_lsn)
2132+
last_saved_restart_lsn_updated = true;
2133+
21262134
SaveSlotToPath(s, path, LOG);
21272135
}
21282136
LWLockRelease(ReplicationSlotAllocationLock);
21292137

21302138
/*
2131-
* Recompute the required LSN as SaveSlotToPath() updated
2132-
* last_saved_restart_lsn for slots.
2139+
* Recompute the required LSN if SaveSlotToPath() updated
2140+
* last_saved_restart_lsn for any slot.
21332141
*/
2134-
ReplicationSlotsComputeRequiredLSN();
2142+
if (last_saved_restart_lsn_updated)
2143+
ReplicationSlotsComputeRequiredLSN();
21352144
}
21362145

21372146
/*

0 commit comments

Comments
 (0)