[BACKPORT 2025.2][#35386] YSQL: Fix lost notifications after the only listener on a node re-LISTENs (#35400) #37124
All Vouch review confidence checks passed
Residual risk 0.12 = Change Risk (0.35) × (1 − Review Confidence (0.66)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.35 · 151 lines diff across 2 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.54 · 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.301
Real PR Conversation Timeline
4 items
<!-- Reviewable:start -->
This change is <img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>
<!-- Reviewable:end -->
Approved
Approved these changes.
Approved
Approved these changes.
arpang
dhruva4869
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
ybListenerQueueScanCurrentXactStatetoskip 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 andis kept across a poller's crash restarts.
poller_idit was built under.Exec_ListenPreCommitresets the state when the backend registers undera different poller, whether this backend recreated the slot or another
one did.
the state is kept, so a crash replay of a transaction the backend
already received is still skipped.
count left over from one transaction cannot drop notifications from the
next.
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.Original commit: 08068000a6f11f47ef91de2ca9a0b3542db5b947 / #35400
Test plan
testNotifyAfterSoloListenerRelistens. Without the fix it fails3/3 with
expected:<[n2a, n2b, n3]> but was:<[n3]>, and the listenerlogs
Listener found duplicate txn BEGIN entry in async queue (xid 2),.skipping 2 notifications
testNotifyAfterRelistenOnSlotRecreatedByAnotherListenertestNoDuplicateAfterRelistenWithSamePollertestListenNotifyNoDuplicateAfterPollerCrashBeforeAck(existingreplay test)
Checked items were run on a debug build on macOS arm64, against an
earlier revision of this PR.
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>