Repository navigation
Let a logical slot hold the coordinator's WAL - #2450
Conversation
|
Thats some sort of tech solution which doesn't look promising to me. Making Cloudberry retain more files on FS just for logical decoding is something that may become fragile to support. My proposal is to take https://www.postgresql.org/message-id/EC645E05-27FD-4394-91F1-60B4F58DCE3E%40yandex-team.ru and enable for logical replication too (would be 1 if statement). So, server would simply fetch WAL from archive on purposes of decoding it. WHYT? |
Fair concern, but I think the scope here is narrower than it looks. On the coordinator KeepLogSeg() never looks at logical slots at all — it ends up at segno = currSegNo, so WAL gets recycled whether or not a consumer is behind, and max_slot_wal_keep_size has nothing to cap. This patch doesn't ask for unbounded retention; it just puts the slot into the calculation so the coordinator behaves like the segments do, that GUC included. Re wal_sender_restore: I'd like to see it land. But it works by letting a physical receiver survive without a slot pinning WAL, and logical has no such option — the protocol needs the slot, and by the time a slot is invalidated the catalog rows its catalog_xmin held back are already vacuumed, so getting the WAL back from an archive doesn't get you decoding back. Different problem, not a competing fix. |
WAL retention on a coordinator does not follow replication slots. It follows what the connected walsenders have confirmed, because the coordinator's standby is fed by a bare walsender with no slot behind it, and a slot minimum of "nothing" would have left that standby unprotected. The comment on it says as much: replication slot is not created there. One is now. A logical slot is a promise written to disk precisely so that it outlives the connection, and the subscriber it belongs to is expected to be away sometimes -- disabled, its target down, restarting after an error. The walsender bookkeeping exists only while somebody is connected, so during every one of those gaps the coordinator had no reason to keep any WAL at all: it recycled, and the next checkpoint then invalidated the slot of every subscription that happened not to be running. The segments never had this, which made it look stranger than it was -- the same subscription, the same slot name, dead on the coordinator and healthy on all three segments. Consult both and keep the earlier. Only logical slots join in: the coordinator's physical replication has never been driven by slots and this is not the place to change that, and ReplicationSlotsComputeLogicalRestartLSN() already leaves out slots that have been invalidated, so a dead one cannot pin WAL for ever. Where there are no logical slots it answers InvalidXLogRecPtr and nothing about this changes. That last part is why the two cannot simply be Min()ed: InvalidXLogRecPtr means "nothing to say" here, and it is zero, so Min() would read an abstention as the strictest possible answer and keep no WAL at all -- which is exactly the case this is about. The cap this brings into play is max_slot_wal_keep_size, which until now could not do anything on a coordinator, because it caps a keep point computed from slots and no such point was ever computed. A publisher that would rather drop a subscriber than grow its WAL can now say so there too.
a099220 to
28ce598
Compare
What does this PR do?
Lets a logical replication slot hold WAL on the coordinator.
KeepLogSeg()has two ways of deciding how far back WAL must be kept, and thecoordinator used only one of them:
The comment above it explains why — "coordinator needs a different way to
determine the keep point as replication slot is not created there". The
coordinator's standby is fed by a bare walsender with no slot behind it, so a
slot minimum of "nothing" would have left that standby unprotected.
Something does create a slot there now. A logical slot is a promise written
to disk precisely so that it outlives the connection, and the subscriber it
belongs to is expected to be away sometimes: disabled, its target down,
restarting after an error. The walsender bookkeeping exists only while somebody
is connected, so during every one of those gaps the coordinator had no reason
to keep any WAL at all. It recycled, and the next checkpoint then invalidated
the slot of every subscription that happened not to be running.
The segments never had this, which made it look stranger than it was: the same
subscription, the same slot name, dead on the coordinator and healthy on all
three segments.
What it does instead
Consult both and keep the earlier. Only logical slots join in —
ReplicationSlotsComputeLogicalRestartLSN(), not the general slot minimum:this is not the place to change that;
one cannot pin WAL for ever;
InvalidXLogRecPtrand nothingabout the existing behaviour changes.
Why the two are not simply
Min()ed.InvalidXLogRecPtrmeans "nothing tosay" here, and it is zero — so
Min()would read an abstention as thestrictest possible answer and keep no WAL at all, which is exactly the case
this is about. Each is tested for validity and the earliest of those that
answered wins.
Side effect worth knowing
This brings
max_slot_wal_keep_sizeinto play on a coordinator, where until nowit could do nothing: it caps a keep point computed from slots, and no such point
was ever computed there. A publisher that would rather drop a subscriber than
grow its WAL can now say so on the coordinator too.
Type of Change
Breaking Changes
None. Where no logical slot exists on the coordinator — which is every cluster
that is not a logical replication source — the computed keep point is unchanged,
because
ReplicationSlotsComputeLogicalRestartLSN()returnsInvalidXLogRecPtrand the walsender answer is taken as before. Physical replication and the
coordinator's standby are untouched.
Test Plan
main(xlog.o, no warnings)3-segment cluster, its consumer stopped, then WAL generated and
checkpoints forced. Before: the slot is invalidated at the next
checkpoint while the segments' slots of the same name survive. After:
it is retained, and
max_slot_wal_keep_sizebounds how far that goes.make installcheckmake -C src/test installcheck-cbdb-parallelA regression test for this needs a coordinator logical slot plus checkpoint
control plus a wait for invalidation; I have not written one, and would rather
say so than imply coverage that is not there.
Impact
Performance: one extra shared-memory read per
KeepLogSeg()call on thecoordinator, i.e. per checkpoint.
User-facing changes: a logical slot on the coordinator survives its
subscriber being away.
max_slot_wal_keep_sizestarts applying there.Dependencies: none.
Checklist