Repository navigation
fix: cap fileservice event logger during cache eviction - #24542
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? |
There was a problem hiding this comment.
Pull request overview
This PR mitigates a remaining CN OOM path under high-concurrency point-select reads by bounding per-request FileService slow-event logging and preventing cache-eviction callbacks from inflating a request-scoped event buffer during EnsureNBytes-driven evictions.
Changes:
- Cap per-request FileService event logger entries (drop after a fixed limit) and report the dropped count in slow-event logs.
- Strip the request-scoped event logger from contexts passed into memory-cache capacity eviction (
EnsureNBytes) so eviction/post-evict callbacks don’t amplify a single request’s event buffer. - Add unit tests covering event dropping at the limit and event-logger stripping behavior.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/fileservice/event_logger.go | Add event cap + dropped counter; add withoutEventLogger helper; avoid pooling oversized event slices; include dropped count in slow-event log. |
| pkg/fileservice/event_logger_test.go | Add tests for drop-after-limit and withoutEventLogger behavior. |
| pkg/fileservice/bytes.go | Ensure cache capacity checks (EnsureNBytes) run with event logger stripped from context. |
| pkg/fileservice/local_fs.go | Strip event logger from contexts passed into mem-cache EnsureNBytes during cache data allocation/copy. |
| pkg/fileservice/s3_fs.go | Strip event logger from contexts passed into mem-cache EnsureNBytes during cache data allocation/copy. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Reviewed the fix for event logger growth during cache eviction; the cap, dropped-event accounting, and event-logger suppression on EnsureNBytes paths look sound.
Merge Queue Status
This pull request spent 22 seconds in the queue, including 3 seconds running CI. Required conditions to merge
|
## Summary Fixes #24534. This follows the post-#24542 OOM evidence from the 4.0-dev nightly run: - `nightly-regression-dis-tp-cn-6t6mx` was OOMKilled during sysbench update-index 1000. - The image already included #24542, and Pyroscope no longer showed `fileservice.eventLogger.emit` as the dominant heap owner. - RSS reached hard pressure while `Workspace` observed the pressure, but only the CNFlushS3 throttler had RSS cache eviction configured. - SHARED memory cache was evicted once, then refilled back near its cap before the next RSS sample. ## Changes - Enable RSS scavenging/cache eviction on the default `Workspace` throttler, so hard RSS observed by workspace allocation paths can evict memory/meta caches to the hard target. - Add sticky pressure admission targets for fileservice memory cache and objectio metadata cache. - Keep stricter active targets from being loosened by later softer targets. - Skip memory/meta cache writes while a pressure target is active and the write would refill cache above that target. ## Tests - `GOCACHE=/private/tmp/matrixone-rss-cache-gocache go test ./pkg/fileservice -run 'TestMemoryCachePressureAdmission|TestMemoryCacheEvictToCapacityPercent'` Local broader package tests are blocked by existing environment dependencies: - `go test ./pkg/objectio ...` and `go test ./pkg/cnservice ...` fail during build because this machine is missing `usearch.h` and `xxhash.h`. - Full `pkg/fileservice` tests also hit sandbox networking restrictions in `httptest` listener setup.
## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue #24592 ## What this PR does / why we need it: This PR reverts the risky semantic changes from the previous RSS-pressure fixes, then restores only the minimal cache-pressure protection needed for high RSS: 1. Revert the prior cache/PK-path changes from #24535, #24542, and #24543 as a clean baseline. 2. Keep the low-risk fileservice event logger cap and strip request event logging from cache-capacity eviction before cache-data allocation. 3. Under RSS pressure, asynchronously evict fileservice memory cache and objectio metadata cache to a bounded target. 4. Run CN memory-cache and metadata-cache pressure eviction concurrently so one slow cache family cannot consume the shared pressure timeout and skip the other. 5. Keep a short pressure admission target so memory/meta cache writes do not immediately refill the just-evicted caches. 6. Do not change PK check concurrency behavior beyond reverting the risky metadata/BF/tombstone scope expansion. 7. Do not change tombstone, metadata, or bloom-filter read policy. 8. Keep foreground cache allocation from consuming global async eviction debt. 9. Add pressure logs and metrics for RSS trigger, cache eviction duration, and admission skips. The intended behavior is: - Normal RSS: no cache throttling or PK-path behavior change. - High RSS: background cache/meta eviction plus temporary cache-admission suppression. - Foreground reads/writes: no global PK semaphore expansion, no tombstone policy change, no metadata/BF policy change. ## Test ```text git diff --check git diff --check base/4.0-dev...HEAD GOCACHE=/private/tmp/mo-gocache go test ./pkg/fileservice/fifocache -run 'TestEvict|TestPostEvict|TestMemoryCache|TestCachePressure|TestEvictToTarget' -count=1 GOCACHE=/private/tmp/mo-gocache go test ./pkg/fileservice -run 'TestEventLogger|TestWithoutEventLogger|TestMemoryCache|TestDiskCacheReadEnsuresMemoryCacheCapacity' -count=1 GOCACHE=/private/tmp/mo-gocache go test ./pkg/objectio -run 'TestMetaCachePressure' -count=1 GOCACHE=/private/tmp/mo-gocache go test ./pkg/common/rscthrottler -run 'TestMemThrottlerRSS|TestAcquirePolicyForCNFlushS3|TestAcquirePolicyForDataBranch' -count=1 GOCACHE=/private/tmp/mo-gocache go test ./pkg/cnservice -run 'TestMakeRSSCacheEvictor|Test_InitServer|Test_tenant' -count=1 GOCACHE=/private/tmp/mo-gocache go test ./pkg/vm/engine/disttae -run 'TestTombstonePKExistsInRange|TestLinearSearchOffsetByValFactory' -count=1 GOCACHE=/private/tmp/mo-gocache go test ./pkg/vm/engine/disttae -run 'TestPKCheckSemaphore|TestTombstonePKExistsInRange' -count=1 ```
This PR ports the final minimal RSS cache pressure protection from #24612 to `main`. Background: - #24535 tried to reduce CN RSS pressure under TPCC/sysbench, but it mixed cache pressure handling with broader PK, tombstone, metadata, and BF read-path behavior changes. - #24542 added fileservice event logger capacity protection. - #24543 kept cache pressure admission targets active under high RSS. - #24612 reverted the risky mixed behavior on `4.0-dev` and restored only the smaller validated RSS cache pressure protection. `main` does not contain the risky #24535/#24542/#24543 commits, so this PR does not cherry-pick those revert commits. It ports the final net behavior directly: - cap fileservice event logger events; - avoid carrying request event logs into cache capacity eviction; - asynchronously trigger memory cache and metadata cache eviction under RSS pressure; - keep a short pressure admission TTL to prevent immediate cache refill; - keep foreground `EvictWithWait` from absorbing async eviction debt; - add cache pressure trigger / eviction / admission-skip / eviction-duration metrics; - run CN memory/meta cache family eviction concurrently with independent timeouts; - add focused coverage for cache admission, target eviction, event logger caps, RSS soft/hard target escalation, and CN concurrent eviction. One `main` port adjustment: - `tryScavengeRSS` captures the evictor and `freeOSMemory` hook before launching the async goroutine, preserving behavior while avoiding a race-detector issue in tests that replace the package-level hook. Validation: ```text GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/fileservice/fifocache -run 'TestEvict|TestPostEvict|TestMemoryCache|TestCachePressure|TestEvictToTarget' -count=1 GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/fileservice -run 'TestEventLogger|TestWithoutEventLogger|TestMemoryCache|TestDiskCacheReadEnsuresMemoryCacheCapacity' -count=1 GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/objectio -run 'TestMetaCachePressure' -count=1 GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/common/rscthrottler -run 'TestMemThrottlerRSS|TestAcquirePolicyForCNFlushS3|TestAcquirePolicyForDataBranch' -count=1 GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/cnservice -run 'TestMakeRSSCacheEvictor|Test_InitServer|Test_tenant' -count=1 GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/util/metric/v2 -run TestNonExistent -count=0 GOCACHE=/private/tmp/mo-gocache-main go test -race ./pkg/common/rscthrottler -run 'TestMemThrottlerRSSCacheEviction' -count=10 GOCACHE=/private/tmp/mo-gocache-main go test -race ./pkg/cnservice -run 'TestMakeRSSCacheEvictor' -count=10 git diff --check base/main...HEAD ``` Approved by: @gouhongshen, @XuPeng-SH, @aptend
…#24615) This PR ports the final minimal RSS cache pressure protection from matrixorigin#24612 to `main`. Background: - matrixorigin#24535 tried to reduce CN RSS pressure under TPCC/sysbench, but it mixed cache pressure handling with broader PK, tombstone, metadata, and BF read-path behavior changes. - matrixorigin#24542 added fileservice event logger capacity protection. - matrixorigin#24543 kept cache pressure admission targets active under high RSS. - matrixorigin#24612 reverted the risky mixed behavior on `4.0-dev` and restored only the smaller validated RSS cache pressure protection. `main` does not contain the risky matrixorigin#24535/matrixorigin#24542/matrixorigin#24543 commits, so this PR does not cherry-pick those revert commits. It ports the final net behavior directly: - cap fileservice event logger events; - avoid carrying request event logs into cache capacity eviction; - asynchronously trigger memory cache and metadata cache eviction under RSS pressure; - keep a short pressure admission TTL to prevent immediate cache refill; - keep foreground `EvictWithWait` from absorbing async eviction debt; - add cache pressure trigger / eviction / admission-skip / eviction-duration metrics; - run CN memory/meta cache family eviction concurrently with independent timeouts; - add focused coverage for cache admission, target eviction, event logger caps, RSS soft/hard target escalation, and CN concurrent eviction. One `main` port adjustment: - `tryScavengeRSS` captures the evictor and `freeOSMemory` hook before launching the async goroutine, preserving behavior while avoiding a race-detector issue in tests that replace the package-level hook. Validation: ```text GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/fileservice/fifocache -run 'TestEvict|TestPostEvict|TestMemoryCache|TestCachePressure|TestEvictToTarget' -count=1 GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/fileservice -run 'TestEventLogger|TestWithoutEventLogger|TestMemoryCache|TestDiskCacheReadEnsuresMemoryCacheCapacity' -count=1 GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/objectio -run 'TestMetaCachePressure' -count=1 GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/common/rscthrottler -run 'TestMemThrottlerRSS|TestAcquirePolicyForCNFlushS3|TestAcquirePolicyForDataBranch' -count=1 GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/cnservice -run 'TestMakeRSSCacheEvictor|Test_InitServer|Test_tenant' -count=1 GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/util/metric/v2 -run TestNonExistent -count=0 GOCACHE=/private/tmp/mo-gocache-main go test -race ./pkg/common/rscthrottler -run 'TestMemThrottlerRSSCacheEviction' -count=10 GOCACHE=/private/tmp/mo-gocache-main go test -race ./pkg/cnservice -run 'TestMakeRSSCacheEvictor' -count=10 git diff --check base/main...HEAD ``` Approved by: @gouhongshen, @XuPeng-SH, @aptend
…#24615) This PR ports the final minimal RSS cache pressure protection from matrixorigin#24612 to `main`. Background: - matrixorigin#24535 tried to reduce CN RSS pressure under TPCC/sysbench, but it mixed cache pressure handling with broader PK, tombstone, metadata, and BF read-path behavior changes. - matrixorigin#24542 added fileservice event logger capacity protection. - matrixorigin#24543 kept cache pressure admission targets active under high RSS. - matrixorigin#24612 reverted the risky mixed behavior on `4.0-dev` and restored only the smaller validated RSS cache pressure protection. `main` does not contain the risky matrixorigin#24535/matrixorigin#24542/matrixorigin#24543 commits, so this PR does not cherry-pick those revert commits. It ports the final net behavior directly: - cap fileservice event logger events; - avoid carrying request event logs into cache capacity eviction; - asynchronously trigger memory cache and metadata cache eviction under RSS pressure; - keep a short pressure admission TTL to prevent immediate cache refill; - keep foreground `EvictWithWait` from absorbing async eviction debt; - add cache pressure trigger / eviction / admission-skip / eviction-duration metrics; - run CN memory/meta cache family eviction concurrently with independent timeouts; - add focused coverage for cache admission, target eviction, event logger caps, RSS soft/hard target escalation, and CN concurrent eviction. One `main` port adjustment: - `tryScavengeRSS` captures the evictor and `freeOSMemory` hook before launching the async goroutine, preserving behavior while avoiding a race-detector issue in tests that replace the package-level hook. Validation: ```text GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/fileservice/fifocache -run 'TestEvict|TestPostEvict|TestMemoryCache|TestCachePressure|TestEvictToTarget' -count=1 GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/fileservice -run 'TestEventLogger|TestWithoutEventLogger|TestMemoryCache|TestDiskCacheReadEnsuresMemoryCacheCapacity' -count=1 GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/objectio -run 'TestMetaCachePressure' -count=1 GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/common/rscthrottler -run 'TestMemThrottlerRSS|TestAcquirePolicyForCNFlushS3|TestAcquirePolicyForDataBranch' -count=1 GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/cnservice -run 'TestMakeRSSCacheEvictor|Test_InitServer|Test_tenant' -count=1 GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/util/metric/v2 -run TestNonExistent -count=0 GOCACHE=/private/tmp/mo-gocache-main go test -race ./pkg/common/rscthrottler -run 'TestMemThrottlerRSSCacheEviction' -count=10 GOCACHE=/private/tmp/mo-gocache-main go test -race ./pkg/cnservice -run 'TestMakeRSSCacheEvictor' -count=10 git diff --check base/main...HEAD ``` Approved by: @gouhongshen, @XuPeng-SH, @aptend
…#24615) This PR ports the final minimal RSS cache pressure protection from matrixorigin#24612 to `main`. Background: - matrixorigin#24535 tried to reduce CN RSS pressure under TPCC/sysbench, but it mixed cache pressure handling with broader PK, tombstone, metadata, and BF read-path behavior changes. - matrixorigin#24542 added fileservice event logger capacity protection. - matrixorigin#24543 kept cache pressure admission targets active under high RSS. - matrixorigin#24612 reverted the risky mixed behavior on `4.0-dev` and restored only the smaller validated RSS cache pressure protection. `main` does not contain the risky matrixorigin#24535/matrixorigin#24542/matrixorigin#24543 commits, so this PR does not cherry-pick those revert commits. It ports the final net behavior directly: - cap fileservice event logger events; - avoid carrying request event logs into cache capacity eviction; - asynchronously trigger memory cache and metadata cache eviction under RSS pressure; - keep a short pressure admission TTL to prevent immediate cache refill; - keep foreground `EvictWithWait` from absorbing async eviction debt; - add cache pressure trigger / eviction / admission-skip / eviction-duration metrics; - run CN memory/meta cache family eviction concurrently with independent timeouts; - add focused coverage for cache admission, target eviction, event logger caps, RSS soft/hard target escalation, and CN concurrent eviction. One `main` port adjustment: - `tryScavengeRSS` captures the evictor and `freeOSMemory` hook before launching the async goroutine, preserving behavior while avoiding a race-detector issue in tests that replace the package-level hook. Validation: ```text GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/fileservice/fifocache -run 'TestEvict|TestPostEvict|TestMemoryCache|TestCachePressure|TestEvictToTarget' -count=1 GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/fileservice -run 'TestEventLogger|TestWithoutEventLogger|TestMemoryCache|TestDiskCacheReadEnsuresMemoryCacheCapacity' -count=1 GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/objectio -run 'TestMetaCachePressure' -count=1 GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/common/rscthrottler -run 'TestMemThrottlerRSS|TestAcquirePolicyForCNFlushS3|TestAcquirePolicyForDataBranch' -count=1 GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/cnservice -run 'TestMakeRSSCacheEvictor|Test_InitServer|Test_tenant' -count=1 GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/util/metric/v2 -run TestNonExistent -count=0 GOCACHE=/private/tmp/mo-gocache-main go test -race ./pkg/common/rscthrottler -run 'TestMemThrottlerRSSCacheEviction' -count=10 GOCACHE=/private/tmp/mo-gocache-main go test -race ./pkg/cnservice -run 'TestMakeRSSCacheEvictor' -count=10 git diff --check base/main...HEAD ``` Approved by: @gouhongshen, @XuPeng-SH, @aptend
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #24534
What this PR does / why we need it:
Follow-up to #24535 for the remaining CN OOM path seen in nightly regression.
The previous RSS cache-eviction fix does trigger and can evict SHARED memory
cache to the hard target, but high-concurrency point-select reads may still
enter
EnsureNBytes -> EvictWithWait -> runPendingPostEvictswhile carryingthe request-scoped fileservice event logger. Each evicted memory-cache entry
then appends post-evict events to the same slow-event buffer, amplifying Go heap
while the CN is already under RSS pressure.
This PR:
count in slow-event logs.
request event logger, so post-evict callbacks cannot inflate a single read
request's event buffer.
Validation: