Skip to content

Return fileservice read buffer allocation errors - #33131

Merged
mergify[bot] merged 6 commits into
matrixorigin:4.2-devfrom
iamlinjunhong:codex/loom/33095-4.2-dev
Nov 24, 2026
Merged

mergify[bot] merged 6 commits into
matrixorigin:4.2-devfrom
iamlinjunhong:codex/loom/33095-4.2-dev

Conversation

@iamlinjunhong

@iamlinjunhong iamlinjunhong commented Nov 24, 2026 •

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:

What this PR does / why we need it:

Fileservice panics when it needs a new read buffer and the allocator returns ENOMEM. Return the allocator error to the caller before reading or marking the entry complete. A read with sufficient existing capacity reuses that buffer without allocating.

If a LocalFS read fails after allocating a new buffer, its rollback clears the owning entry and releases the buffer once. If the read reuses an existing buffer, LocalFS publishes the resized slice only after both the read and cache conversion succeed. Disk cache reads propagate ENOMEM to the caller before object-store fallback. Ordinary cache misses and read errors still fall back. When a later entry fails after a partial disk-cache hit, error cleanup clears the released buffer and its published reader so the same IOVector can be retried safely.

Validation

  • Main baseline e17d5541537d30252009a9a2d4c70ab5480d3bc3 (macOS arm64, Go 1.27.1). The issue's one-byte reproducer panicked after one allocation attempt when a buffer was needed. The existing-buffer case read the byte with zero allocations. The issue reports the same baseline behavior on 4.2-dev.
  • Main candidate be16d27be8fb21cd716620c4c7b86f1bc8e1f238 (macOS arm64, Go 1.27.1 with CGo). make -j8 build, the issue's reproducer, focused fileservice tests, QA probes, and changed-code lint passed.
  • 4.2-dev candidate fe121f6df07f1ac60826c5df1651c7ecbe108d96 (macOS arm64, Go 1.26.4 with CGo). Its branch-specific make -j8 build and the same reproducer, focused fileservice tests, QA probes, and changed-code lint passed.

Both candidates returned an error matching syscall.ENOMEM after one allocation attempt, with the file offset unchanged and the entry incomplete. Both read the correct byte with zero allocations when capacity was sufficient. The QA probes also covered LocalFS rollback, short reads, conversion failures, and disk cache fallback. These are local results. PR CI runs separately.

Disk-cache follow-up at 8b85a3a815c3194c10697c96fe2613bdc68a62d1 (Darwin/arm64, Go 1.26.4, CGo)

  • TestS3FSReadDiskCacheAllocationFailure reproduced the fallback allocation panic on 3cb144de818ec1ef25b9fd1b0de5859ace52eba8. The repaired read returns ENOMEM without calling object storage or the cache-data allocator. The miss and short-read controls fetch the correct data, and the short-read buffer is released once.
  • Focused fileservice and ObjectIO cleanup tests passed with -race -short -tags matrixone_test. The fileservice package passed in the same mode with TestMinioSDK excluded because its external endpoint denied access in the earlier local run. Fileservice vet and incremental lint passed.
  • CI on the preceding head passed. The injected test covers the fileservice path. The original Linux mapping exhaustion and CN restart behavior remain unverified.

Partial-hit cleanup at 762408a73d7d6d9975036fb8bdd5465d875ad90a (Darwin/arm64, Go 1.26.4, CGo)

  • The new TestS3FSReadDiskCacheAllocationFailure partial-hit case reproduced the stale owned buffer on the reviewed head. After the fix, cleanup clears the buffer and reader, and retrying the same vector reads both entries with fresh owned storage. The caller-buffer control retains and reuses its supplied capacity.
  • Focused fileservice and ObjectIO cleanup tests passed with -race -short -tags matrixone_test. The fileservice package passed in the same mode with TestMinioSDK excluded because its external endpoint denied access in an earlier local run. Fileservice vet and incremental lint passed.
  • CI on the reviewed head passed. The local tests inject allocation failures. They do not reproduce the original Linux mapping exhaustion.

Performance and deployment scope

The read path adds a capacity branch and a publication check in LocalFS. The capacity-reuse tests confirmed zero allocations. The patch is expected to prevent the fileservice panic observed during the reported Linux CN checkpoint read when the allocator returns ENOMEM. The original CN workload, the mapping growth that reached the limit, and container restart behavior remain unverified by these tests.

Related PR

@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 the kind/bug Something isn't working label Nov 24, 2026
@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Nov 24, 2026
@mergify

mergify Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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

@XuPeng-SH

XuPeng-SH commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 3cb144de818ec1ef25b9fd1b0de5859ace52eba8

Review completed. Read the assessment.

XuPeng-SH pushed a commit that referenced this pull request Nov 24, 2026
## What type of PR is this?

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

## Which issue(s) this PR fixes:

- #33095

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

Fileservice panics when it needs a new read buffer and the allocator
returns `ENOMEM`. Return the allocator error to the caller before
reading or marking the entry complete. A read with sufficient existing
capacity reuses that buffer without allocating.

If a LocalFS read fails after allocating a new buffer, its rollback
clears the owning entry and releases the buffer once. If the read reuses
an existing buffer, LocalFS publishes the resized slice only after both
the read and cache conversion succeed. Disk cache reads retain their
existing fallback on errors.

### Validation

- Main baseline `e17d5541537d30252009a9a2d4c70ab5480d3bc3` (macOS arm64,
Go 1.27.1). The issue's one-byte reproducer panicked after one
allocation attempt when a buffer was needed. The existing-buffer case
read the byte with zero allocations. The issue reports the same baseline
behavior on `4.2-dev`.
- Main candidate `be16d27be8fb21cd716620c4c7b86f1bc8e1f238` (macOS
arm64, Go 1.27.1 with CGo). `make -j8 build`, the issue's reproducer,
focused fileservice tests, QA probes, and changed-code lint passed.
- `4.2-dev` candidate `fe121f6df07f1ac60826c5df1651c7ecbe108d96` (macOS
arm64, Go 1.26.4 with CGo). Its branch-specific `make -j8 build` and the
same reproducer, focused fileservice tests, QA probes, and changed-code
lint passed.

Both candidates returned an error matching `syscall.ENOMEM` after one
allocation attempt, with the file offset unchanged and the entry
incomplete. Both read the correct byte with zero allocations when
capacity was sufficient. The QA probes also covered LocalFS rollback,
short reads, conversion failures, and disk cache fallback. These are
local results. PR CI runs separately.

The current main PR head (`416f5765909c5a0eeee117eb480d11019608b98c`, Go
1.27.1) and the current `4.2-dev` PR head
(`3cb144de818ec1ef25b9fd1b0de5859ace52eba8`, Go 1.26.4) each passed
`make -j8 build`, `mo-service -version`, the issue reproducer, the
focused fileservice tests, and the QA probes on macOS arm64 with CGo.

### Performance and deployment scope

The read path adds a capacity branch and a publication check in LocalFS.
The capacity-reuse tests confirmed zero allocations. The patch is
expected to prevent the fileservice panic observed during the reported
Linux CN checkpoint read when the allocator returns `ENOMEM`. The
original CN workload, the mapping growth that reached the limit, and
container restart behavior remain unverified by these tests.

### Related PR

- `4.2-dev` backport
[#33131](#33131).

---------

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

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

Request changes: the ReadFromOSFile unit contract is fixed, but persistent allocator exhaustion can still panic on the incident's disk-cache → object-store read path. See the inline finding for the tested failure path and a possible repair boundary.

I also ran the six targeted reader/rollback/reuse tests with -race; they pass. The failing check below is a separate local fault-injection probe, not a claim that CI reproduced the original VMA exhaustion.

Comment thread pkg/fileservice/io_entry.go Resolved

@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: 3cb144de818ec1ef25b9fd1b0de5859ace52eba8

Assessment: request_changes

The direct reader and LocalFS now return allocation errors and clean up their read buffers. The checkpoint path in issue #33095 can still panic under persistent ENOMEM because the disk cache treats the allocation failure as a miss.

Model: gpt-6.2-sol / xhigh

Session: 01a20d20-3fe4-7541-b411-a67000af0276 · slot 0 · generation 4

  • P1 pkg/fileservice/io_entry.go:61: A checkpoint metadata read hits the disk cache, its read-buffer allocation returns ENOMEM, and the object-storage fallback also receives ENOMEM while allocating space for decoded or copied metadata.
    Impact: The panic escapes the checkpoint reader and can terminate the CN process. Returning the allocation error would let the logtail consumer handle it through its existing reconnection path.
    Evidence: DiskCache.read discards the error at pkg/fileservice/disk_cache.go:444. The fallback invokes the metadata converter at pkg/fileservice/s3_fs.go:1388, and pkg/fileservice/bytes.go:116 panics on allocation failure. Both allocators use the same default allocator on 4.2-dev. The prior same-head S3FS fault injection reported a panic when both allocations failed and success when the second allocation recovered. Propagate the allocation error through DiskCache or make the fallback return it. Cover persistent ENOMEM and ordinary cache fallback through S3FS.Read.

Validation:

  • Verified the frozen head, merge base, complete patch, and isolation preflight. See scope.stdout, preflight.stdout, and their receipts under checks/.

  • Reused attempt 2's passing focused run for allocation errors, buffer reuse, rollback, and transient LocalFS disk-cache fallback. Its merge-base control showed the original panic. See ../attempt-2/head-focused.jsonl, base-probe.jsonl, and the matching receipts.

  • Both focused S3FS cache-fill and fallback tests passed with CGo enabled. See s3-cache-controls.jsonl and checks/1795517115366760887-2.json.

Limitations:

  • The package-wide run passed the new regression cases, then reached its 240-second deadline during TestLocalFSWithDiskCache. That test completed in the same-head focused run. See fileservice-full.jsonl and checks/1795517052499197404-2.json.

  • The prior persistent-ENOMEM S3FS probe and race run are available as discussion reports. The original Linux mapping exhaustion and CN restart behavior remain unverified.

@XuPeng-SH

XuPeng-SH commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 8b85a3a815c3194c10697c96fe2613bdc68a62d1

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: 8b85a3a815c3194c10697c96fe2613bdc68a62d1

Assessment: request_changes

Disk-cache ENOMEM now reaches the caller before object-store fallback, and ordinary misses and short reads still fall through. A partial disk-cache hit leaves stale buffer aliases after the caller cleans up the returned error.

Model: gpt-6.2-sol / xhigh

Session: 01a20d47-b35e-7bd2-9d5c-61978a866730 · slot 0 · generation 6

  • P2 pkg/fileservice/disk_cache.go:452: A multi-entry read completes an earlier disk-cache entry with a vector-owned raw buffer, then returns ENOMEM for a later entry. The caller uses ReleaseReadResultOnError before reusing the vector.
    Impact: Cleanup frees the first buffer and resets done but leaves Data and the returned read closer pointing at the freed storage. On retry, prepareData can treat the stale slice capacity as reusable. The old reader also retains the invalid reference.
    Evidence: The public S3FS probe observed one release with both aliases still present. The caller-owned control passed. A diagnostic-only overlay that clears both aliases after release passed the same-vector retry and confirmed fresh allocation. See pkg/fileservice/io_vector.go:56, pkg/fileservice/io_entry.go:124, and receipts 1795528478395057555-2.json and 1795528565472479881-2.json. Clear both aliases when releasing a completed vector-owned buffer and cover retry in the disk-cache regression.

Validation:

  • The exact-head focused race run passed the maintained fileservice and ObjectIO cases, including persistent ENOMEM, ordinary miss and short-read fallback, rollback, reuse and cleanup. Receipt 1795528569028910375-2.json.

  • Verified the frozen patch, whitespace and pinned policy. Reconciled checks and logs in validation-reconciliation.json and accounted for all discussion keys in discussion-assessment.json.

  • The frozen CI snapshot records successful x86 UT and arm64 SCA for the assigned head.

Limitations:

  • Local validation used allocation fault injection. It did not recreate the original Linux CN mapping exhaustion or restart.

Partial disk-cache hits can publish both Data and a reader before a later entry returns ENOMEM. Clear those aliases with the owning release callback so a vector retry obtains a fresh buffer.
@iamlinjunhong

Copy link
Copy Markdown
Contributor Author

Follow-up to review 6040510905.

Commit 762408a73d7d6d9975036fb8bdd5465d875ad90a clears the raw data and published reader when error cleanup releases a completed entry's owned buffer. It retains the configured output pointer and preserves caller-owned buffers.

The new disk-backed S3FS regression reproduced the stale slice on the reviewed head. With the fix, a two-entry read returns ENOMEM after its first disk hit, cleanup releases the owned buffer once and clears both references, and a retry on the same vector reads both bytes with fresh owned allocations. The caller-owned control keeps its original buffer and reuses it. Both cases and the downstream ObjectIO cleanup tests passed under race.

@XuPeng-SH

XuPeng-SH commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 762408a73d7d6d9975036fb8bdd5465d875ad90a

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: 762408a73d7d6d9975036fb8bdd5465d875ad90a

Assessment: approve

The ENOMEM fix returns allocation failures through LocalFS and disk-cache reads, retains ordinary cache fallback, and clears released aliases before a partial-hit vector is retried. It reuses the existing allocator and cleanup ownership; the scoped test override avoids shared mutable allocator state. Both prior review findings are resolved by the current implementation and targeted regression cases.

Model: gpt-6.1-terra / max

Session: 01a20de6-4798-7d33-92a8-6fabbca9bb9d · slot 3 · generation 1

Validation:

  • Reviewed the complete frozen patch, allocation and vector cleanup owners, S3FS/ObjectIO consumers, issue 33095 and all indexed discussion.

  • The author reports focused fileservice and ObjectIO cleanup tests passing with -race at the assigned head, including persistent ENOMEM, fallback and partial-hit retry controls; these are reported results rather than locally reproduced runs.

  • The frozen CI snapshot for the assigned head records successful Ubuntu/x86 unit tests, Linux/arm64 SCA and shared build.

  • Local isolation preflight passed: preflight.log and checks/1795544690848645097-3.json.

Limitations:

  • The original Linux VMA exhaustion and CN restart were not reproduced. No additional local Go test run was performed; the assessment relies on the targeted author report, frozen CI and source review.

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

mergify Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

✅ Merged into 4.2-dev as 1d0a8f1 at 19:25 UTC

58 min in the queue, 57 min of it CI.

So far

  • ✅ Entered the queue Tue 24 Nov, 18:27 · rule release-4.2 · triggered by rule Automatic queue on approval for release-4.2
  • ✅ Passed · in place
  • ✅ Merged 19:25 · 1d0a8f1 · 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

This branch was previously deployed

1 inactive deployment
ci — 8dd4a484 Deployed Nov 24, 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 size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants