Skip to content

[4.2-dev] Backport #26616 table_changes to 4.2-dev - #32849

Open
jiangxinmeng1 wants to merge 41 commits into
matrixorigin:4.2-devfrom
jiangxinmeng1:backport/pr-26616-4.2-dev
Open

jiangxinmeng1 wants to merge 41 commits into
matrixorigin:4.2-devfrom
jiangxinmeng1:backport/pr-26616-4.2-dev

Conversation

@jiangxinmeng1

@jiangxinmeng1 jiangxinmeng1 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Backport #26616 to 4.2-dev for #26615. Consumers can use change_watermark() to choose a transaction boundary and table_changes() to read the net changes for each primary key in (after, until]. An empty after bootstraps the consumer with rows visible at until.

Replay and resource use on 4.2

  • Incremental replay reads original row and delete events within retained history. Compaction can retire a tombstone while unrelated objects are created nearby. Those objects cannot establish what was deleted. If retention no longer covers the start, the query asks the caller to rebuild from a fresh snapshot. A missing source file tells the caller to discard partial output and retry the same watermarks.
  • Bootstrap reads the objects visible at the requested end, plus visible in-memory rows. Both paths use the same per-key reduction. The existing unbounded DATA BRANCH consumer keeps its snapshot recovery path.
  • Small polls sort and reduce in memory. When the working set exceeds the in-memory window, replay uses the existing query spill budget and releases reservations on failure or cancellation. Persisted columns use the released 4.2 layout. The backport needs no new storage codec or cluster protocol gate.

Validation

  • Compared the previous implementation with regression tests for history GC, compaction next to an unrelated object, missing original data, and a single-row poll with no spill storage.
  • Ran the two-CN pessimistic SQL suites on the rebased binary. All 202 table_changes statements and all 141 DATA BRANCH statements passed, including an insert and a delete flushed separately and read at three different boundaries.
  • Used the official Linux x86-64 v4.2.9 release to write and flush a table with inserts, an update and a deletion. Stopped the service, restarted the candidate on the same data directory, and verified the complete snapshot, a subsequent flushed incremental delete and insert, and the resulting snapshot.
  • Built mo-service. Eleven affected packages passed their full unit tests. ObjectIO, logtail replay and disttae also passed with the race detector. Incremental static analysis reported zero issues in the checked packages.

(cherry picked from commit ed4a810a539d8b7feae95711d37e7d7d9449d89f)

- [ ] API-change
- [ ] BUG
- [ ] Improvement
- [ ] Documentation
- [x] Feature
- [ ] Test and CI
- [ ] Code Refactoring

issue matrixorigin#26615

Agent/catalog incremental discovery

---------

Co-authored-by: gouhongshen <[email protected]>
Co-authored-by: XuPeng-SH <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit ed4a810)
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@mergify

mergify Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request

…6-4.2-dev

# Conflicts:
#	pkg/vm/engine/change_handle_pk_filter.go
#	pkg/vm/engine/disttae/logtailreplay/change_handle.go
@jiangxinmeng1

Copy link
Copy Markdown
Contributor Author

@XuPeng-SH The overlapping-chunk spill finding in your review of 8126a92 is addressed by f1bafa9: bounded windows process and release each chunk before loading the next one. TestChunkedColumnRoundTripAndRangedRead checks an overlapping two-chunk window with zero spill reservations. The earlier spill cleanup and duplicate-read findings also have focused regression tests. Please re-review the current head when convenient. I have merged the latest 4.2-dev and am working through the separate changed-line coverage failure.

@XuPeng-SH

XuPeng-SH commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · superseded

Commit: 03778cc9bbc60faef7d37ffd5539918e851390df

PR closed or head changed

@XuPeng-SH

XuPeng-SH commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: a2e778bece54b7d7466862fecf0f67b08c0b3a45

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: a2e778bece54b7d7466862fecf0f67b08c0b3a45

Assessment: request_changes

Bounded table_changes replay can return incorrect change streams after partition-state GC or object compaction, and it requires spill admission even for a single in-memory row. The backport also adds an optional persisted-format writer and mixed-version gate that conflict with the pinned 4.2 maintenance policy. The earlier spill-cleanup, window-sizing, duplicate-read and overlapping-chunk concerns are resolved; the new replay counterexamples invalidate the earlier no-blocker assessment. Reusing the existing replay and spill-budget owners is appropriate, but their bounded integration needs these corrections.

Model: gpt-6.1-terra / max

Session: 01a2319b-6eff-73c0-b59b-ebce3800e538 · slot 2 · generation 16

  • P1 pkg/vm/engine/disttae/change_handle.go:445: A nonempty lower watermark predates the live partition state's retained history, for example after a consumer has been stopped longer than the one-hour partition-state retention period.
    Impact: The query can succeed while omitting deletes, so a consumer that advances its watermark retains stale downstream rows.
    Evidence: The new bounded branch always builds from the end snapshot, bypassing the existing checkpoint-splitting path. The range constructor logs and proceeds when stateStart exceeds start, although partition GC removes retired tombstone entries. The retained retention-valid-test.log probe returned a delete at timestamp 100 for (50,120], then returned no rows and no error for (50,200] after GC at 160. Reconstruct the missing nonempty range through a complete supported history source, or return a stale-range error when completeness cannot be established; handle the empty initial watermark separately.

  • P2 pkg/vm/engine/disttae/change_handle.go:641: A bounded range includes an object retired by compaction and an unrelated TN object created later in the same table.
    Impact: The change stream can emit a delete for a key that did not exist at the lower watermark, causing consumers to process a spurious change event.
    Evidence: The newly normal bounded SQL path invokes the existing delete-chain resolver, which treats the earliest later TN creation timestamp as a successor without establishing lineage. In fuzzy-test.log, an insert at 100 followed by a delete at 120 correctly cancels while its object remains visible; after that object is retired at 150, an unrelated object created at 160 is selected as its successor and the same range incorrectly emits the delete. The timestamp heuristic predates this PR, but this change makes it the ordinary bounded table_changes path. Read a complete historical source or require verified successor lineage and fail or recover when it is unavailable.

  • P2 pkg/vm/engine/disttae/logtailreplay/change_handle.go:3434: Any nonempty bounded range is processed while spill-file admission is unavailable, even when all its rows fit within the configured in-memory limit.
    Impact: Small table_changes polls fail under spill quota pressure and otherwise incur spill-file I/O and reservations unnecessarily.
    Evidence: Every enabled range enters prepareRangeNetEffectSpill, and spillBaseHandleByPrimaryKey opens a file for its first nonempty batch. The focused probe observed a one-row range fail on its first denied file reservation despite a 64 MiB limit; the admitted control opened two spill files. ChangeRangeLimit documents spill for excess rows. Compute net effects within the existing bound for ranges that fit, transitioning to the existing spill mechanism when needed.

  • P2 pkg/sql/colexec/s3util.go:282: The 4.2 backport introduces an opt-in chunked persisted-column writer controlled by a new per-feature RPC-version threshold intended for mixed-version upgrades.
    Impact: This adds another on-disk writer format and rollout mechanism to 4.2 without a default deployment benefit: the branch advertises protocol 12, below the new threshold of 29. The live RPC value is also not a durable format-capability record.
    Evidence: The pinned .agents/skills/mo-dev/references/upgrade-compatibility.md 4.2 maintenance policy defers optional format evolution to main and disallows extending protocol gates for unsupported mixed-version operation. The existing legacy-column window path already supports bounded replay, including spill for oversized columns. Defer the optional writer and its PR-owned gate, while retaining any reader required by supported released artifacts, unless an applicable 4.2 maintenance need justifies the format change.

Validation:

  • The private /tmp and loopback preflight passed. Native libraries were reused only after matching 170 source inputs and six output hashes; an initially mismatched artifact was rejected.

  • Focused Go tests passed for ObjectIO, replay, table functions, planner and frontend authorization. The one-row spill-admission probe reproduced the reported behavior. See focused-tests.log and receipt checks/1796155497387757129-3.json.

  • The retained GC and unrelated-successor probes passed by asserting the observed incorrect results. See retention-valid-test.log and fuzzy-test.log, with receipts checks/1796156354065112028-3.json and checks/1796155953581275456-3.json.

  • Selected legacy and chunked ObjectIO, publication, writer-gate and disttae routing tests passed. See shared-owners-tests.log and receipt checks/1796156009583508781-3.json.

  • The frozen CI snapshot reports successful build, unit, proxy Compose and pessimistic multi-CN jobs. All 14 discussion keys are accounted for in discussion-assessment.json.

Limitations:

  • The counterexamples exercise the production replay reader with constructed object state; they were not reproduced through a running SQL cluster. The frozen CI summary does not identify whether the new distributed SQL case was selected.

  • No verified v4.2.9 release artifact or applicable newer hotfix was available in the supplied checkout, and no release-artifact upgrade or backup/restore test was run. The older v4.2.8 tag was not treated as the latest release.

XuPeng-SH and others added 8 commits December 2, 2026 07:58
An in-place ALTER replaces the mo_tables row under the same key. DATA BRANCH needs the original commit to include pre-ALTER writes in its diff. Keep the history policy when a partition handle opens later ranges and reject full-history requests on the bounded net-effect reader.

Keep storage error codes on an incomplete table_changes read and tell clients how to retry the fixed window. Check structured TN flush responses in BVT so serialization whitespace cannot fail a successful flush.
Drop the backport-specific SIMD workaround superseded by matrixorigin#33001. Use the release Makefile to select the toolchain in go.mod and generate matching service and unit test coverage blocks.
Use the same Unicode case rules as catalog lookup. Otherwise a newer toolchain maps previously distinct primary-key columns to one name during delete replay. Reuse the normalized name for both column and key lookups.
@XuPeng-SH

XuPeng-SH commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · superseded

Commit: 75633fa1cbaeebe8ae546432ec5f610ed816b0b9

PR changed before dispatch

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/wip size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants