Skip to content

refactor(fileservice): consolidate memory cache allocation ownership - #28182

Merged
XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-27138-cbfed3d2
Sep 5, 2026
Merged

XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-27138-cbfed3d2

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 #27138

What this PR does / why we need it:

Root cause

Memory Cache now reserves physical backing capacity before it allocates cache data. The standard FileService factory nevertheless retained a second capacity owner: DiskCache received the Memory Cache allocator and a separate FIFO cache pointer which wrapped allocations in cacheCapacityGuardedAllocator / EnsureNBytes. RemoteCache was also given a FileService wrapper instead of the Memory Cache allocator directly. These parallel mechanisms obscured the reservation owner and made future double reservation or bypass regressions likely.

Changes

  • Make the factory construct Memory Cache before Remote Cache (after preserving the invalid-remote-config validation), and wire DiskCache and RemoteCache directly to the same *MemCache allocator.
  • Remove DiskCache’s legacy FIFO capacity pointer, guarded allocator, capacity-guard marker, and ensureCacheDataCapacity.
  • Keep LocalFS and S3FS allocator delegation intact; their cache-owned Allocate, AllocateWithHint, and Copy paths continue to enter Memory Cache reservation.
  • Keep ObjectIO column constructors on the FileService-injected allocator. Its independent Default allocator use is only for generated data that is not admitted to that FileService Memory Cache.

Issue-to-test proof

  • TestFileServiceCacheDataAllocatorsReserveBackingCapacity covers LocalFS and S3FS Allocate, AllocateWithHint, and Copy at full capacity.
  • TestDiskCacheReadUsesMemoryCacheReservation fills the Memory Cache, reads through DiskCache, verifies allocator identity, eviction before allocation, backing-size reservation, owner identity, and release on vector/flush.
  • TestRemoteCacheReadUsesMemoryCacheReservation performs a validated remote hit against a full Memory Cache and verifies the same ownership, eviction, reservation, and release behavior.
  • TestFileServiceCachesUseMemoryCacheAllocator verifies the standard factory gives DiskCache and RemoteCache the one Memory Cache allocator.
  • Existing reservation lifecycle tests cover rehome-before-copy, FIFO usage commit, and duplicate insertion until data release. ObjectIO cache/vector tests verify validation and cache-admission forwarding, including remote column cache admission.

Tests

  • make -j8 cgo
  • Focused FileService reservation tests
  • mo-cgo-test -count=1 -timeout=600s -skip "^TestMinioSDK$" ./pkg/fileservice
  • mo-cgo-test -race -count=1 -timeout=600s -skip "^TestMinioSDK$" ./pkg/fileservice
  • mo-cgo-test -race -count=100 -run "^TestRemoteCacheReadUsesMemoryCacheReservation$" ./pkg/fileservice
  • mo-cgo-test -run "Test.*(Cache|Vector)" ./pkg/objectio

TestMinioSDK/file_service/basic was excluded only after reproducing the same Access Denied response against the local MinIO endpoint from an origin/main worktree.

Residual risks

This refactor does not change backing-size accounting, eviction policy, remote routing, or cache data layout. The changed boundary is exercised with race tests; external MinIO authorization remains an environment dependency.

@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

gouhongshen commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor Author

Unrelated CI blocker: Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY) failed in workflow run 33945731661 while restoring sys from a cluster snapshot. The failure is in snapshot system-catalog restoration / DistTAE deleteTable, outside the FileService cache-allocation scope of this PR. Matrixone Utils CI / Coverage then failed because that required BVT producer failed.

Tracking issue: #28206. The failed jobs were rerun once from workflow attempt 1.

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

Deep-reviewed at a74b89d.

Design decision: the existing MemCache reservation API is the single physical-capacity owner. The factory now constructs that owner first and gives the same allocator directly to DiskCache and RemoteCache. With memory cache disabled, both retain their default allocator fallback; remote configuration is still rejected before any cache resource is created. Direct DiskCache and RemoteCache constructors preserve their standalone defaults. This consolidates an existing contract rather than changing the configured capacity, eviction policy, data format, or public API.

Unhappy-path audit:

  • Q1 passes: Disk and validated Remote reads transfer one pending reservation with the returned Bytes; successful FIFO insertion commits it, while validation failure, duplicate or rejected admission, vector release, idle drain, Flush, and Close release it through the existing exact-once paths.
  • Q2 passes: no wait or lock edge is added. Removing the legacy guard eliminates a redundant eviction path; reserveCacheData retains its non-blocking transient-buffer fallback when capacity cannot be obtained.
  • Q3 passes: FIFO used bytes plus pending reservations remain under the hard MemCache capacity, and retained idle buffers remain bounded by size class, per-class count, explicit drains, and the same quota.

All removed tests covered the deleted wrapper itself; replacement tests exercise real LocalFS, S3FS, DiskCache, and RemoteCache allocation paths, owner identity, full-capacity eviction, reservation release, and disabled-cache fallback. Exact-head UT, SCA, and multi-CN BVT CI is green. The steady-state path removes interface checks and one FileService delegation, so there is no performance regression or log amplification. No blocker found.

@mergify mergify Bot added the queued label Sep 5, 2026
@mergify

mergify Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-05 09:06 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-09-05 09:21 UTC · at 3845035b6d5e0547da1fa2cd48d58bd61808e8ff

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

Waiting for
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
    • check-success = Matrixone CI / SCA Test on Linux/arm64
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
All conditions
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
    • check-success = Matrixone CI / SCA Test on Linux/arm64
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]

Reason

Pull request #28182 has been dequeued

Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.

The author needs to enable "Allow edits from maintainers" on this pull request.

Failing checks:

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, 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

@XuPeng-SH
XuPeng-SH merged commit 0cee094 into matrixorigin:main Sep 5, 2026
24 of 25 checks passed
@mergify mergify Bot added dequeued and removed queued labels Sep 5, 2026
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…atrixorigin#28182)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Related to matrixorigin#27138

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

### Root cause

Memory Cache now reserves physical backing capacity before it allocates
cache data. The standard FileService factory nevertheless retained a
second capacity owner: DiskCache received the Memory Cache allocator and
a separate FIFO cache pointer which wrapped allocations in
`cacheCapacityGuardedAllocator` / `EnsureNBytes`. RemoteCache was also
given a FileService wrapper instead of the Memory Cache allocator
directly. These parallel mechanisms obscured the reservation owner and
made future double reservation or bypass regressions likely.

### Changes

- Make the factory construct Memory Cache before Remote Cache (after
preserving the invalid-remote-config validation), and wire DiskCache and
RemoteCache directly to the same `*MemCache` allocator.
- Remove DiskCache’s legacy FIFO capacity pointer, guarded allocator,
capacity-guard marker, and `ensureCacheDataCapacity`.
- Keep LocalFS and S3FS allocator delegation intact; their cache-owned
`Allocate`, `AllocateWithHint`, and `Copy` paths continue to enter
Memory Cache reservation.
- Keep ObjectIO column constructors on the FileService-injected
allocator. Its independent Default allocator use is only for generated
data that is not admitted to that FileService Memory Cache.

### Issue-to-test proof

- `TestFileServiceCacheDataAllocatorsReserveBackingCapacity` covers
LocalFS and S3FS `Allocate`, `AllocateWithHint`, and `Copy` at full
capacity.
- `TestDiskCacheReadUsesMemoryCacheReservation` fills the Memory Cache,
reads through DiskCache, verifies allocator identity, eviction before
allocation, backing-size reservation, owner identity, and release on
vector/flush.
- `TestRemoteCacheReadUsesMemoryCacheReservation` performs a validated
remote hit against a full Memory Cache and verifies the same ownership,
eviction, reservation, and release behavior.
- `TestFileServiceCachesUseMemoryCacheAllocator` verifies the standard
factory gives DiskCache and RemoteCache the one Memory Cache allocator.
- Existing reservation lifecycle tests cover rehome-before-copy, FIFO
usage commit, and duplicate insertion until data release. ObjectIO
cache/vector tests verify validation and cache-admission forwarding,
including remote column cache admission.

### Tests

- `make -j8 cgo`
- Focused FileService reservation tests
- `mo-cgo-test -count=1 -timeout=600s -skip "^TestMinioSDK$"
./pkg/fileservice`
- `mo-cgo-test -race -count=1 -timeout=600s -skip "^TestMinioSDK$"
./pkg/fileservice`
- `mo-cgo-test -race -count=100 -run
"^TestRemoteCacheReadUsesMemoryCacheReservation$" ./pkg/fileservice`
- `mo-cgo-test -run "Test.*(Cache|Vector)" ./pkg/objectio`

`TestMinioSDK/file_service/basic` was excluded only after reproducing
the same `Access Denied` response against the local MinIO endpoint from
an `origin/main` worktree.

### Residual risks

This refactor does not change backing-size accounting, eviction policy,
remote routing, or cache data layout. The changed boundary is exercised
with race tests; external MinIO authorization remains an environment
dependency.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…atrixorigin#28182)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Related to matrixorigin#27138

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

### Root cause

Memory Cache now reserves physical backing capacity before it allocates
cache data. The standard FileService factory nevertheless retained a
second capacity owner: DiskCache received the Memory Cache allocator and
a separate FIFO cache pointer which wrapped allocations in
`cacheCapacityGuardedAllocator` / `EnsureNBytes`. RemoteCache was also
given a FileService wrapper instead of the Memory Cache allocator
directly. These parallel mechanisms obscured the reservation owner and
made future double reservation or bypass regressions likely.

### Changes

- Make the factory construct Memory Cache before Remote Cache (after
preserving the invalid-remote-config validation), and wire DiskCache and
RemoteCache directly to the same `*MemCache` allocator.
- Remove DiskCache’s legacy FIFO capacity pointer, guarded allocator,
capacity-guard marker, and `ensureCacheDataCapacity`.
- Keep LocalFS and S3FS allocator delegation intact; their cache-owned
`Allocate`, `AllocateWithHint`, and `Copy` paths continue to enter
Memory Cache reservation.
- Keep ObjectIO column constructors on the FileService-injected
allocator. Its independent Default allocator use is only for generated
data that is not admitted to that FileService Memory Cache.

### Issue-to-test proof

- `TestFileServiceCacheDataAllocatorsReserveBackingCapacity` covers
LocalFS and S3FS `Allocate`, `AllocateWithHint`, and `Copy` at full
capacity.
- `TestDiskCacheReadUsesMemoryCacheReservation` fills the Memory Cache,
reads through DiskCache, verifies allocator identity, eviction before
allocation, backing-size reservation, owner identity, and release on
vector/flush.
- `TestRemoteCacheReadUsesMemoryCacheReservation` performs a validated
remote hit against a full Memory Cache and verifies the same ownership,
eviction, reservation, and release behavior.
- `TestFileServiceCachesUseMemoryCacheAllocator` verifies the standard
factory gives DiskCache and RemoteCache the one Memory Cache allocator.
- Existing reservation lifecycle tests cover rehome-before-copy, FIFO
usage commit, and duplicate insertion until data release. ObjectIO
cache/vector tests verify validation and cache-admission forwarding,
including remote column cache admission.

### Tests

- `make -j8 cgo`
- Focused FileService reservation tests
- `mo-cgo-test -count=1 -timeout=600s -skip "^TestMinioSDK$"
./pkg/fileservice`
- `mo-cgo-test -race -count=1 -timeout=600s -skip "^TestMinioSDK$"
./pkg/fileservice`
- `mo-cgo-test -race -count=100 -run
"^TestRemoteCacheReadUsesMemoryCacheReservation$" ./pkg/fileservice`
- `mo-cgo-test -run "Test.*(Cache|Vector)" ./pkg/objectio`

`TestMinioSDK/file_service/basic` was excluded only after reproducing
the same `Access Denied` response against the local MinIO endpoint from
an `origin/main` worktree.

### Residual risks

This refactor does not change backing-size accounting, eviction policy,
remote routing, or cache data layout. The changed boundary is exercised
with race tests; external MinIO authorization remains an environment
dependency.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…atrixorigin#28182)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Related to matrixorigin#27138

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

### Root cause

Memory Cache now reserves physical backing capacity before it allocates
cache data. The standard FileService factory nevertheless retained a
second capacity owner: DiskCache received the Memory Cache allocator and
a separate FIFO cache pointer which wrapped allocations in
`cacheCapacityGuardedAllocator` / `EnsureNBytes`. RemoteCache was also
given a FileService wrapper instead of the Memory Cache allocator
directly. These parallel mechanisms obscured the reservation owner and
made future double reservation or bypass regressions likely.

### Changes

- Make the factory construct Memory Cache before Remote Cache (after
preserving the invalid-remote-config validation), and wire DiskCache and
RemoteCache directly to the same `*MemCache` allocator.
- Remove DiskCache’s legacy FIFO capacity pointer, guarded allocator,
capacity-guard marker, and `ensureCacheDataCapacity`.
- Keep LocalFS and S3FS allocator delegation intact; their cache-owned
`Allocate`, `AllocateWithHint`, and `Copy` paths continue to enter
Memory Cache reservation.
- Keep ObjectIO column constructors on the FileService-injected
allocator. Its independent Default allocator use is only for generated
data that is not admitted to that FileService Memory Cache.

### Issue-to-test proof

- `TestFileServiceCacheDataAllocatorsReserveBackingCapacity` covers
LocalFS and S3FS `Allocate`, `AllocateWithHint`, and `Copy` at full
capacity.
- `TestDiskCacheReadUsesMemoryCacheReservation` fills the Memory Cache,
reads through DiskCache, verifies allocator identity, eviction before
allocation, backing-size reservation, owner identity, and release on
vector/flush.
- `TestRemoteCacheReadUsesMemoryCacheReservation` performs a validated
remote hit against a full Memory Cache and verifies the same ownership,
eviction, reservation, and release behavior.
- `TestFileServiceCachesUseMemoryCacheAllocator` verifies the standard
factory gives DiskCache and RemoteCache the one Memory Cache allocator.
- Existing reservation lifecycle tests cover rehome-before-copy, FIFO
usage commit, and duplicate insertion until data release. ObjectIO
cache/vector tests verify validation and cache-admission forwarding,
including remote column cache admission.

### Tests

- `make -j8 cgo`
- Focused FileService reservation tests
- `mo-cgo-test -count=1 -timeout=600s -skip "^TestMinioSDK$"
./pkg/fileservice`
- `mo-cgo-test -race -count=1 -timeout=600s -skip "^TestMinioSDK$"
./pkg/fileservice`
- `mo-cgo-test -race -count=100 -run
"^TestRemoteCacheReadUsesMemoryCacheReservation$" ./pkg/fileservice`
- `mo-cgo-test -run "Test.*(Cache|Vector)" ./pkg/objectio`

`TestMinioSDK/file_service/basic` was excluded only after reproducing
the same `Access Denied` response against the local MinIO endpoint from
an `origin/main` worktree.

### Residual risks

This refactor does not change backing-size accounting, eviction policy,
remote routing, or cache data layout. The changed boundary is exercised
with race tests; external MinIO authorization remains an environment
dependency.

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

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

kind/refactor Code refactor 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