Skip to content
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

Fix race condition in TestThinCache #3198

Merged
merged 1 commit into from
Feb 21, 2025
Merged
Changes from all commits
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
23 changes: 19 additions & 4 deletions solr/core/src/test/org/apache/solr/search/ThinCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,25 @@ public void close() throws IOException {

@Override
public void onRemoval(K key, V value, RemovalCause cause) {
if (cause.wasEvicted()) {
evictions.increment();
}
local.remove(key);
// Only remove if the current value is the same as the removal.
// RemovalListener gives us no guarantee that onRemoval() will be called
// before the same key gets updated again.
// We are still not protecting against a removal then a put() with the
// same value in quick succession.
local.computeIfPresent(
key,
(keyEntry, valEntry) -> {
// Delete only if the value being deleted is the same as what we have locally
if (valEntry.ref.refersTo(value)) {
if (cause.wasEvicted()) {
evictions.increment();
}
return null;
} else {
// Otherwise keep the value in the map
return valEntry;
}
});
}

@Override
Expand Down
Loading