[#35386] YSQL: Fix lost notifications after the only listener on a node re-LISTENs #35400
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.42) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.42 · 351 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.351
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #35400"
general
weight: 0.35
arpang
Summary
When the only listener on a node UNLISTENs and the same backend LISTENs again, the notifications of the next transaction are lost.
Each listening backend keeps
ybListenerQueueScanCurrentXactStateto skip queue entries that the notifications poller writes twice when it replays an unacknowledged transaction. A BEGIN marker with the same xid as the previous one is treated as a replay. These xids come from the notifications slot's virtual WAL, so they are only unique within one slot and cannot be compared across slots: numbering restarts every time the slot is created, which happens when a node gets its first listener after the last one left. The state was never reset, so the first transaction on a new slot could match the last transaction the backend saw on the old slot (in the issue's repro both are xid 2), and its notifications were skipped as duplicates.The fix ties the state to the slot its xids came from, identified by the existing
poller_id: it changes exactly when the slot is recreated and is kept across a poller's crash restarts.poller_idit was built under.Exec_ListenPreCommitresets the state when the backend registers under a different poller, whether this backend recreated the slot or another one did.The other way to get the same false duplicate, an old poller writing to the queue after a new listener registered, is already prevented by the existing
poller_idcheck on the queue write path.Test plan
testNotifyAfterSoloListenerRelistens. Without the fix it fails 3/3 withexpected:<[n2a, n2b, n3]> but was:<[n3]>, and the listener logsListener found duplicate txn BEGIN entry in async queue (xid 2), skipping 2 notifications.testNotifyAfterRelistenOnSlotRecreatedByAnotherListenertestNoDuplicateAfterRelistenWithSamePollertestListenNotifyNoDuplicateAfterPollerCrashBeforeAck(existing replay test)Checked items were run on a debug build on macOS arm64, against an earlier revision of this PR.