Repository navigation
test(fileservice): align cache hit assertion with async publication - #27520
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? |
|
Deep review completed at Reviewed against base
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. |
### 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
…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`.
…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
…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`.
…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
…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`.
…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
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #27519
What this PR does / why we need it:
The failing test combined two different contracts:
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
FlushCachepublication 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
Validation
-count=100;matrixone_test,-p 6, and the CIcoverpkgscope:-count=10;-count=100;pkg/fileservicesuite in normal and race modes;go buildandgo vetforpkg/fileservice;git diff --check.