Skip to content

[4.2-dev] perf(branch): resolve creation timestamps before catalog replay - #32925

Merged
mergify[bot] merged 10 commits into
matrixorigin:4.2-devfrom
gouhongshen:codex/branch-catalog-merge-opt-42dev
Nov 23, 2026
Merged

mergify[bot] merged 10 commits into
matrixorigin:4.2-devfrom
gouhongshen:codex/branch-catalog-merge-opt-42dev

Conversation

@gouhongshen

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Follow-up to #32705 for #32708. The main counterpart is #32707.

What this PR does / why we need it:

A DATA BRANCH MERGE of one renamed row in a six-row table spent most of its time replaying historical mo_catalog.mo_tables changes. Four scans encountered the same missing historical object before falling back to a snapshot Reader. The original catalog row was already readable by its compound primary key at the required snapshot.

  • Prefer a snapshot read for table creation time when its row matches the table ID, has the original catalog version, and carries a commit timestamp in the required range. Retain historical replay and the existing ID-based recovery for other cases.
  • Reuse proven creation bounds for the same physical generation. This keeps a pre-ALTER destination write visible to WHEN CONFLICT SKIP even when ALTER rewrites the catalog row.
  • Reuse bounded checkpoint object metadata within a statement, avoid redundant checkpoint prefetches, overlap catalog metadata reads, and coalesce overlapping persisted-block reads with bounded compressed input. Reduce the allocations used to collapse changes for each key while retaining visible-state and recovery semantics.

On a QA cluster running the 4.2.8 hotfix line, a six-row one-update MERGE in the same older database took 62.946 s on the current QA CN and 0.834 s on one isolated CN with these optimizations. This is a one-run result per CN. The baseline spent 56.10 s on four catalog replays. The optimized run resolved both table creation timestamps via snapshot reads in 4.08 ms and 0.12 ms, and its result matched all six expected rows.

Validation

Passed locally on Go 1.26.4 / macOS arm64:

  • Full objectio, objectio/ioutil, tae/logtail, disttae/logtailreplay, and vm/engine package tests.
  • Targeted frontend, vm/engine/test, and tests/dml tests for DATA BRANCH, PK filtering, checkpoint ranges and metadata reuse, and stale-read recovery.
  • The checkpoint-catalog SQL regression checks rename, repeated merge, conflict preservation across a catalog rewrite, insert and delete results.

The QA timing was measured on the hotfix-based image. GitHub CI covers this 4.2-dev port on its own base.

@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 added kind/bug Something isn't working kind/enhancement kind/test-ci labels Nov 19, 2026
@matrix-meow matrix-meow added the size/XL Denotes a PR that changes [1000, 1999] lines label Nov 19, 2026
@mergify

mergify Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Queue requested — the merge queue status continues in this comment ↓.

@XuPeng-SH

XuPeng-SH commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 9045579f6480b2956003fde9692710161ad0d974

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: 9045579f6480b2956003fde9692710161ad0d974

Assessment: request_changes

Reviewed against 4.2-dev at 71e2233. The catalog lookup reuses the snapshot reader, and the SQL regression preserved the destination update across ALTER. The new block-read cleanup can consume the request deadline before missing-file recovery gets a chance to run.

Model: gpt-6.2-sol / xhigh

Session: 01a1f0a0-5126-78f3-9ab8-ef4e87f2f119 · slot 0 · generation 3

  • P2 pkg/vm/engine/disttae/logtailreplay/change_handle.go:875: A historical replay read returns ErrFileNotFound while another block read in the same prefetch window is still pending on the request context.
    Impact: Replay waits for the pending read before returning the missing-file error. If that read consumes the remaining deadline, DATA BRANCH MERGE can time out even when the snapshot reader could have recovered the catalog row.
    Evidence: The base-versus-candidate probe in recovery-probe.log returned ErrFileNotFound with a live parent context on the base and with context deadline exceeded on the candidate. The candidate submits reads on the parent context at line 806 and still joins every submitted job after recording the error. pkg/frontend/data_branch.go:2926 then returns the context error before the ID-based fallback. Give the prefetch window a cancellable child context and cancel pending reads when a terminal error is known. Drain and clean up the jobs, then return the original error while the parent remains usable for recovery.

Validation:

  • Focused logtail replay, checkpoint, engine and SQL tests passed. The SQL run exercised both Reader and CollectChanges paths and verified conflict SKIP after ALTER. See focused-proxy.log and checks/1795080186354533764-2.json.

  • The full logtailreplay package passed under -race. The coalescing, dispatch and replacement-lineage tests each passed 100 targeted race repetitions. See replay-race-proxy.log, race-stress-*.log and their receipts.

  • The missing-file probe reproduced the deadline regression against a 4.2-dev control. See recovery-probe.log and checks/1795080161233967019-2.json. An earlier probe build had a missing test import, recorded in recovery-probe-build.log.

  • Focused object I/O error and commit-timestamp tests passed. The same-binary row-collapse benchmark reduced allocations from 49,042 to 16,273 per operation on disjoint keys and from 56,913 to 15,954 on paired keys. See objectio-focused.log, collapse-bench.log and their receipts.

  • Diff hygiene, runtime preflight and the native prerequisite build passed. Frozen exact-head CI also records successful Ubuntu unit tests, Linux arm64 SCA and multi-CN BVT.

Limitations:

  • The recovery probe used controlled FileService reads and the replay entry point. The SQL regression exercised the ordinary merge path.

  • The reported QA timing came from one run per CN on a hotfix-based image. The local benchmark measured row collapse only.

Stop the read window when a block or its metadata cannot be read. Drain submitted jobs and preserve the original error so snapshot fallback can still use the caller context.

@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.

Re-reviewed 2819d44 against 4.2-dev 1aa4d1a. The previous metadata-versus-payload ordering case is addressed: a completed current plan can dispatch its payload while later metadata is pending. There is still a blocker in the termination of those speculative workers: cancellation does not necessarily release a real FileService metadata read, so synchronous cleanup can delay both a completed window and the missing-file recovery path. The inline comment contains a deterministic reproduction at the replay boundary using the real S3FS disk cache.

The repro uses test-only barriers to park an actual disk-cache entry update and observe its existing wait; it is not an end-to-end SQL or production timing measurement. Current-head Linux CI is green. Earlier focused functional and race evidence for unchanged closures was reused.

@XuPeng-SH

XuPeng-SH commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 2819d441a9c97b2d97a44efc2742970fe69685f1

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: 2819d441a9c97b2d97a44efc2742970fe69685f1

Assessment: request_changes

The snapshot-first lookup reuses the catalog reader and preserves the existing replay and ID fallback. The earlier dispatch and error-ordering cases are addressed. Speculative metadata still puts an unrelated disk-cache update on the response and recovery paths.

Model: gpt-6.2-sol / xhigh

Session: 01a1f0a0-5126-78f3-9ab8-ef4e87f2f119 · slot 0 · generation 3

  • P2 pkg/vm/engine/disttae/logtailreplay/change_handle.go:550: A later object's speculative metadata read misses the memory cache and reaches a disk-cache range entry that another goroutine is updating. The current payload window has already completed or found a missing file.
    Impact: Replay waits for the unrelated cache writer before returning the completed window or its original error. If the request deadline expires during that wait, DATA BRANCH MERGE skips the snapshot fallback and can time out again.
    Evidence: The deferred finishBlockPlanPrefetch cancels its child context and then receives from every pending worker. FastLoadObjectMeta reaches S3FS.Read and DiskCache.Read, where waitUpdateComplete at pkg/fileservice/disk_cache.go:676 waits on a condition variable with no cancellation condition. pkg/frontend/data_branch.go:2926 returns the parent context error before the ID fallback. The merge base has no later-object metadata workers in this payload window. The same-head reproduction in review_comments:4645497161 observed both successful payloads and ErrFileNotFound held behind the real cache wait. Keep speculative cache I/O off the synchronous return path, or make the relevant wait interruptible while preserving worker ownership and ordered errors.

Validation:

  • Verified the assigned head, target and merge base against the frozen patch and checked source cleanliness and diff whitespace. See scope.stdout and checks/1795231365593565931-2.json.

  • Traced the cache-writer wait and fallback in current source, and reconciled them with the exact-head real S3FS and disk-cache reproduction reported in review_comments:4645497161.

  • Reused frozen exact-head CI results for the Linux build, unit tests, coverage, arm64 SCA, and proxy and pessimistic multi-CN BVT. Earlier review reports cover the SQL merge and ALTER conflict regression and focused race cases on unchanged paths.

Limitations:

  • The real-cache reproduction was reported at the replay boundary. This attempt did not independently rerun it or exercise the final SQL fallback.

  • The reported QA timings came from one run per CN on a hotfix-based image. The earlier row-collapse benchmark measures that component only. The linked issue was available, and the related PR discussions were outside the frozen evidence.

…ates

Wake contending readers and cache fills when their context ends. Keep the update slot owned by its writer and verify replay returns both a completed payload window and the original missing-file error.
@XuPeng-SH

XuPeng-SH commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 431ff78e6d9ead61966bdd6e8ce42faa63024cfb

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: 431ff78e6d9ead61966bdd6e8ce42faa63024cfb

Assessment: approve

The snapshot-first catalog lookup reuses the existing Reader and preserves historical replay and ID-based fallback. The latest disk-cache change resolves the prior recovery blocker. Canceled readers and cache fills leave the wait while the active writer retains its update slot.

Model: gpt-6.2-sol / xhigh

Session: 01a1f0a0-5126-78f3-9ab8-ef4e87f2f119 · slot 0 · generation 3

Validation:

  • Verified the frozen patch, pinned review policy, native prerequisites, and private /tmp and loopback preflight.

  • Focused race-enabled tests passed for disk-cache cancellation, replay dispatch, coalesced reads, replacement lineage, row collapse, and checkpoint metadata. The cache and replay cancellation tests each passed ten repetitions.

  • The embedded SQL checkpoint regression passed through both Reader and CollectChanges paths. It verified repeat merge, conflict SKIP after ALTER, insertion, and deletion. Checkpoint reuse tests also passed across distinct ranges and filters.

  • The frozen head passed Linux unit tests, arm64 static analysis, and proxy and pessimistic multi-CN BVT.

Limitations:

  • The QA speedup was an author-reported hotfix comparison with one run per CN. Local checks establish correctness and cancellation behavior on the 4.2-dev port.

@mergify mergify Bot added the queued label Nov 23, 2026
@mergify

mergify Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

✅ Merged into 4.2-dev as 6faa4f2 at 08:45 UTC

1 h 21 min in the queue, 1 h 19 min of it CI.

So far

  • ✅ Entered the queue Mon 23 Nov, 07:24 · rule release-4.2 · triggered by rule Automatic queue on approval for release-4.2
  • ✅ Passed · in place
  • ✅ Merged 08:45 · 6faa4f2 · squash
3 merge conditions met
  • #review-threads-unresolved = 0 · required by GitHub branch protection
  • github-review-approved · required by GitHub branch protection
  • any of · required by GitHub branch protection:
    • check-success = CI Required
    • check-neutral = CI Required
    • check-skipped = CI Required

Times in UTC · dashboard · how the merge queue works

@mergify
mergify Bot merged commit 6faa4f2 into matrixorigin:4.2-dev Nov 23, 2026
@mergify mergify Bot removed the queued label Nov 23, 2026
XuPeng-SH pushed a commit that referenced this pull request Nov 30, 2026
…ailure (#32992)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Related to #32708. Follow-up to #32707 and the 4.2-dev review finding in
#32925.

## What this PR does / why we need it:

Historical catalog replay reads metadata in parallel. If a required
object was missing, replay waited for all later reads before checking
the error. A slow read could exhaust the request deadline and prevent
DATA BRANCH MERGE from using the existing snapshot fallback.

Wait for metadata plans in object order. Once a required plan fails,
cancel and join the later reads using a child context. Preserve the
original error and the request context. Keep the existing bound on
parallel reads.

The regression exercises a missing first or second object's metadata
with a later read held open. Both cases exhausted the caller deadline
before the fix. The fixed version passed 100 runs under the race
detector, including the existing data-block cases.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

This branch was previously deployed

1 inactive deployment
ci — 9a343cd0 Deployed Nov 23, 2026 by mergify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working kind/enhancement kind/test-ci size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants