[jbosscache-commits] JBoss Cache SVN: r4823 - in core/trunk/src: main/java/org/jboss/cache/buddyreplication and 1 other directories.
jbosscache-commits at lists.jboss.org
jbosscache-commits at lists.jboss.org
Mon Dec 10 16:45:51 EST 2007
Author: bstansberry at jboss.com
Date: 2007-12-10 16:45:51 -0500 (Mon, 10 Dec 2007)
New Revision: 4823
Modified:
core/trunk/src/main/java/org/jboss/cache/RegionManager.java
core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyAssignmentStateTransferTest.java
Log:
[JBCACHE-1234] Region activation requests partial state transfer from wrong nodes
Modified: core/trunk/src/main/java/org/jboss/cache/RegionManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RegionManager.java 2007-12-10 19:37:16 UTC (rev 4822)
+++ core/trunk/src/main/java/org/jboss/cache/RegionManager.java 2007-12-10 21:45:51 UTC (rev 4823)
@@ -394,10 +394,12 @@
{
// Get the state from each DataOwner and integrate in their
// respective buddy backup cache
- List<Address> buddies = buddyManager.getBuddyAddresses();
+ List<Address> buddies = buddyManager.getBackupDataOwners();
for (Address buddy : buddies)
{
List<Address> sources = new ArrayList<Address>(1);
+ if (!cache.getMembers().contains(buddy))
+ continue;
sources.add(buddy);
Fqn buddyRoot = BuddyManager.getBackupFqn(buddy, fqn);
subtreeRoot = cache.findNode(buddyRoot);
@@ -410,7 +412,7 @@
subtreeRoot = cache.getRoot().addChild(buddyRoot);
cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(false);
}
- cache.fetchPartialState(sources, fqn, subtreeRoot.getFqn());
+ cache.fetchPartialState(sources, fqn, subtreeRoot.getFqn());
}
}
else
Modified: core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java 2007-12-10 19:37:16 UTC (rev 4822)
+++ core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java 2007-12-10 21:45:51 UTC (rev 4823)
@@ -535,6 +535,22 @@
}
}
}
+
+ /**
+ * Returns a List<IpAddress> identifying the DataOwner for each buddy
+ * group for which this node serves as a backup node.
+ */
+ public List<Address> getBackupDataOwners()
+ {
+ List<Address> owners = new ArrayList<Address>();
+ for (BuddyGroup group : buddyGroupsIParticipateIn.values())
+ {
+ owners.add(group.getDataOwner());
+ }
+ return owners;
+ }
+
+
// -------------- static util methods ------------------
Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyAssignmentStateTransferTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyAssignmentStateTransferTest.java 2007-12-10 19:37:16 UTC (rev 4822)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyAssignmentStateTransferTest.java 2007-12-10 21:45:51 UTC (rev 4823)
@@ -13,15 +13,18 @@
import java.util.ArrayList;
+import org.jboss.cache.Cache;
import org.jboss.cache.CacheImpl;
import org.jboss.cache.Fqn;
import org.jboss.cache.misc.TestingUtil;
+import org.testng.annotations.Test;
/**
* Tests how groups are formed and disbanded
*
* @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
*/
+ at Test(groups = {"functional", "jgroups"})
public class BuddyAssignmentStateTransferTest extends BuddyReplicationTestsBase
{
@@ -66,7 +69,89 @@
assertEquals("State transferred", "Joe", caches.get(2).get(test, "name"));
}
+
+ public void testRegionBasedStateTransfer() throws Exception
+ {
+ caches = new ArrayList<CacheImpl<Object, Object>>();
+
+ caches.add(createCache(1, "TEST", false, false));
+ caches.add(createCache(1, "TEST", false, false));
+ caches.add(createCache(1, "TEST", false, false));
+ // JBCACHE-1234 -- add a 4th cache so when we kill caches[1]
+ // caches[0] is not the backup node for caches[2] (although
+ // caches[2] *is* the backup node for caches[0]
+ caches.add(createCache(1, "TEST", false, false));
+ caches.get(0).getConfiguration().setInactiveOnStartup(true);
+ caches.get(1).getConfiguration().setInactiveOnStartup(true);
+ caches.get(2).getConfiguration().setInactiveOnStartup(true);
+ caches.get(3).getConfiguration().setInactiveOnStartup(true);
+ caches.get(0).getConfiguration().setUseRegionBasedMarshalling(true);
+ caches.get(1).getConfiguration().setUseRegionBasedMarshalling(true);
+ caches.get(2).getConfiguration().setUseRegionBasedMarshalling(true);
+ caches.get(3).getConfiguration().setUseRegionBasedMarshalling(true);
+ caches.get(0).start();
+ caches.get(1).start();
+ caches.get(2).start();
+ caches.get(3).start();
+
+ TestingUtil.blockUntilViewsReceived(caches.toArray(new CacheImpl[0]), VIEW_BLOCK_TIMEOUT);
+ TestingUtil.sleepThread(getSleepTimeout());
+
+ Fqn fqnA = Fqn.fromString("/a");
+ Fqn fqnD = Fqn.fromString("/d");
+
+ // FIXME We have to use a hack to get JBC to recognize that our
+ // regions are for marshalling
+ ClassLoader cl = Fqn.class.getClassLoader();
+ caches.get(0).getRegion(fqnA, true).registerContextClassLoader(cl);
+ caches.get(1).getRegion(fqnA, true).registerContextClassLoader(cl);
+ caches.get(2).getRegion(fqnA, true).registerContextClassLoader(cl);
+ caches.get(3).getRegion(fqnA, true).registerContextClassLoader(cl);
+ caches.get(0).getRegion(fqnD, true).registerContextClassLoader(cl);
+ caches.get(1).getRegion(fqnD, true).registerContextClassLoader(cl);
+ caches.get(2).getRegion(fqnD, true).registerContextClassLoader(cl);
+ caches.get(3).getRegion(fqnD, true).registerContextClassLoader(cl);
+
+ caches.get(0).getRegion(fqnA, true).activate();
+ caches.get(1).getRegion(fqnA, true).activate();
+ caches.get(2).getRegion(fqnA, true).activate();
+ caches.get(3).getRegion(fqnA, true).activate();
+
+ caches.get(0).getRegion(fqnD, true).activate();
+ caches.get(1).getRegion(fqnD, true).activate();
+
+ Fqn mainA = Fqn.fromString("/a/b/c");
+ caches.get(0).put(mainA, "name", "Joe");
+
+ Fqn mainD = Fqn.fromString("/d/e/f");
+ caches.get(0).put(mainD, "name", "Joe");
+
+ Fqn group = new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN,
+ BuddyManager.getGroupNameFromAddress(caches.get(0).getLocalAddress()));
+ Fqn testA = new Fqn(group, mainA);
+ assertEquals("/a replicated", "Joe", caches.get(1).get(testA, "name"));
+ assertNull("No backup of /a", caches.get(2).get(testA, "name"));
+
+ Fqn testD = new Fqn(group, mainD);
+ assertEquals("/d replicated", "Joe", caches.get(1).get(testD, "name"));
+ assertNull("No backup of /d", caches.get(2).get(testD, "name"));
+
+ // Make 2 the buddy of 0 -- this should cause a push from 0 to 2
+ caches.get(1).stop();
+ TestingUtil.sleepThread(getSleepTimeout());
+
+ assertEquals("/a state transferred", "Joe", caches.get(2).get(testA, "name"));
+ assertNull("/d state not transferred", caches.get(2).get(testD, "name"));
+
+ // JBCACHE-1234 -- Activate region on 2 and 3. This should cause
+ // a pull from 0 by and from 2 by 3.
+ caches.get(2).getRegion(fqnD, true).activate();
+ caches.get(3).getRegion(fqnD, true).activate();
+ assertEquals("/d transferred to cache 2", "Joe", caches.get(2).get(testD, "name"));
+ assertNull("/d state not transferred to cache 3", caches.get(3).get(testD, "name"));
+ }
+
public void testPersistentStateTransfer() throws Exception
{
caches = new ArrayList<CacheImpl<Object, Object>>();
More information about the jbosscache-commits
mailing list