Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix issue #78: Race condition in InMemoryStorageEngine, patch by Dain…

… Sundstrom with slight modification from me.
  • Loading branch information...
commit 6568b055cbeea185ba688c3acd1a7a6102183f73 1 parent e44ec88
@ijuma ijuma authored
Showing with 11 additions and 2 deletions.
  1. +11 −2 src/java/voldemort/store/memory/InMemoryStorageEngine.java
View
13 src/java/voldemort/store/memory/InMemoryStorageEngine.java
@@ -83,8 +83,12 @@ public boolean delete(K key, Version version) {
deletedSomething = true;
}
}
- if(values.size() == 0)
- map.remove(key);
+ if(values.size() == 0) {
+ // If this remove fails, then another delete operation got
+ // there before this one
+ if(!map.remove(key, values))
+ return false;
+ }
return deletedSomething;
}
@@ -122,6 +126,11 @@ public void put(K key, Versioned<V> value) throws VoldemortException {
success = map.putIfAbsent(key, items) == null;
} else {
synchronized(items) {
+ // if this check fails, items has been removed from the map
+ // by delete, so we try again.
+ if(map.get(key) != items)
+ continue;
+
// Check for existing versions - remember which items to
// remove in case of success
List<Versioned<V>> itemsToRemove = new ArrayList<Versioned<V>>(items.size());
Please sign in to comment.
Something went wrong with that request. Please try again.