Madan Jampani
Committed by Gerrit Code Review

ECMap: notify peers only for remove operations initiated locally

Change-Id: I67d66ec366759b8c96fbb686d1af01aa4eaaa83c
...@@ -316,6 +316,12 @@ public class EventuallyConsistentMapImpl<K, V> ...@@ -316,6 +316,12 @@ public class EventuallyConsistentMapImpl<K, V>
316 // TODO prevent calls here if value is important for timestamp 316 // TODO prevent calls here if value is important for timestamp
317 MapValue<V> tombstone = new MapValue<>(null, timestampProvider.apply(key, null)); 317 MapValue<V> tombstone = new MapValue<>(null, timestampProvider.apply(key, null));
318 MapValue<V> previousValue = removeInternal(key, Optional.empty(), tombstone); 318 MapValue<V> previousValue = removeInternal(key, Optional.empty(), tombstone);
319 + if (previousValue != null) {
320 + notifyPeers(new UpdateEntry<>(key, tombstone), peerUpdateFunction.apply(key, previousValue.get()));
321 + if (previousValue.isAlive()) {
322 + notifyListeners(new EventuallyConsistentMapEvent<>(REMOVE, key, previousValue.get()));
323 + }
324 + }
319 return previousValue != null ? previousValue.get() : null; 325 return previousValue != null ? previousValue.get() : null;
320 } 326 }
321 327
...@@ -325,7 +331,13 @@ public class EventuallyConsistentMapImpl<K, V> ...@@ -325,7 +331,13 @@ public class EventuallyConsistentMapImpl<K, V>
325 checkNotNull(key, ERROR_NULL_KEY); 331 checkNotNull(key, ERROR_NULL_KEY);
326 checkNotNull(value, ERROR_NULL_VALUE); 332 checkNotNull(value, ERROR_NULL_VALUE);
327 MapValue<V> tombstone = new MapValue<>(null, timestampProvider.apply(key, value)); 333 MapValue<V> tombstone = new MapValue<>(null, timestampProvider.apply(key, value));
328 - removeInternal(key, Optional.of(value), tombstone); 334 + MapValue<V> previousValue = removeInternal(key, Optional.of(value), tombstone);
335 + if (previousValue != null) {
336 + notifyPeers(new UpdateEntry<>(key, tombstone), peerUpdateFunction.apply(key, previousValue.get()));
337 + if (previousValue.isAlive()) {
338 + notifyListeners(new EventuallyConsistentMapEvent<>(REMOVE, key, previousValue.get()));
339 + }
340 + }
329 } 341 }
330 342
331 private MapValue<V> removeInternal(K key, Optional<V> value, MapValue<V> tombstone) { 343 private MapValue<V> removeInternal(K key, Optional<V> value, MapValue<V> tombstone) {
...@@ -348,10 +360,6 @@ public class EventuallyConsistentMapImpl<K, V> ...@@ -348,10 +360,6 @@ public class EventuallyConsistentMapImpl<K, V>
348 return updated.get() ? tombstone : existing; 360 return updated.get() ? tombstone : existing;
349 }); 361 });
350 if (updated.get()) { 362 if (updated.get()) {
351 - notifyPeers(new UpdateEntry<>(key, tombstone), peerUpdateFunction.apply(key, null));
352 - if (previousValue.get() != null && previousValue.get().isAlive()) {
353 - notifyListeners(new EventuallyConsistentMapEvent<>(REMOVE, key, previousValue.get().get()));
354 - }
355 if (persistent) { 363 if (persistent) {
356 persistentStore.update(key, tombstone); 364 persistentStore.update(key, tombstone);
357 } 365 }
...@@ -503,7 +511,7 @@ public class EventuallyConsistentMapImpl<K, V> ...@@ -503,7 +511,7 @@ public class EventuallyConsistentMapImpl<K, V>
503 peer) 511 peer)
504 .whenComplete((result, error) -> { 512 .whenComplete((result, error) -> {
505 if (error != null) { 513 if (error != null) {
506 - log.warn("Failed to send anti-entropy advertisement to {}", peer); 514 + log.debug("Failed to send anti-entropy advertisement to {}", peer, error);
507 } 515 }
508 }); 516 });
509 } 517 }
......