Skip to content

fix(frontend): stop DATA BRANCH DIFF SQL output closing the borrowed shared file service - #30769

Merged
XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-30755-main-2206e158
Oct 22, 2026
Merged

XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-30755-main-2206e158

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:

Related to #30755

What this PR does / why we need it:

Root cause

SQL-format DATA BRANCH DIFF ... OUTPUT FILE with a SHARED:/... target borrows the process-wide shared file service in prepareFSForDiffAsFile, but all three terminal paths called targetFS.Close(ctx) unconditionally: the preparation-error defer, the mutable release, and newSingleWriteAppender's streaming release. A single diff operation therefore ran terminal cleanup of the long-lived service registry: FileServices.Close iterates every registered service, and S3FS/LocalFS Close tear down their registered mem/disk caches.

Change

pkg/frontend/data_branch_output.go:

  • prepareFSForDiffAsFile now records ownsTargetFS only in the branch that creates an ETL service via fileservice.GetForETL (implicit-local, stage-resolved, and dynamic ETL targets). The SHARED branch borrows the process service, and the preparation-error defer closes only the owned service; output deletion and error propagation are unchanged.
  • New helper releaseDiffTargetFS builds both releases: the owned mutator/writer release runs first, then exactly one terminal Close for the operation-created ETL service, still returning the underlying error. A borrowed target service is returned unwrapped and never closed.
  • newSingleWriteAppender's release now closes only its pipe endpoint and waits for the writer task; it no longer closes the caller-supplied target file service, whose lifetime stays at the acquisition boundary.

Issue-to-test proof

pkg/frontend/data_branch_output_test.go, using counting shared-service surrogates over the real prepareFSForDiffAsFile/release/cleanup path with SHARED:/diff targets:

  • TestDataBranchOutputPrepFailureKeepsBorrowedSharedService - injected preparation delete failure: the injected error propagates, preparation delete + failure-cleanup delete both run, borrowed Close count 0.
  • TestDataBranchOutputStreamingReleaseKeepsBorrowedSharedService - streaming success: the writer task finished before release returned (full SQL output captured), preparation and cleanup deletes run, borrowed Close count 0 and the service stays usable after release.
  • TestDataBranchOutputStreamingWriteFailureKeepsBorrowedSharedService - injected streaming write failure: the write error propagates from writeFile and release, failed-output cleanup deletes, borrowed Close count 0.
  • TestDataBranchOutputMutableReleaseKeepsBorrowedSharedService - mutable append path: the owned mutator closes exactly once on release, output appended correctly, borrowed Close count 0.
  • TestDataBranchOutputMutableAppenderReturnsCloseFailure (strengthened) - mutator close failure still propagates while the borrowed service is never closed.
  • TestReleaseDiffTargetFSOwnership - release policy: borrowed service never closed (also on writer error); owned ETL service closed exactly once, strictly after its owned writers finished, also on writer error.

The same focused set failed on base 0276f82 with borrowed Close count 1 in every scenario above, so the red/green pair proves this change fixes the reported defect.

Test commands and results (CGo test wrapper, macOS/arm64, Go 1.27.1, head 0276f82 + this change)

  • Red on base with tests only: .agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=300s -run 'KeepsBorrowedSharedService|^TestDataBranchOutputMutableAppenderReturnsCloseFailure$' ./pkg/frontend - exit 1, borrowed Close count 1 on all scenarios (defect reproduced).
  • Green: same selection with -v - exit 0, all six tests plus four policy subtests PASS under -race.
  • Adaptive focused race protocol: each of the six diff-touched streaming lifecycle tests measured once under -race -json (T=0.00-0.01s, N=clamp(floor(30s/T),1,100)=100), then .agents/skills/mo-dev/scripts/mo-cgo-test -race -count=100 -timeout=120s -run '^<Test>$' ./pkg/frontend per test - all six exit 0.
  • Owning package without a test-name filter: .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=3600s ./pkg/frontend - exit 0, ok github.com/matrixorigin/matrixone/pkg/frontend 25.873s; .agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=7200s ./pkg/frontend - exit 0, ok github.com/matrixorigin/matrixone/pkg/frontend 59.567s.
  • Diff-output family regression: .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -v -timeout=600s -run 'DataBranchOutput|DataBranchDiff|DataBranchCSV|OnlineBranchApply' ./pkg/frontend - exit 0, 141 selected tests/subtests, 0 fail.
  • Static: gofmt -l on both changed files clean; with the repository CGo environment, go vet -mod=readonly ./pkg/frontend - exit 0 and golangci-lint run -c .golangci.yml --new-from-rev 0276f82fb7 ./pkg/frontend - exit 0, 0 issues.

Residual risks and limitations

  • go vet / golangci-lint on pkg/frontend require the repository CGo environment (CGO_CFLAGS/CGO_LDFLAGS pointing at cgo/ and thirdparties/install); without it the cgo package fails to build and vet emits pan-package typecheck noise that is an environment failure, not a code failure.
  • newSingleWriteAppender no longer closes the target file service; its only production caller now wraps the release through releaseDiffTargetFS. All package-local direct callers were covered by the green full-package runs; none asserted close behavior.
  • Owned-ETL terminal closure is proven by the release-policy UT plus the green full-package runs, because fileservice.GetForETL constructs services internally and provides no injection seam; the borrowed branch is proven end to end.
  • For owned ETL targets, cleanup still deletes via the ETL service after release closed it; that ordering predates this change (LocalETLFS Delete remains functional after Close) and is deliberately preserved.

…shared file service

## Summary

- prepareFSForDiffAsFile now closes only the ETL service it creates for
  SQL-format diff output files; the borrowed process-wide SHARED file service
  is never closed by preparation failure, mutable release, or streaming release
- new releaseDiffTargetFS chains the owned mutator/writer release before the
  single terminal Close of the operation-created ETL service, and returns
  borrowed releases unwrapped
- newSingleWriteAppender's release closes its pipe endpoint and joins the
  writer task, and no longer closes the caller-supplied file service, whose
  lifetime stays at the acquisition boundary

## Verification

- focused borrowed-service tests failed on base 0276f82 (borrowed Close
  count 1 on preparation failure, streaming release, streaming write failure,
  mutable release, and mutator close failure) and pass after the change
- each diff-touched streaming lifecycle test measured once under -race
  (T=0.00-0.01s) and stress-run 100 times via -race -count=100, all exit 0
- full ./pkg/frontend green without a test-name filter in normal mode
  (ok 25.873s) and under -race (ok 59.567s); gofmt/vet/golangci-lint clean
@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 →

@gouhongshen

Copy link
Copy Markdown
Contributor Author

Unrelated UT-failure record — attempt 1 of run 39716108348

UT Test on Ubuntu/x86 failed on two tests; the failed-job log shows both are outside this PR's delta:

  • TestCDCNoFullPublicTakeoverLifecycle (pkg/tests/sqlintegration, 04:08:44–04:10:02 UTC, 77.59s) — the CN C label assignment (ddl_test.go:1325, 30 s-bounded DebugUpdateCNLabelWithContext) timed out inside a logservice/HAKeeper progress-stall burst (14× heartbeat context deadline exceeded, 41× checker-state timeouts, propose/tick timeouts, 40 dragonboat LocalTick batch accumulations). This is the residual stall class already recorded in [Bug]: CDC takeover lifecycle flakes when CN label RPC exceeds its three-second deadline #30231, including a prior identical-head-class recurrence; full reproduction record: 30231 (comment). The same head passed this UT lane earlier the same day (run 39708823079, job 119595480840, success 02:50:05Z).
  • TestPublicationSurvivesAllocatorRestart (pkg/lockservice, 03:35:20–03:35:30 UTC, 10.19s) — a data race wholly inside pkg/lockservice between the allocator's keepalive handler (lock_table_allocator.go:1616 read) and the test's publication-storage writer write through LocalETLFS. go list -deps ./pkg/lockservice contains no pkg/frontend package, so this failing test binary is identical to main's. No matching existing issue was found for it, so per policy no issue-tracking action was taken.

This PR's own suite was green in the failed run itself (pkg/frontend pass, 246.65 s) and its delta remains pkg/frontend/data_branch_output.go + test only. Per policy, the single allowed failed-jobs rerun of run 39716108348 (attempt 1) was requested after recording the above evidence; no source, assertion, timeout, sleep, or CI setting was changed for these failures.

@XuPeng-SH

XuPeng-SH commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-xupeng · superseded

Commit: 15f41231f5e778b150a45cbb686d86d927ab1a0d

Review belongs to an older commit; it is not a review of the current head.

@XuPeng-SH

XuPeng-SH commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 15f41231f5e778b150a45cbb686d86d927ab1a0d

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: 15f41231f5e778b150a45cbb686d86d927ab1a0d

Assessment: approve

Reviewed the complete two-file delta and affected ownership, error and cancellation paths. The acquisition boundary correctly distinguishes borrowed services from owned ETL services, preserves writer completion and error propagation, and avoids registry-wide cache teardown. No actionable findings remain.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1

Validation:

  • Passed 12 focused tests and four ownership-policy subtests under -race, covering preparation failure, streaming success/failure, mutable release and close ordering.

  • Passed six individually selected streaming lifecycle tests with -race -count=100 each, using repetitions derived from measured test durations.

  • Preflight passed; tests used the supplied test-exec. Missing native prerequisites were recovered through repository make cgo, with 194 frozen input hashes verified.

  • Reconciled commands, source fingerprints, exit receipts and terminal logs in /home/xupeng/.local/state/mo-bot/jobs/e7a7c7cf55c4cf280c982262/attempt-1/validation-reconciliation.json. Source remains unchanged; git diff --check passed.

  • Reused frozen exact-head successful UT, coverage, static-analysis and multi-CN BVT results. Performance tracing found only constant-size release bookkeeping, with no added per-row work or I/O.

Limitations:

  • No local live-S3 teardown test or performance benchmark was run; ownership is verified through controlled tests and traced service implementations.

  • Raw CI logs and the linked issue body were not supplied. Earlier-base author test claims were not counted as fresh execution evidence.

@mergify mergify Bot added the queued label Oct 22, 2026
@mergify

mergify Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-22 05:45 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🚫 Left the queue — 2026-10-22 06:03 UTC · at 15f41231f5e778b150a45cbb686d86d927ab1a0d

This pull request spent 18 minutes 28 seconds in the queue, with no time running CI.

Reason

The pull request can't be updated

GitHub response: refusing to allow a GitHub App to create or update workflow .github/workflows/mo-eos-sink.yml without workflows permission
GitHub only lets Mergify write to .github/workflows/ with the workflows permission. An organization owner can accept Mergify's pending permissions at https://dashboard.mergify.com/orgs/matrixorigin/repositories.

Hint

You should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

@mergify mergify Bot added dequeued and removed queued labels Oct 22, 2026

This branch was previously deployed

1 inactive deployment
ci — b3183a03 Deployed Oct 22, 2026 by XuPeng-SH
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 size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants