-
Notifications
You must be signed in to change notification settings - Fork 140
CBG-5020: fix panic in eviction based on out of sync stats #7895
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR addresses a panic in the revision cache eviction logic when memory statistics become out of sync with the actual cache state. The fix adds defensive checks when performing type assertions and introduces safeguards to detect and correct inconsistent memory statistics.
Key changes:
- Added defensive type assertion checks in cache removal operations
- Implemented detection and correction of inconsistent memory statistics during eviction
- Refactored locking to use defer statements for safer unlock behavior
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| db/revision_cache_lru.go | Added type assertion checks, moved to defer-based locking, and added logic to detect/correct inconsistent memory stats during eviction |
| db/revision_cache_test.go | Added test case to reproduce and verify the fix for the panic scenario with out-of-sync stats |
| correctionVal := rc.currMemoryUsage.Value() | ||
| rc.currMemoryUsage.Add(-correctionVal) | ||
| rc.cacheMemoryBytesStat.Add(-correctionVal) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be much clearer and potentially safer to use Set(0) for this than doing two separate Value and Add IMO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have changed this, I have added some comments on this area, we can;t quite set cacheMemoryBytesStat to 0 given this is the memory usage across all shards.
CBG-5020
Pre-review checklist
fmt.Print,log.Print, ...)base.UD(docID),base.MD(dbName))docs/apiDependencies (if applicable)
Integration Tests
GSI=true,xattrs=truehttps://jenkins.sgwdev.com/job/SyncGatewayIntegration/173/