JBoss Cache SVN: r8186 - core/trunk/src/main/java/org/jboss/cache/buddyreplication.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-08-17 05:48:26 -0400 (Mon, 17 Aug 2009)
New Revision: 8186
Modified:
core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java
Log:
[JBCACHE-1531] ( Replication is allowed when buddy group state is inconsistent )
Modified: core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java 2009-08-16 19:21:57 UTC (rev 8185)
+++ core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java 2009-08-17 09:48:26 UTC (rev 8186)
@@ -56,6 +56,7 @@
import org.jboss.cache.notifications.event.ViewChangedEvent;
import org.jboss.cache.statetransfer.StateTransferManager;
import org.jboss.cache.util.concurrent.ConcurrentHashSet;
+import org.jboss.cache.util.concurrent.ReclosableLatch;
import org.jboss.cache.util.reflect.ReflectionUtil;
import org.jboss.util.stream.MarshalledValueInputStream;
import org.jboss.util.stream.MarshalledValueOutputStream;
@@ -178,6 +179,7 @@
private BuddyFqnTransformer buddyFqnTransformer;
private ConcurrentMap<String, Set<DefunctDataHistory>> defunctDataHistory = new ConcurrentHashMap<String, Set<DefunctDataHistory>>();
+ private final ReclosableLatch buddyMembershipInFluxLatch = new ReclosableLatch(true);
public BuddyManager()
{
@@ -446,73 +448,80 @@
*/
private void reassignBuddies(List<Address> members) throws CacheException
{
- List<Address> membership = new ArrayList<Address>(members); // defensive copy
-
- if (log.isDebugEnabled())
+ buddyMembershipInFluxLatch.close();
+ try
{
- log.debug("Data owner address " + cache.getLocalAddress());
- log.debug("Entering updateGroup. Current group: " + buddyGroup + ". Current View membership: " + membership);
- }
- // some of my buddies have died!
- List<Address> newBuddies = buddyLocator.locateBuddies(buddyPool, membership, buddyGroup.getDataOwner());
- List<Address> unreachableBuddies;
- if (!(unreachableBuddies = checkBuddyStatus(newBuddies)).isEmpty())
- {
- // some of the new buddies are unreachable. Ditch them, try the algo again.
- membership.removeAll(unreachableBuddies);
- newBuddies = buddyLocator.locateBuddies(buddyPool, membership, buddyGroup.getDataOwner());
- }
- List<Address> uninitialisedBuddies = new ArrayList<Address>();
- List<Address> originalBuddies = buddyGroup.getBuddies();
+ List<Address> membership = new ArrayList<Address>(members); // defensive copy
- for (Address newBuddy : newBuddies)
- {
- if (!originalBuddies.contains(newBuddy))
+ if (log.isDebugEnabled())
{
- uninitialisedBuddies.add(newBuddy);
+ log.debug("Data owner address " + cache.getLocalAddress());
+ log.debug("Entering updateGroup. Current group: " + buddyGroup + ". Current View membership: " + membership);
}
- }
+ // some of my buddies have died!
+ List<Address> newBuddies = buddyLocator.locateBuddies(buddyPool, membership, buddyGroup.getDataOwner());
+ List<Address> unreachableBuddies;
+ if (!(unreachableBuddies = checkBuddyStatus(newBuddies)).isEmpty())
+ {
+ // some of the new buddies are unreachable. Ditch them, try the algo again.
+ membership.removeAll(unreachableBuddies);
+ newBuddies = buddyLocator.locateBuddies(buddyPool, membership, buddyGroup.getDataOwner());
+ }
+ List<Address> uninitialisedBuddies = new ArrayList<Address>();
+ List<Address> originalBuddies = buddyGroup.getBuddies();
- List<Address> obsoleteBuddies = new ArrayList<Address>();
- // find obsolete buddies
- for (Address origBuddy : originalBuddies)
- {
- if (!newBuddies.contains(origBuddy))
+ for (Address newBuddy : newBuddies)
{
- obsoleteBuddies.add(origBuddy);
+ if (!originalBuddies.contains(newBuddy))
+ {
+ uninitialisedBuddies.add(newBuddy);
+ }
}
- }
- // Update buddy list
- boolean buddyGroupMutated = !obsoleteBuddies.isEmpty() || !uninitialisedBuddies.isEmpty();
+ List<Address> obsoleteBuddies = new ArrayList<Address>();
+ // find obsolete buddies
+ for (Address origBuddy : originalBuddies)
+ {
+ if (!newBuddies.contains(origBuddy))
+ {
+ obsoleteBuddies.add(origBuddy);
+ }
+ }
- if (!obsoleteBuddies.isEmpty())
- {
- removeFromGroup(obsoleteBuddies);
- }
- else
- {
- log.trace("No obsolete buddies found, nothing to announce.");
- }
+ // Update buddy list
+ boolean buddyGroupMutated = !obsoleteBuddies.isEmpty() || !uninitialisedBuddies.isEmpty();
- if (!uninitialisedBuddies.isEmpty())
- {
- addBuddies(newBuddies);
+ if (!obsoleteBuddies.isEmpty())
+ {
+ removeFromGroup(obsoleteBuddies);
+ }
+ else
+ {
+ log.trace("No obsolete buddies found, nothing to announce.");
+ }
+
+ if (!uninitialisedBuddies.isEmpty())
+ {
+ addBuddies(newBuddies);
+ }
+ else
+ {
+ log.trace("No uninitialized buddies found, nothing to announce.");
+ }
+
+ if (buddyGroupMutated)
+ {
+ if (log.isInfoEnabled()) log.info("Buddy group members have changed. New buddy group: " + buddyGroup);
+ configuration.getRuntimeConfig().setBuddyGroup(buddyGroup);
+ notifier.notifyBuddyGroupChange(buddyGroup, false);
+ }
+ else
+ log.debug("Nothing has changed; new buddy list is identical to the old one.");
}
- else
+ finally
{
- log.trace("No uninitialized buddies found, nothing to announce.");
+ buddyMembershipInFluxLatch.open();
}
-
- if (buddyGroupMutated)
- {
- if (log.isInfoEnabled()) log.info("Buddy group members have changed. New buddy group: " + buddyGroup);
- configuration.getRuntimeConfig().setBuddyGroup(buddyGroup);
- notifier.notifyBuddyGroupChange(buddyGroup, false);
- }
- else
- log.debug("Nothing has changed; new buddy list is identical to the old one.");
-
}
/**
@@ -772,6 +781,14 @@
*/
public List<Address> getBuddyAddresses()
{
+ try
+ {
+ buddyMembershipInFluxLatch.await();
+ }
+ catch (InterruptedException e)
+ {
+ Thread.currentThread().interrupt();
+ }
return buddyGroup.getBuddies();
}
@@ -782,6 +799,14 @@
*/
public Vector<Address> getBuddyAddressesAsVector()
{
+ try
+ {
+ buddyMembershipInFluxLatch.await();
+ }
+ catch (InterruptedException e)
+ {
+ Thread.currentThread().interrupt();
+ }
return buddyGroup.getBuddiesAsVector();
}