Repository navigation
fix: port minimal RSS cache pressure protection to main - #24615
mergify[bot] merged 5 commits into
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 ports the “minimal, validated” CN RSS cache-pressure protection to main, focusing on preventing cache-refill and request-scoped event logger amplification under high RSS by adding bounded, asynchronous cache eviction plus short-lived admission suppression.
Changes:
- Add RSS-driven cache pressure eviction hooks to
rscthrottlerand wire them into CN service and DistTAE workspace throttlers, evicting memory/meta cache families concurrently with timeouts. - Add cache pressure admission targets (TTL-based) for fileservice memory cache and objectio metadata cache, plus target-based eviction APIs and accompanying tests.
- Cap fileservice event logger growth and ensure cache-capacity eviction (
EnsureNBytes/evict callbacks) doesn’t append into request-scoped event logs; add pressure-related Prometheus metrics.
Reviewed changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/vm/engine/disttae/engine.go | Enables RSS scavenging + cache-family eviction for the workspace mem throttler. |
| pkg/common/rscthrottler/resource_throttler.go | Adds RSS cache-eviction triggering (soft/hard thresholds), async eviction invocation, and trigger logging/metrics. |
| pkg/common/rscthrottler/resource_throttler_test.go | Adds tests for RSS-rate-based cache eviction and concurrent escalation behavior. |
| pkg/cnservice/server.go | Wires CNFlushS3 throttler to RSS cache evictor running memory/meta eviction concurrently. |
| pkg/cnservice/server_test.go | Tests that RSS cache evictor runs memory/meta eviction concurrently. |
| pkg/fileservice/event_logger.go | Caps per-request event log entries, tracks dropped count, and adds a context helper to strip the logger. |
| pkg/fileservice/event_logger_test.go | Adds tests for event dropping and logger stripping behavior. |
| pkg/fileservice/s3_fs.go | Strips event logger from cache-capacity eviction before cache allocation. |
| pkg/fileservice/local_fs.go | Strips event logger from cache-capacity eviction before cache allocation. |
| pkg/fileservice/bytes.go | Strips event logger from cache-capacity eviction in guarded allocators. |
| pkg/fileservice/mem_cache.go | Adds memory-cache pressure admission target (TTL), skip-on-pressure writes, and target-based eviction helpers. |
| pkg/fileservice/mem_cache_test.go | Adds tests for target eviction and admission skip/expiry for memory cache. |
| pkg/fileservice/cache.go | Adds “evict memory caches to capacity percent” API with logging + pressure metrics. |
| pkg/fileservice/fscache/data_cache.go | Extends DataCache interface with EvictToTargetWithWait. |
| pkg/fileservice/fifocache/fifo.go | Adds admission target support, target-based eviction APIs, and batched eviction-with-wait semantics. |
| pkg/fileservice/fifocache/fifo_test.go | Adds tests for atomic admission and target-eviction behavior under cancellation/hot promotion. |
| pkg/fileservice/fifocache/data_cache.go | Plumbs admission targets and target-based eviction into the data-cache wrapper. |
| pkg/fileservice/disk_cache_test.go | Updates a test DataCache stub to satisfy the extended interface. |
| pkg/objectio/cache.go | Adds metadata-cache pressure admission target + TTL handling and target-based eviction with metrics/logs. |
| pkg/objectio/meta_test.go | Adds tests for metadata cache target eviction and pressure admission skip/expiry. |
| pkg/util/metric/v2/fileservice.go | Introduces cache-pressure counters and eviction-duration histograms. |
| pkg/util/metric/v2/metrics.go | Registers the new file service cache-pressure metrics with the v2 registry. |
gouhongshen
left a comment
There was a problem hiding this comment.
🔍 Code Review Report — PR #24615
fix: port minimal RSS cache pressure protection to main
📊 Overview
| Metric | Value |
|---|---|
| Files Reviewed | 22 |
| 🔴 Must Fix | 0 |
| 🟡 Should Fix | 1 |
| 🟢 Nit | 2 |
| 🧨 Destructive Test Verdict | Adequate |
📝 Summary
This is a clean port of already-validated RSS cache pressure protection from #24612. The commit history is tight (4 commits: impl → tests → concurrent eviction → race fix), no patch-on-patch chain. The core mechanism — 3-tier RSS pressure detection (soft 85% → evict to 80%, hard 92% → evict to 50%) with async concurrent cache family eviction — is well-designed. Admission gating prevents immediate cache refill under pressure. Test coverage is excellent with dedicated tests for pressure admission atomicity, target escalation, concurrent escalation, TTL expiry, event logger caps, and ctx-cancel safety.
🧨 Destructive Test Verdict: Adequate
Covered failure modes:
- ✅ Concurrent admission gating (100 goroutines,
TestCachePressureAdmissionIsAtomic) - ✅ Concurrent RSS escalation (
TestMemThrottlerRSSCacheEvictionConcurrentEscalation) - ✅ Context cancel during eviction (
TestEvictToTargetWithWaitReturnsActualUsedOnContextCancel) - ✅ Pressure target TTL expiry (
TestMemoryCachePressureAdmissionExpires) - ✅ Admission write-skip above target (
TestMemoryCachePressureAdmissionSkipsWritesAboveTarget) - ✅ Event logger cap + pool cleanup (
TestEventLoggerDropsAfterLimit) - ✅ Race-free hook capture in async goroutine (commit
501a755)
Notable gaps (acceptable for port PR):
- No chaos/integration test with real RSS growth — validated on
4.0-devbranch - No per-cache-family eviction timeout exceeded scenario
🟡 Should Fix
1. Duplicated evictor factory between cnservice and disttae — server.go + engine.go
- Category: Code Health (重复逻辑)
- Description:
makeRSSCacheEvictor(cnservice) andmakeWorkspaceRSSCacheEvictor(disttae) are near-identical — same 2-minute admission TTL, same concurrent eviction pattern, same timeout wrapping. Only differences are constant names (rssCacheFamilyEvictTimeoutvsworkspaceRSSCacheFamilyEvictTimeout) and a function indirection (evictMemoryCachesToCapacityPercentvar vs direct call). - Fix: Extract a shared
MakeRSSCacheFamilyEvictor(timeout time.Duration, admissionTTL time.Duration) func(context.Context, int64)inpkg/fileserviceor a small shared utility, and both callers pass their constants.
🟢 Nit
2. tryScavengeRSS may double-call freeOSMemory — resource_throttler.go:258-269
- When
shouldEvictCacheANDshouldFreeOSMemoryare both true,freeOSMemoryis called once directly and once in the goroutine post-eviction. Harmless (2debug.FreeOSMemory()calls are idempotent), but the goroutinefree()call alone suffices. - Suggestion: When
shouldEvictCacheis true, skip the explicitshouldFreeOSMemoryblock — the goroutine already callsfree().
3. set() return type change to (*_CacheItem, *_CacheItem) — fifo.go:721-748
- Returning
*_CacheItemfor replaced ghost instead ofboolis an internal API change that enablesrollbackRejectedSetto restore ghosts. Correct, but the comment on line 721 could briefly note why the return type changed (for admission rollback support), rather than silently changing a private method signature.
💬 Commit Health
| Commit | Analysis |
|---|---|
e73dbd6 "fix: restore rss cache pressure protection" |
✅ Core implementation |
a0c8741 "test: keep rss cache pressure coverage" |
✅ Test suite |
d9d8130 "fix: run rss cache family eviction concurrently" |
✅ Refinement (concurrent eviction) |
501a755 "fix: avoid rss scavenger hook race" |
✅ Race fix (capture hooks before goroutine) |
Verdict: Clean commit history, no patch chain. The 4 commits represent logical incremental refinement, not bug-fixing-on-bug-fixing.
Review: Clean port PR. No blocking issues. Approve recommended.
gouhongshen
left a comment
There was a problem hiding this comment.
Clean port of validated RSS cache pressure protection. No blocking issues — well-designed admission gating, solid test coverage, clean commit history. LGTM 🚀
XuPeng-SH
left a comment
There was a problem hiding this comment.
I re-checked this PR from multiple angles and I don't see a blocking issue.
The main runtime paths line up: RSS pressure detection and escalation are consistent, CN/workspace cache-family eviction runs concurrently with independent timeouts, memory/meta cache admission suppression is short-lived and target-based, and the event-logger stripping avoids request-log amplification during cache-capacity eviction. The race fix in tryScavengeRSS also looks correct for the async path on main.
I also don't see a correctness gap in the eviction/admission mechanics themselves: EvictToTargetWithWait is wired through consistently, foreground eviction no longer absorbs async debt, and the focused tests cover the concurrency and rollback cases that matter here.
Merge Queue Status
This pull request spent 1 hour 2 minutes 10 seconds in the queue, including 1 hour 1 minute 29 seconds running CI. Required conditions to merge
|
…#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:
Closes #24617
What this PR does / why we need it:
This PR ports the final minimal RSS cache pressure protection from #24612 to
main.Background:
4.0-devand restored only the smaller validated RSS cache pressure protection.maindoes 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:EvictWithWaitfrom absorbing async eviction debt;One
mainport adjustment:tryScavengeRSScaptures the evictor andfreeOSMemoryhook before launching the async goroutine, preserving behavior while avoiding a race-detector issue in tests that replace the package-level hook.Validation: