Brian O'Connor

updates to EventuallyConsistenMapImpl to improve parallelism

Change-Id: I7bf29c02380f630e592d980d0795efc6ac13167a
...@@ -258,23 +258,28 @@ public class EventuallyConsistentMapImpl<K, V> ...@@ -258,23 +258,28 @@ public class EventuallyConsistentMapImpl<K, V>
258 } 258 }
259 259
260 private boolean putInternal(K key, V value, Timestamp timestamp) { 260 private boolean putInternal(K key, V value, Timestamp timestamp) {
261 - synchronized (this) { 261 + Timestamp removed = removedItems.get(key);
262 - Timestamp removed = removedItems.get(key); 262 + if (removed != null && removed.compareTo(timestamp) > 0) {
263 - if (removed != null && removed.compareTo(timestamp) > 0) { 263 + log.debug("ecmap - removed was newer {}", value);
264 - log.debug("ecmap - removed was newer {}", value); 264 + return false;
265 - return false; 265 + }
266 - }
267 266
267 + boolean success;
268 + synchronized (this) {
268 Timestamped<V> existing = items.get(key); 269 Timestamped<V> existing = items.get(key);
269 if (existing != null && existing.isNewer(timestamp)) { 270 if (existing != null && existing.isNewer(timestamp)) {
270 log.debug("ecmap - existing was newer {}", value); 271 log.debug("ecmap - existing was newer {}", value);
271 - return false; 272 + success = false;
272 } else { 273 } else {
273 items.put(key, new Timestamped<>(value, timestamp)); 274 items.put(key, new Timestamped<>(value, timestamp));
274 - removedItems.remove(key); 275 + success = true;
275 - return true;
276 } 276 }
277 } 277 }
278 +
279 + if (success && removed != null) {
280 + removedItems.remove(key, removed);
281 + }
282 + return success;
278 } 283 }
279 284
280 @Override 285 @Override
......
...@@ -77,6 +77,7 @@ public final class Timestamped<T> { ...@@ -77,6 +77,7 @@ public final class Timestamped<T> {
77 * @param other timestamp to compare against 77 * @param other timestamp to compare against
78 * @return true if this instance is newer 78 * @return true if this instance is newer
79 */ 79 */
80 + //TODO put this in Timestamp
80 public boolean isNewer(Timestamp other) { 81 public boolean isNewer(Timestamp other) {
81 return this.timestamp.compareTo(checkNotNull(other)) > 0; 82 return this.timestamp.compareTo(checkNotNull(other)) > 0;
82 } 83 }
......