Repository navigation
fix: clean failed fulltext spill and ETL temp files - #29358
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Reviewed exact head ca22677 against main/merge-base a61e771. No blocking findings. Checked spill write, short-write and Close failures, staging-file cleanup, retained data and retry, partial-success memory accounting, and spill/unspill/close ownership. Bounded spill workers finish before accounting is updated. LocalETLFS retains temp-file ownership until successful rename; a later directory-sync failure does not remove the published destination. Focused failure-injection regressions cover these paths. Exact-head CI run 35995580303 passed enabled build, UT, SCA, coverage and both multi-CN BVT jobs; fileservice race execution is confirmed in the log. This ordinary cleanup fix does not require a separate design document. COMMENT only because this is self-authored.
be71ec2 to
0b54b40
Compare
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep review of 0b54b4079307fbdc1bdeefdeaa90ae89edd8d69d, against main with merge base 44e5226a21d7905a1d1e528d257321d2696c807b.
Recommendation: approve / no blocking findings. COMMENT is used because the authenticated account is also the PR author. This review includes the LocalFS/LocalETLFS NewWriter changes added since the earlier review.
Scope and issue closure
Read every changed hunk across all six files, both target issues (#29251 and #29264), and the relevant callers/cleanup paths. The change map has three closures: partition spill and pool accounting; LocalETLFS.write temporary-file ownership; both local writer finalizers and checksum-wrapper return. This is a focused bug fix, exempt from a separate feature-design gate.
- #29251: write error, short write and close error do not publish the staging file or release resident partition data. Cleanup closes/removes the staging file, and the retained data remains readable and can be spilled/unspilled on retry. A successful spill transfers the path to the partition, whose Unspill/FreeItem/Close paths own its subsequent removal.
- Partial pool failure: eligible partitions are resident, full and distinct. Each worker contributes at most one error; the error channel has capacity nspill. After WaitGroup completion, subtracting only successful partitions restores the resident-memory invariant even when the call returns an error. Retrying skips successful partitions and accounts for the remainder without double subtraction.
- #29264: LocalETLFS.write cleanup depends on explicit ownership rather than a shadowable error variable. LocalFS/ETL writer cleanup now runs during Close, including Sync, Close, ensureDir and Rename failures. Rename is the ownership-transfer point; subsequent directory-sync failure preserves the published destination. The checksum wrapper is returned on each normal finalization path.
The os.File close behavior was checked against the local Go runtime: after an attempted Close, the file is closed even when Close reports an error; the cleanup flags correctly avoid retrying that close.
Unhappy-path audit
| Question | Closure and result |
|---|---|
| Q1: creation to destruction | Staging files are locally owned until spill publication / successful rename. Pre-publication errors close and attempt removal; success transfers ownership to partition/destination. Resident partition data survives failed spills and is eventually freed by retry success or pool cleanup. Reader/writer test fixtures register cleanup and assert descriptor/path/output postconditions. |
| Q2: wait termination | Spill workers are joined before accounting and return; at most nspill buffered error sends cannot require a receiver to unblock. No new lock/channel cycle, retry loop or asynchronous cleanup is introduced. Filesystem syscall completion remains the existing external dependency; this patch does not introduce a hard I/O cancellation guarantee. |
| Q3: accumulation | At most 16 concurrent spill workers, bounded error buffer, one staging file per attempt, and existing partition/heap admission remain in place. Failed attempts retain the existing resident buffer; successful attempts release it and update accounting. No new retained queue/cache is added. |
Cleanup removal is best effort if the OS itself refuses deletion; the fix closes the missing cleanup paths without claiming recovery from every filesystem failure.
Performance, test cost and engineering quality
No added per-row/per-byte processing, copying, fsync, goroutine fan-out or lock is introduced. Spill still performs its existing write/close, with close now checked before publication. Additional Remove calls occur on failure. The local interface/callback seams permit deterministic fault injection without a global hook or generalized framework; their dispatch is per spill operation. The existing sort and spill scheduling complexity is unchanged.
Tests use tiny partitions and temporary directories, deterministic failures, exact state/content/resource assertions, and no cluster or sleep-based scheduling. They distinguish pre-publication cleanup from post-rename preservation. A new SQL BVT would not directly prove these internal filesystem failure contracts; the targeted injection tests are the relevant oracle, supplemented by current-head multi-CN BVT compatibility checks. No production throughput benchmark was run; the performance conclusion is based on the changed operations and their placement.
Validation
New local evidence at the reviewed head, using mo-cgo-test, -mod=readonly, Linux/amd64 and matching freshly built CGo libraries:
make cgo: passed.-race -count=1 -timeout 120s -json ./pkg/fulltext: passed, terminal package elapsed 1.500s; both new spill regression tests were selected and passed.-race -count=1 -timeout 120s -json -run '^(TestLocalWriterCloseCleanup|TestLocalETLFSWriteFailureRemovesTemp)$' ./pkg/fileservice: passed, 1.150s.TestPoolPartialSpillAccountsSuccessfulPartitions, exact selection,-race -count=100: 100 passes, zero failures, package elapsed 1.156s.TestLocalWriterCloseCleanup, exact selection,-race -count=100: 100 passes, zero failures, package elapsed 4.177s. Every iteration includes both implementations and success / closed-file / ensure-dir / rename / directory-sync cases.- Repetition count follows the 30s adaptive budget capped at 100: measured test elapsed was below timer resolution for the pool test and 0.03s for the writer test.
git diff --check: passed; review worktree has no source changes.
Current-head CI is green and the PR is mergeable: https://github.com/matrixorigin/matrixone/actions/runs/36034944053 . Inspected the UT job log confirming the fileservice owning-package race stage completed with status 0, and coverage artifacts confirming execution of the new spill failure paths and writer cleanup branches. Reused CI for the remaining package/static/BVT checks.
Initial local attempts stopped before test execution because a reusable native library failed provenance validation, then because /tmp ran out of space while linking. Rebuilding the native libraries and using a task-owned NVMe temporary directory resolved those environment failures; all reported test passes are completed subsequent runs.
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #29251
Fixes #29264
What this PR does / why we need it:
Failed fulltext partition spills now close and remove the staging file without publishing it or freeing the still-resident partition. Short writes and close errors are treated as failures, so a later spill can retry safely. When a concurrent pool spill only partly succeeds, memory accounting includes the successful partitions even though the operation reports an error.
LocalFSandLocalETLFSwriter finalization closes and removes temporary files when close or publication fails. LocalETLFS owns its temporary file until a successful rename, independently of shadowed local errors. Read, size, close, directory, and rename failures clean it up; after successful rename, a directory-sync error does not remove the published destination.Focused failure-injection tests cover spill write/short-write/close failures, pool partial success and retry, LocalFS/ETL writer-close cleanup, and ETL read/size/rename failures.
Validation:
make cgo; targeted regression tests;mo-cgo-test -count=1 ./pkg/fulltextand./pkg/fileservice;go vet ./pkg/fulltext ./pkg/fileservice;git diff --check. GPT-6 medium design and final review completed, including a review-discovered pool accounting correction.Latest-main rebase and current validation
Rebased onto
matrixorigin/main@44e5226a21(including #29370). New head:0b54b4079307fbdc1bdeefdeaa90ae89edd8d69d. The complete binary diff againstmainis byte-for-byte identical to the diff before rebase, andgit diff --checkpasses. Post-rebase CGo full package tests passed forpkg/fulltextandpkg/fileservice. On the old head, ordinary Ubuntu UT passed; UT Coverage failed becauseTestIssue28234ExceptAllClustertimed out after ten minutes; no attribution to this patch was established. Both multi-CN BVT jobs failed at MinIO startup before SQL;mainnow includes the MinIO compose fix #29370. The old BVT failures are not SQL test verdicts; CI on this new head is pending.