[#35444] YSQL: Deliver a transaction's notifications in send order after pg_yb_notifications splits #38189
All Vouch review confidence checks passed
Residual risk 0.18 = Change Risk (0.46) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.46 · 463 lines diff across 5 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.367
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #38189"
general
weight: 0.35
arpang
Summary
Problem: at commit, the backend writes all of a transaction's notifications to
pg_yb_notificationsas one buffered batch, so the batch's rows reach their tablets in parallel. Each tablet stamps its rows with its own hybrid time, and the virtual WAL orders a transaction's rows by that time, using write order only to break ties within a tablet. With one tablet, all rows share a hybrid time and write order keeps them in send order. Once the table splits, rows on different tablets get unrelated times, so listeners can receive a transaction's notifications out of the order they were sent in.Fix: record each notification's send position, and restore that order in the poller.
ybInsertPendingNotifiesToTablestores the position as{"seq": i}in the previously unusedextra_optionscolumn. Using an existing column needs no schema change topg_yb_notifications, and so no upgrade step.seqbefore writing them to the queue. The sort is deterministic, so a transaction replayed after a poller crash is queued in the same order, and the listeners' duplicate-skipping still works.seqonly when it is a non-negative int32 inside a JSON object, and falls back to arrival order otherwise.seq, which keeps each sender's notifications together, in the virtual WAL's order. Without it, the sort byseqwould interleave them, where today they are contiguous.New test-only gflag
TEST_cdcsdk_vwal_round_up_commit_time_usecrounds the virtual WAL's commit times of transaction records up to a window, so that a test can make transactions commit at the same time.Upgrade/Rollback safety
No schema change and no AutoFlag.
seq, so the poller keeps arrival order, as today.extra_options, as today.Rollback leaves the second case.
Test plan
org.yb.pgsql.TestPgListenNotify#testNotifyOrderAfterNotificationsTableSplit: splitspg_yb_notificationsinto two tablets, then sends 200 notifications three ways (one statement in a transaction block, 200NOTIFYstatements in a transaction block, one autocommit statement) and asserts in-order delivery. It fails without the fix (each tablet's rows arrive as a group) and passes with it.org.yb.pgsql.TestPgListenNotify#testListenNotifyNoDuplicateAfterPollerCrashBeforeAckorg.yb.pgsql.TestPgListenNotify#testLargeNumberOfNotifiesInTransactionorg.yb.pgsql.TestPgListenNotify#testPollerToleratesMalformedExtraOptions: inserts rows with malformedextra_optionsvalues through SQL and checks that a later NOTIFY is still delivered. Without the hardening, a debug build failsJsonContainerIsObjectin the poller.org.yb.pgsql.TestPgListenNotify#testNotifyOrderOfTransactionsWithSameCommitTime: two transactions send 50 notifications each and commit inside one window of the gflag above, in DocDB transaction id order as a real collision streams them. Asserts that each transaction's notifications are delivered together and in send order. Passed 4/4 with the fix; fails without the transaction id sort (notifications interleave). Not rerun since the test started waiting for the window to end before turning the gflag off.