ECMap: synchronization free removeInternal
Change-Id: I89b88d11b830de5ceb97fdc3fb91ae51bc1bb1cb
diff --git a/core/store/dist/src/main/java/org/onosproject/store/ecmap/EventuallyConsistentMapImpl.java b/core/store/dist/src/main/java/org/onosproject/store/ecmap/EventuallyConsistentMapImpl.java
index c08246e..51e5147 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/ecmap/EventuallyConsistentMapImpl.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/ecmap/EventuallyConsistentMapImpl.java
@@ -295,14 +295,22 @@
}
private boolean removeInternal(K key, Timestamp timestamp) {
- synchronized (this) {
- if (items.get(key) != null && items.get(key).isNewer(timestamp)) {
+ Timestamped<V> value = items.get(key);
+ if (value != null) {
+ if (value.isNewer(timestamp)) {
return false;
+ } else {
+ items.remove(key, value);
}
+ }
- items.remove(key);
- removedItems.put(key, timestamp);
- return true;
+ Timestamp removedTimestamp = removedItems.get(key);
+ if (removedTimestamp == null) {
+ return removedItems.putIfAbsent(key, timestamp) == null;
+ } else if (timestamp.compareTo(removedTimestamp) > 0) {
+ return removedItems.replace(key, removedTimestamp, timestamp);
+ } else {
+ return false;
}
}