Skip to content

CBG-4734: fix for race when removing a value that is being loaded into rev cache #7640

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

Merged
merged 3 commits into from
Aug 1, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions db/revision_cache_lru.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,16 @@ func (rc *LRURevisionCache) removeFromCacheByCV(ctx context.Context, docID strin
}
// grab the revid key from the value to enable us to remove the reference from the rev lookup map too
elem := element.Value.(*revCacheValue)

// we can only remove this value if the value has finished loading from the bucket
_, _ = base.RetryLoop(ctx, "remove from revision cache by rev", func() (shouldRetry bool, err error, _ any) {
if !elem.canEvict.Load() {
// value is still in process of being loaded from bucket, we need to wait for this to finish
return true, nil, nil
}
return false, nil, nil
}, base.CreateMaxDoublingSleeperFunc(30, 10, 500))

legacyKey := IDAndRev{DocID: docID, RevID: elem.revID, CollectionID: collectionID}
rc.lruList.Remove(element)
delete(rc.hlvCache, key)
Expand All @@ -538,6 +548,16 @@ func (rc *LRURevisionCache) removeFromCacheByRev(ctx context.Context, docID, rev
}
// grab the cv key from the value to enable us to remove the reference from the rev lookup map too
elem := element.Value.(*revCacheValue)

// we can only remove this value if the value has finished loading from the bucket
_, _ = base.RetryLoop(ctx, "remove from revision cache by rev", func() (shouldRetry bool, err error, _ any) {
if !elem.canEvict.Load() {
// value is still in process of being loaded from bucket, we need to wait for this to finish
return true, nil, nil
}
return false, nil, nil
}, base.CreateMaxDoublingSleeperFunc(30, 10, 500))

hlvKey := IDandCV{DocID: docID, Source: elem.cv.SourceID, Version: elem.cv.Value, CollectionID: collectionID}
rc.lruList.Remove(element)
// decrement the overall memory bytes count
Expand Down
Loading