← Back to Pull requests

[#35444] YSQL: Deliver a transaction's notifications in send order after pg_yb_notifications splits #38189

Closed
unknown closed this pull request without merging on Nov 22, 2026 06:27 UTC
View on GitHub
unknown unknown commented on Nov 17, 2026 10:42 UTC
Author

Summary

Problem: at commit, the backend writes all of a transaction's notifications to pg_yb_notifications as 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.

  • ybInsertPendingNotifiesToTable stores the position as {"seq": i} in the previously unused extra_options column. Using an existing column needs no schema change to pg_yb_notifications, and so no upgrade step.

  • The notifications poller already buffers a whole transaction until COMMIT. It now sorts the buffered entries by seq before 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.

  • The table also takes plain SQL writes, so the poller uses seq only when it is a non-negative int32 inside a JSON object, and falls back to arrival order otherwise.

  • The virtual WAL streams DocDB transactions that commit at the same hybrid time as one transaction (possible across tservers' independent clocks), so one batch can hold several senders' rows, each numbered from 0. The poller sorts by DocDB transaction id first, then seq, which keeps each sender's notifications together, in the virtual WAL's order. Without it, the sort by seq would interleave them, where today they are contiguous.
  • New test-only gflag TEST_cdcsdk_vwal_round_up_commit_time_usec rounds 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.

  • Old writer, new poller: rows have no seq, so the poller keeps arrival order, as today.

  • New writer, old poller: the old poller ignores extra_options, as today.
  • Rollback leaves the second case.

    Test plan

  • New org.yb.pgsql.TestPgListenNotify#testNotifyOrderAfterNotificationsTableSplit: splits pg_yb_notifications into two tablets, then sends 200 notifications three ways (one statement in a transaction block, 200 NOTIFY statements 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#testListenNotifyNoDuplicateAfterPollerCrashBeforeAck

  • org.yb.pgsql.TestPgListenNotify#testLargeNumberOfNotifiesInTransaction

  • New org.yb.pgsql.TestPgListenNotify#testPollerToleratesMalformedExtraOptions: inserts rows with malformed extra_options values through SQL and checks that a later NOTIFY is still delivered. Without the hardening, a debug build fails JsonContainerIsObject in the poller.

  • New 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.
  • Diff: 463 lines (+347 / -116) across 5 files Reviewer: arpang Review duration: 6945m
    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
    0.46
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.6% (MEDIUM) · Higher = larger blast radius
    45.6%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 18% · Safe to merge
    18%