Fix bug with slot for former leader not retained on failover (#3261)

the problem existed because _build_retain_slots() method was falsely relying on members being present in DCS, while on failover the member key for the former leader is expiring exactly at the same time.
This commit is contained in:
Alexander Kukushkin
2025-02-04 13:39:19 +01:00
committed by GitHub
parent 302757b71a
commit 0bb12473fb
5 changed files with 25 additions and 10 deletions
+3 -1
View File
@@ -81,4 +81,6 @@ Feature: permanent slots
When I start postgres-0
Then postgres-0 role is the replica after 20 seconds
And physical replication slot named postgres_1 on postgres-0 has no xmin value after 10 seconds
And physical replication slot named postgres_2 on postgres-0 has no xmin value after 10 seconds
# postgres_2 and postgres_3 slots are retained, but postgres_2 will still have xmin value :(
And postgres-0 has a physical replication slot named postgres_2 after 10 seconds
And postgres-0 has a physical replication slot named postgres_3 after 10 seconds
+2 -2
View File
@@ -99,8 +99,8 @@ def has_physical_replication_slot(context, pg_name, slot_name, time_limit):
def physical_slot_no_xmin(context, pg_name, slot_name, time_limit):
time_limit *= context.timeout_multiplier
max_time = time.time() + int(time_limit)
query = "SELECT xmin FROM pg_catalog.pg_replication_slots WHERE slot_type = 'physical'"
f" AND slot_name = '{slot_name}'"
query = "SELECT xmin FROM pg_catalog.pg_replication_slots WHERE slot_type = 'physical'" +\
f" AND slot_name = '{slot_name}'"
exists = False
while time.time() < max_time:
try: