Committed by
Brian O'Connor
Move sending advertisement outside synchronized block
Change-Id: I1709fecbec5e6f5ac245b535c14a5c0b2aea2820
Showing
1 changed file
with
16 additions
and
12 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,20 +542,25 @@ public class EventuallyConsistentMapImpl<K, V> | ... | @@ -543,20 +542,25 @@ 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)) { |
| 546 | - AntiEntropyAdvertisement<K> myAd = createAdvertisement(); | 545 | + sync = true; |
| 547 | - try { | 546 | + break; |
| 548 | - unicastMessage(sender, antiEntropyAdvertisementSubject, | ||
| 549 | - myAd); | ||
| 550 | - break; | ||
| 551 | - } catch (IOException e) { | ||
| 552 | - log.debug( | ||
| 553 | - "Failed to send reactive anti-entropy advertisement to {}", | ||
| 554 | - sender); | ||
| 555 | - } | ||
| 556 | } | 547 | } |
| 557 | } | 548 | } |
| 558 | } // synchronized (this) | 549 | } // synchronized (this) |
| 559 | 550 | ||
| 551 | + // Send the advertisement outside the synchronized block | ||
| 552 | + if (sync) { | ||
| 553 | + final NodeId sender = ad.sender(); | ||
| 554 | + AntiEntropyAdvertisement<K> myAd = createAdvertisement(); | ||
| 555 | + try { | ||
| 556 | + unicastMessage(sender, antiEntropyAdvertisementSubject, myAd); | ||
| 557 | + } catch (IOException e) { | ||
| 558 | + log.debug( | ||
| 559 | + "Failed to send reactive anti-entropy advertisement to {}", | ||
| 560 | + sender); | ||
| 561 | + } | ||
| 562 | + } | ||
| 563 | + | ||
| 560 | externalEvents.forEach(this::notifyListeners); | 564 | externalEvents.forEach(this::notifyListeners); |
| 561 | } | 565 | } |
| 562 | 566 | ... | ... |
-
Please register or login to post a comment