Committed by
Brian O'Connor
Move sending advertisement outside synchronized block
Change-Id: I1709fecbec5e6f5ac245b535c14a5c0b2aea2820
Showing
1 changed file
with
11 additions
and
7 deletions
... | @@ -530,10 +530,9 @@ public class EventuallyConsistentMapImpl<K, V> | ... | @@ -530,10 +530,9 @@ public class EventuallyConsistentMapImpl<K, V> |
530 | 530 | ||
531 | private void handleAntiEntropyAdvertisement(AntiEntropyAdvertisement<K> ad) { | 531 | private void handleAntiEntropyAdvertisement(AntiEntropyAdvertisement<K> ad) { |
532 | List<EventuallyConsistentMapEvent<K, V>> externalEvents; | 532 | List<EventuallyConsistentMapEvent<K, V>> externalEvents; |
533 | + boolean sync = false; | ||
533 | 534 | ||
534 | synchronized (this) { | 535 | synchronized (this) { |
535 | - final NodeId sender = ad.sender(); | ||
536 | - | ||
537 | externalEvents = antiEntropyCheckLocalItems(ad); | 536 | externalEvents = antiEntropyCheckLocalItems(ad); |
538 | 537 | ||
539 | antiEntropyCheckLocalRemoved(ad); | 538 | antiEntropyCheckLocalRemoved(ad); |
... | @@ -543,19 +542,24 @@ public class EventuallyConsistentMapImpl<K, V> | ... | @@ -543,19 +542,24 @@ public class EventuallyConsistentMapImpl<K, V> |
543 | // if remote ad has something unknown, actively sync | 542 | // if remote ad has something unknown, actively sync |
544 | for (K key : ad.timestamps().keySet()) { | 543 | for (K key : ad.timestamps().keySet()) { |
545 | if (!items.containsKey(key)) { | 544 | if (!items.containsKey(key)) { |
545 | + sync = true; | ||
546 | + break; | ||
547 | + } | ||
548 | + } | ||
549 | + } // synchronized (this) | ||
550 | + | ||
551 | + // Send the advertisement outside the synchronized block | ||
552 | + if (sync) { | ||
553 | + final NodeId sender = ad.sender(); | ||
546 | AntiEntropyAdvertisement<K> myAd = createAdvertisement(); | 554 | AntiEntropyAdvertisement<K> myAd = createAdvertisement(); |
547 | try { | 555 | try { |
548 | - unicastMessage(sender, antiEntropyAdvertisementSubject, | 556 | + unicastMessage(sender, antiEntropyAdvertisementSubject, myAd); |
549 | - myAd); | ||
550 | - break; | ||
551 | } catch (IOException e) { | 557 | } catch (IOException e) { |
552 | log.debug( | 558 | log.debug( |
553 | "Failed to send reactive anti-entropy advertisement to {}", | 559 | "Failed to send reactive anti-entropy advertisement to {}", |
554 | sender); | 560 | sender); |
555 | } | 561 | } |
556 | } | 562 | } |
557 | - } | ||
558 | - } // synchronized (this) | ||
559 | 563 | ||
560 | externalEvents.forEach(this::notifyListeners); | 564 | externalEvents.forEach(this::notifyListeners); |
561 | } | 565 | } | ... | ... |
-
Please register or login to post a comment