Skip to content

test(fileservice): align cache hit assertion with async publication - #27520

Merged
XuPeng-SH merged 2 commits into
mainfrom
fix/issue-27519-disk-cache-test-contract
Aug 24, 2026
Merged

XuPeng-SH merged 2 commits into
mainfrom
fix/issue-27519-disk-cache-test-contract

Conversation

@XuPeng-SH

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Fixes #27519

What this PR does / why we need it:

The failing test combined two different contracts:

  • an async S3 read guarantees caller data and bounded disk-cache admission;
  • a disk-cache hit is guaranteed only after cache publication completes.

After #27368, full-object disk-cache finalization intentionally runs outside the caller-visible read generation. An immediate follower may wait for the bounded publication window and then fall back to object storage. The test still assumed the old synchronous behavior, so coverage scheduling could produce S3 Get / disk hit counters of 2 / 0 instead of 1 / 1.

This change waits on the public FlushCache publication barrier before asserting the later disk-cache hit. The barrier has the existing five-second lifecycle timeout, so a broken finalizer fails as a bounded hang instead of making the assertion scheduler-dependent.

The async production path, bounded follower fallback, cache scope, and hit assertions remain unchanged. No production code or hot path is modified.

First-principles test matrix

  • async admission before publication: existing deterministic blocked-finalizer tests continue to prove reads return and followers may fall back;
  • publication barrier: the fixed regression waits for durable publication before requiring a cache hit;
  • retained-buffer invariant: the first range result still must not retain the whole object buffer;
  • post-publication oracle: S3 Get remains 1 and disk hit becomes 1 without sleeps or retries.

Validation

  • focused regression: normal -count=100;
  • exact all-package coverage instrumentation with matrixone_test, -p 6, and the CI coverpkg scope: -count=10;
  • focused regression under race: measured 0.03s, 30s budget, adaptive cap -count=100;
  • async/sync IOMerger finalization control and async follower fallback control;
  • full pkg/fileservice suite in normal and race modes;
  • go build and go vet for pkg/fileservice;
  • git diff --check.

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

@XuPeng-SH

Copy link
Copy Markdown
Contributor Author

Deep review completed at a8ec4fa30dc7e67a62f0b62512ef4983531b4368: no blocking findings (approve-equivalent; GitHub does not permit self-approval because the author and reviewer are both XuPeng-SH).

Reviewed against base a4465b3846c770b8f3e2c313a624afd8534427da:

  • Correctness / completeness: the first full-object read reserves the async finalizer before returning; FlushCache waits for that pending generation to finish sync, publication, and index insertion before the disk-hit assertion. This closes the actual admission-vs-publication race instead of masking it with a sleep.
  • Unhappy paths / lifecycle: the wait is bounded by the existing 5s lifecycle test timeout and the timeout is asserted. No new goroutine, ownership edge, retry loop, or cleanup path is introduced. A cache publication failure remains fail-open in production and fails this test through the unchanged S3/disk counters.
  • Performance: test-only change; no production hot-path impact, no polling, and no additional object-buffer copy. The normal path only joins already-admitted async cache work.
  • Validation: focused test passed -count=100; focused race run passed -race -count=20; full ./pkg/fileservice package passed locally under the controlled CGo environment.

Non-blocking wording note: “a read ... guarantees cache admission” is broader than the global fail-open cache contract (admission can be rejected under capacity/close conditions), but it is true for this isolated test setup and does not affect the fix.

mergify Bot pushed a commit that referenced this pull request Aug 29, 2026
### Root cause

`DiskCache.loadCache` runs asynchronously during file-service initialization. It
removed every empty non-root directory while walking the cache tree. A concurrent
full-object cache fill creates its parent with `MkdirAll` and then calls
`CreateTemp`. If the loader removed that parent in between, the optional cache
write failed open and the S3 read fell back to a full-object buffer; a small
range then retained that entire backing allocation.

The historical #27520 issue is independent: it synchronized the later
post-publication cache-hit assertion. This failure is on the first range read
before that barrier.

### Changes

- Serialize startup empty-directory cleanup with the `MkdirAll` plus
`CreateTemp` critical section using a per-`DiskCache` `RWMutex`.
- Keep concurrent cache writers compatible with the shared lock. The loader
takes the exclusive lock only while attempting one empty-directory removal.
- Keep stale empty-directory cleanup; no new cache-directory retention path is
introduced.
- Add deterministic lifecycle coverage with instance-local barriers. It forces
the loader to reach cleanup while a foreground cache writer owns its parent
directory, then verifies temp-file creation succeeds. A stale empty-directory
control remains removable.

### Issue-to-test proof

- `TestDiskCacheLoadCacheKeepsForegroundDirectory` proves the exact
`MkdirAll -> loader cleanup -> CreateTemp` ownership boundary without sleeps:
the writer reaches the temporary-file phase under the shared lock, the loader
reaches directory cleanup, and only then is the writer released. The cache
temp file and its parent survive; a separate stale directory is removed.
- `TestS3FSFullObjectDiskCacheFillDoesNotRetainWholeObjectBuffer` covers the
consumer contract: the first seven-byte range from a 1 MiB object has bounded
capacity and one S3 Get; after `FlushCache`, a later range hits disk cache.

### Tests run

The branch was rebased without conflict onto `origin/main`
`7bb89155a2c43a3a97da0f0fb4d865fdf4855235`; the following were rerun on
`2232f3852c09cd11191fb047cb131e9bb7b3af6e`:

- Both issue-proving tests in CI-style coverage mode:
`-short -tags matrixone_test -covermode=set`.
- Both directly affected tests under `-race -count=100`.
- The full `TestDiskCache|TestS3FSFullObject` group with
`-short -tags matrixone_test`.
- `GOWORK=off go vet -mod=readonly -tags matrixone_test ./pkg/fileservice`.
- `git diff --check`.

The earlier CI-style coverage mode with the repository-wide `-coverpkg` scope
passed both selected tests and generated a profile with 89,738 lines. The
base-side commits incorporated by the rebases change only `pkg/fulltext2` and
`pkg/sql/plan`, not the fileservice code, dependencies, fixtures, or test modes
exercised here.

The normal and race `pkg/fileservice` package runs reached completion but failed
only at `TestMinioSDK/file_service` with `Access Denied` from the local MinIO
service. The same selected MinIO test fails with the same signature in an
isolated `origin/main` worktree, so it is unrelated to this diff.

### Residual risks

The loader can briefly wait for an in-progress parent-directory creation, but
the shared critical section contains only `MkdirAll` and `CreateTemp`; it does
not cover streaming, fsync, or publication. Cache writes retain their existing
fail-open behavior for real filesystem errors.

Approved by: @XuPeng-SH
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…atrixorigin#27520)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Fixes matrixorigin#27519

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

The failing test combined two different contracts:

- an async S3 read guarantees caller data and bounded disk-cache
admission;
- a disk-cache hit is guaranteed only after cache publication completes.

After matrixorigin#27368, full-object disk-cache finalization intentionally runs
outside the caller-visible read generation. An immediate follower may
wait for the bounded publication window and then fall back to object
storage. The test still assumed the old synchronous behavior, so
coverage scheduling could produce S3 Get / disk hit counters of 2 / 0
instead of 1 / 1.

This change waits on the public `FlushCache` publication barrier before
asserting the later disk-cache hit. The barrier has the existing
five-second lifecycle timeout, so a broken finalizer fails as a bounded
hang instead of making the assertion scheduler-dependent.

The async production path, bounded follower fallback, cache scope, and
hit assertions remain unchanged. No production code or hot path is
modified.

## First-principles test matrix

- async admission before publication: existing deterministic
blocked-finalizer tests continue to prove reads return and followers may
fall back;
- publication barrier: the fixed regression waits for durable
publication before requiring a cache hit;
- retained-buffer invariant: the first range result still must not
retain the whole object buffer;
- post-publication oracle: S3 Get remains 1 and disk hit becomes 1
without sleeps or retries.

## Validation

- focused regression: normal `-count=100`;
- exact all-package coverage instrumentation with `matrixone_test`, `-p
6`, and the CI `coverpkg` scope: `-count=10`;
- focused regression under race: measured 0.03s, 30s budget, adaptive
cap `-count=100`;
- async/sync IOMerger finalization control and async follower fallback
control;
- full `pkg/fileservice` suite in normal and race modes;
- `go build` and `go vet` for `pkg/fileservice`;
- `git diff --check`.
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…n#27840)

### Root cause

`DiskCache.loadCache` runs asynchronously during file-service initialization. It
removed every empty non-root directory while walking the cache tree. A concurrent
full-object cache fill creates its parent with `MkdirAll` and then calls
`CreateTemp`. If the loader removed that parent in between, the optional cache
write failed open and the S3 read fell back to a full-object buffer; a small
range then retained that entire backing allocation.

The historical matrixorigin#27520 issue is independent: it synchronized the later
post-publication cache-hit assertion. This failure is on the first range read
before that barrier.

### Changes

- Serialize startup empty-directory cleanup with the `MkdirAll` plus
`CreateTemp` critical section using a per-`DiskCache` `RWMutex`.
- Keep concurrent cache writers compatible with the shared lock. The loader
takes the exclusive lock only while attempting one empty-directory removal.
- Keep stale empty-directory cleanup; no new cache-directory retention path is
introduced.
- Add deterministic lifecycle coverage with instance-local barriers. It forces
the loader to reach cleanup while a foreground cache writer owns its parent
directory, then verifies temp-file creation succeeds. A stale empty-directory
control remains removable.

### Issue-to-test proof

- `TestDiskCacheLoadCacheKeepsForegroundDirectory` proves the exact
`MkdirAll -> loader cleanup -> CreateTemp` ownership boundary without sleeps:
the writer reaches the temporary-file phase under the shared lock, the loader
reaches directory cleanup, and only then is the writer released. The cache
temp file and its parent survive; a separate stale directory is removed.
- `TestS3FSFullObjectDiskCacheFillDoesNotRetainWholeObjectBuffer` covers the
consumer contract: the first seven-byte range from a 1 MiB object has bounded
capacity and one S3 Get; after `FlushCache`, a later range hits disk cache.

### Tests run

The branch was rebased without conflict onto `origin/main`
`7bb89155a2c43a3a97da0f0fb4d865fdf4855235`; the following were rerun on
`2232f3852c09cd11191fb047cb131e9bb7b3af6e`:

- Both issue-proving tests in CI-style coverage mode:
`-short -tags matrixone_test -covermode=set`.
- Both directly affected tests under `-race -count=100`.
- The full `TestDiskCache|TestS3FSFullObject` group with
`-short -tags matrixone_test`.
- `GOWORK=off go vet -mod=readonly -tags matrixone_test ./pkg/fileservice`.
- `git diff --check`.

The earlier CI-style coverage mode with the repository-wide `-coverpkg` scope
passed both selected tests and generated a profile with 89,738 lines. The
base-side commits incorporated by the rebases change only `pkg/fulltext2` and
`pkg/sql/plan`, not the fileservice code, dependencies, fixtures, or test modes
exercised here.

The normal and race `pkg/fileservice` package runs reached completion but failed
only at `TestMinioSDK/file_service` with `Access Denied` from the local MinIO
service. The same selected MinIO test fails with the same signature in an
isolated `origin/main` worktree, so it is unrelated to this diff.

### Residual risks

The loader can briefly wait for an in-progress parent-directory creation, but
the shared critical section contains only `MkdirAll` and `CreateTemp`; it does
not cover streaming, fsync, or publication. Cache writes retain their existing
fail-open behavior for real filesystem errors.

Approved by: @XuPeng-SH
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…atrixorigin#27520)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Fixes matrixorigin#27519

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

The failing test combined two different contracts:

- an async S3 read guarantees caller data and bounded disk-cache
admission;
- a disk-cache hit is guaranteed only after cache publication completes.

After matrixorigin#27368, full-object disk-cache finalization intentionally runs
outside the caller-visible read generation. An immediate follower may
wait for the bounded publication window and then fall back to object
storage. The test still assumed the old synchronous behavior, so
coverage scheduling could produce S3 Get / disk hit counters of 2 / 0
instead of 1 / 1.

This change waits on the public `FlushCache` publication barrier before
asserting the later disk-cache hit. The barrier has the existing
five-second lifecycle timeout, so a broken finalizer fails as a bounded
hang instead of making the assertion scheduler-dependent.

The async production path, bounded follower fallback, cache scope, and
hit assertions remain unchanged. No production code or hot path is
modified.

## First-principles test matrix

- async admission before publication: existing deterministic
blocked-finalizer tests continue to prove reads return and followers may
fall back;
- publication barrier: the fixed regression waits for durable
publication before requiring a cache hit;
- retained-buffer invariant: the first range result still must not
retain the whole object buffer;
- post-publication oracle: S3 Get remains 1 and disk hit becomes 1
without sleeps or retries.

## Validation

- focused regression: normal `-count=100`;
- exact all-package coverage instrumentation with `matrixone_test`, `-p
6`, and the CI `coverpkg` scope: `-count=10`;
- focused regression under race: measured 0.03s, 30s budget, adaptive
cap `-count=100`;
- async/sync IOMerger finalization control and async follower fallback
control;
- full `pkg/fileservice` suite in normal and race modes;
- `go build` and `go vet` for `pkg/fileservice`;
- `git diff --check`.
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…n#27840)

### Root cause

`DiskCache.loadCache` runs asynchronously during file-service initialization. It
removed every empty non-root directory while walking the cache tree. A concurrent
full-object cache fill creates its parent with `MkdirAll` and then calls
`CreateTemp`. If the loader removed that parent in between, the optional cache
write failed open and the S3 read fell back to a full-object buffer; a small
range then retained that entire backing allocation.

The historical matrixorigin#27520 issue is independent: it synchronized the later
post-publication cache-hit assertion. This failure is on the first range read
before that barrier.

### Changes

- Serialize startup empty-directory cleanup with the `MkdirAll` plus
`CreateTemp` critical section using a per-`DiskCache` `RWMutex`.
- Keep concurrent cache writers compatible with the shared lock. The loader
takes the exclusive lock only while attempting one empty-directory removal.
- Keep stale empty-directory cleanup; no new cache-directory retention path is
introduced.
- Add deterministic lifecycle coverage with instance-local barriers. It forces
the loader to reach cleanup while a foreground cache writer owns its parent
directory, then verifies temp-file creation succeeds. A stale empty-directory
control remains removable.

### Issue-to-test proof

- `TestDiskCacheLoadCacheKeepsForegroundDirectory` proves the exact
`MkdirAll -> loader cleanup -> CreateTemp` ownership boundary without sleeps:
the writer reaches the temporary-file phase under the shared lock, the loader
reaches directory cleanup, and only then is the writer released. The cache
temp file and its parent survive; a separate stale directory is removed.
- `TestS3FSFullObjectDiskCacheFillDoesNotRetainWholeObjectBuffer` covers the
consumer contract: the first seven-byte range from a 1 MiB object has bounded
capacity and one S3 Get; after `FlushCache`, a later range hits disk cache.

### Tests run

The branch was rebased without conflict onto `origin/main`
`7bb89155a2c43a3a97da0f0fb4d865fdf4855235`; the following were rerun on
`2232f3852c09cd11191fb047cb131e9bb7b3af6e`:

- Both issue-proving tests in CI-style coverage mode:
`-short -tags matrixone_test -covermode=set`.
- Both directly affected tests under `-race -count=100`.
- The full `TestDiskCache|TestS3FSFullObject` group with
`-short -tags matrixone_test`.
- `GOWORK=off go vet -mod=readonly -tags matrixone_test ./pkg/fileservice`.
- `git diff --check`.

The earlier CI-style coverage mode with the repository-wide `-coverpkg` scope
passed both selected tests and generated a profile with 89,738 lines. The
base-side commits incorporated by the rebases change only `pkg/fulltext2` and
`pkg/sql/plan`, not the fileservice code, dependencies, fixtures, or test modes
exercised here.

The normal and race `pkg/fileservice` package runs reached completion but failed
only at `TestMinioSDK/file_service` with `Access Denied` from the local MinIO
service. The same selected MinIO test fails with the same signature in an
isolated `origin/main` worktree, so it is unrelated to this diff.

### Residual risks

The loader can briefly wait for an in-progress parent-directory creation, but
the shared critical section contains only `MkdirAll` and `CreateTemp`; it does
not cover streaming, fsync, or publication. Cache writes retain their existing
fail-open behavior for real filesystem errors.

Approved by: @XuPeng-SH
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…atrixorigin#27520)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Fixes matrixorigin#27519

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

The failing test combined two different contracts:

- an async S3 read guarantees caller data and bounded disk-cache
admission;
- a disk-cache hit is guaranteed only after cache publication completes.

After matrixorigin#27368, full-object disk-cache finalization intentionally runs
outside the caller-visible read generation. An immediate follower may
wait for the bounded publication window and then fall back to object
storage. The test still assumed the old synchronous behavior, so
coverage scheduling could produce S3 Get / disk hit counters of 2 / 0
instead of 1 / 1.

This change waits on the public `FlushCache` publication barrier before
asserting the later disk-cache hit. The barrier has the existing
five-second lifecycle timeout, so a broken finalizer fails as a bounded
hang instead of making the assertion scheduler-dependent.

The async production path, bounded follower fallback, cache scope, and
hit assertions remain unchanged. No production code or hot path is
modified.

## First-principles test matrix

- async admission before publication: existing deterministic
blocked-finalizer tests continue to prove reads return and followers may
fall back;
- publication barrier: the fixed regression waits for durable
publication before requiring a cache hit;
- retained-buffer invariant: the first range result still must not
retain the whole object buffer;
- post-publication oracle: S3 Get remains 1 and disk hit becomes 1
without sleeps or retries.

## Validation

- focused regression: normal `-count=100`;
- exact all-package coverage instrumentation with `matrixone_test`, `-p
6`, and the CI `coverpkg` scope: `-count=10`;
- focused regression under race: measured 0.03s, 30s budget, adaptive
cap `-count=100`;
- async/sync IOMerger finalization control and async follower fallback
control;
- full `pkg/fileservice` suite in normal and race modes;
- `go build` and `go vet` for `pkg/fileservice`;
- `git diff --check`.
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…n#27840)

### Root cause

`DiskCache.loadCache` runs asynchronously during file-service initialization. It
removed every empty non-root directory while walking the cache tree. A concurrent
full-object cache fill creates its parent with `MkdirAll` and then calls
`CreateTemp`. If the loader removed that parent in between, the optional cache
write failed open and the S3 read fell back to a full-object buffer; a small
range then retained that entire backing allocation.

The historical matrixorigin#27520 issue is independent: it synchronized the later
post-publication cache-hit assertion. This failure is on the first range read
before that barrier.

### Changes

- Serialize startup empty-directory cleanup with the `MkdirAll` plus
`CreateTemp` critical section using a per-`DiskCache` `RWMutex`.
- Keep concurrent cache writers compatible with the shared lock. The loader
takes the exclusive lock only while attempting one empty-directory removal.
- Keep stale empty-directory cleanup; no new cache-directory retention path is
introduced.
- Add deterministic lifecycle coverage with instance-local barriers. It forces
the loader to reach cleanup while a foreground cache writer owns its parent
directory, then verifies temp-file creation succeeds. A stale empty-directory
control remains removable.

### Issue-to-test proof

- `TestDiskCacheLoadCacheKeepsForegroundDirectory` proves the exact
`MkdirAll -> loader cleanup -> CreateTemp` ownership boundary without sleeps:
the writer reaches the temporary-file phase under the shared lock, the loader
reaches directory cleanup, and only then is the writer released. The cache
temp file and its parent survive; a separate stale directory is removed.
- `TestS3FSFullObjectDiskCacheFillDoesNotRetainWholeObjectBuffer` covers the
consumer contract: the first seven-byte range from a 1 MiB object has bounded
capacity and one S3 Get; after `FlushCache`, a later range hits disk cache.

### Tests run

The branch was rebased without conflict onto `origin/main`
`7bb89155a2c43a3a97da0f0fb4d865fdf4855235`; the following were rerun on
`2232f3852c09cd11191fb047cb131e9bb7b3af6e`:

- Both issue-proving tests in CI-style coverage mode:
`-short -tags matrixone_test -covermode=set`.
- Both directly affected tests under `-race -count=100`.
- The full `TestDiskCache|TestS3FSFullObject` group with
`-short -tags matrixone_test`.
- `GOWORK=off go vet -mod=readonly -tags matrixone_test ./pkg/fileservice`.
- `git diff --check`.

The earlier CI-style coverage mode with the repository-wide `-coverpkg` scope
passed both selected tests and generated a profile with 89,738 lines. The
base-side commits incorporated by the rebases change only `pkg/fulltext2` and
`pkg/sql/plan`, not the fileservice code, dependencies, fixtures, or test modes
exercised here.

The normal and race `pkg/fileservice` package runs reached completion but failed
only at `TestMinioSDK/file_service` with `Access Denied` from the local MinIO
service. The same selected MinIO test fails with the same signature in an
isolated `origin/main` worktree, so it is unrelated to this diff.

### Residual risks

The loader can briefly wait for an in-progress parent-directory creation, but
the shared critical section contains only `MkdirAll` and `CreateTemp`; it does
not cover streaming, fsync, or publication. Cache writes retain their existing
fail-open behavior for real filesystem errors.

Approved by: @XuPeng-SH

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/bug Something isn't working kind/test-ci size/XS Denotes a PR that changes [1, 9] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: TestS3FSFullObjectDiskCacheFillDoesNotRetainWholeObjectBuffer flakes in UT coverage

2 participants