[jbosscache-commits] JBoss Cache SVN: r4616 - in core/trunk/src: main/java/org/jboss/cache/interceptors and 1 other directories.
jbosscache-commits at lists.jboss.org
jbosscache-commits at lists.jboss.org
Fri Oct 12 20:52:26 EDT 2007
Author: manik.surtani at jboss.com
Date: 2007-10-12 20:52:26 -0400 (Fri, 12 Oct 2007)
New Revision: 4616
Modified:
core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
core/trunk/src/main/java/org/jboss/cache/interceptors/DataGravitatorInterceptor.java
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationWithCacheLoaderTest.java
Log:
JBCACHE-1192 - cannot gravitate data only stored in a cache loader
Modified: core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2007-10-12 23:39:28 UTC (rev 4615)
+++ core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2007-10-13 00:52:26 UTC (rev 4616)
@@ -2915,6 +2915,7 @@
ctx.setOriginLocal(false);
// use a get() call into the cache to make sure cache loading takes place.
+ // no need to cache the original skipDataGravitation setting here - it will always be false of we got here!!
ctx.getOptionOverrides().setSkipDataGravitation(true);
Node<K, V> actualNode = get(fqn);
ctx.getOptionOverrides().setSkipDataGravitation(false);
@@ -2941,19 +2942,14 @@
actualNode = get(backupNodeFqn);
ctx.getOptionOverrides().setSkipDataGravitation(false);
- if (actualNode != null) break;
+ if (actualNode != null)
+ {
+ // make sure we LOAD data for this node!!
+ getData(backupNodeFqn);
+ break;
+ }
}
}
- /*Map children = backupSubtree.getChildrenMapDirect();
- if (children != null)
- {
- Iterator childNames = children.keySet().iterator();
- while (childNames.hasNext() && actualNode == null)
- {
- backupNodeFqn = BuddyManager.getBackupFqn(childNames.next().toString(), fqn);
- actualNode = findNode(backupNodeFqn);
- }
- }*/
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/DataGravitatorInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/DataGravitatorInterceptor.java 2007-10-12 23:39:28 UTC (rev 4615)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/DataGravitatorInterceptor.java 2007-10-13 00:52:26 UTC (rev 4616)
@@ -89,16 +89,11 @@
{
if (cache.peek(fqn, false) == null)
{
- BackupData data;
+ log.trace("Gravitating from local backup tree");
+ BackupData data = localBackupGet(fqn, ctx);
- // perform a data gravitation
- if (localBackupExists(fqn))
+ if (data == null)
{
- log.trace("Gravitating from local backup tree");
- data = localBackupGet(fqn, ctx);
- }
- else
- {
log.trace("Gravitating from remote backup tree");
// gravitate remotely.
data = remoteBackupGet(fqn);
@@ -121,6 +116,10 @@
cleanBackupData(data, ctx.getGlobalTransaction(), ctx);
}
}
+ else
+ {
+ log.trace("No need to gravitate; have this already.");
+ }
}
}
else
Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationWithCacheLoaderTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationWithCacheLoaderTest.java 2007-10-12 23:39:28 UTC (rev 4615)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationWithCacheLoaderTest.java 2007-10-13 00:52:26 UTC (rev 4616)
@@ -235,13 +235,13 @@
*
* @throws Exception
*/
- public void testGravitationOfEvictedNodes() throws Exception
+ public void testLocalGravitationOfEvictedNodes() throws Exception
{
- CacheImpl<Object,Object> cache0 = createCacheWithCacheLoader(true, true, passivation, true, false);
- Configuration cfg0 = cache0.getConfiguration();
- configureEviction(cfg0);
- Configuration cfg1 = cfg0.clone();
- CacheImpl<Object,Object> cache1 = (CacheImpl<Object,Object>) DefaultCacheFactory.getInstance().createCache(cfg1, false);
+ CacheImpl<Object,Object> cache1 = createCacheWithCacheLoader(true, true, passivation, true, false);
+ Configuration cfg1 = cache1.getConfiguration();
+ configureEviction(cfg1);
+ Configuration cfg0 = cfg1.clone();
+ CacheImpl<Object,Object> cache0 = (CacheImpl<Object,Object>) DefaultCacheFactory.getInstance().createCache(cfg0, false);
// Store them for the teardown method
if (caches == null)
@@ -252,18 +252,89 @@
cache0.start();
cache1.start();
- TestingUtil.blockUntilViewsReceived((Cache[]) caches.toArray(new Cache[2]), VIEW_BLOCK_TIMEOUT);
+ TestingUtil.blockUntilViewsReceived(caches.toArray(new Cache[caches.size()]), VIEW_BLOCK_TIMEOUT * caches.size());
TestingUtil.sleepThread(getSleepTimeout());
-
+
+
Fqn foo = Fqn.fromString("/foo");
+ Fqn backupFoo = BuddyManager.getBackupFqn(cache0.getLocalAddress(), foo);
cache0.put(foo, "key", "value");
+ assert cache0.exists(foo) : "Data should exist in data owner";
+ assert cache1.exists(backupFoo) : "Buddy should have data";
+
// Sleep long enough for eviction to run twice plus a bit
- TestingUtil.sleepThread(2050);
-
+ TestingUtil.sleepThread(3050);
+
+ // test that the data we're looking for has been evicted in both the data owner and the buddy.
+ assert !cache0.exists(foo) : "Data should have evicted in data owner";
+ assert !cache1.exists(backupFoo) : "Buddy should have data evicted";
+
+ // now test that this exists in both loaders.
+ assert cache0.getCacheLoader().get(foo) != null : "Should exist in data owner's cache loader";
+ assert cache1.getCacheLoader().get(backupFoo) != null : "Should exist in buddy's loader";
+
+
+ // a local gravitation should occur since cache1 has foo in it's backup tree.
assertEquals("Passivated value available from buddy", "value", cache1.get(foo, "key"));
}
+ /**
+ * Tests whether nodes that have been evicted can successfully be
+ * gravitated.
+ *
+ * @throws Exception
+ */
+ public void testRemoteGravitationOfEvictedNodes() throws Exception
+ {
+ CacheImpl<Object,Object> cache0 = createCacheWithCacheLoader(true, true, passivation, true, false);
+ Configuration cfg0 = cache0.getConfiguration();
+ configureEviction(cfg0);
+ Configuration cfg1 = cfg0.clone();
+ CacheImpl<Object,Object> cache1 = (CacheImpl<Object,Object>) DefaultCacheFactory.getInstance().createCache(cfg1, false);
+ Configuration cfg2 = cfg0.clone();
+ CacheImpl<Object,Object> cache2 = (CacheImpl<Object,Object>) DefaultCacheFactory.getInstance().createCache(cfg2, false);
+
+ // Store them for the teardown method
+ if (caches == null)
+ caches = new ArrayList<CacheImpl<Object,Object>>();
+ caches.add(cache0);
+ caches.add(cache1);
+ caches.add(cache2);
+
+ cache0.start();
+ cache1.start();
+ cache2.start();
+
+ TestingUtil.blockUntilViewsReceived(caches.toArray(new Cache[caches.size()]), 600000);
+ TestingUtil.sleepThread(getSleepTimeout());
+
+
+ assert (cache0.getBuddyManager().getBuddyAddresses().contains(cache1.getLocalAddress())) : "Cache1 should be cache0's buddy!";
+
+ Fqn foo = Fqn.fromString("/foo");
+ Fqn backupFoo = BuddyManager.getBackupFqn(cache0.getLocalAddress(), foo);
+ cache0.put(foo, "key", "value");
+
+ // test that the data exists in both the data owner and the buddy
+ assert cache0.exists(foo) : "Data should exist in data owner";
+ assert cache1.exists(backupFoo) : "Buddy should have data";
+
+ // Sleep long enough for eviction to run twice plus a bit
+ TestingUtil.sleepThread(3050);
+
+ // test that the data we're looking for has been evicted in both the data owner and the buddy.
+ assert !cache0.exists(foo) : "Data should have evicted in data owner";
+ assert !cache1.exists(backupFoo) : "Buddy should have data evicted";
+
+ // now test that this exists in both loaders.
+ assert cache0.getCacheLoader().get(foo) != null : "Should exist in data owner's loader";
+ assert cache1.getCacheLoader().get(backupFoo) != null : "Should exist in buddy's loader";
+
+ // doing a get on cache2 will guarantee a remote data gravitation.
+ assertEquals("Passivated value available from buddy", "value", cache2.get(foo, "key"));
+ }
+
private void configureEviction(Configuration cfg)
{
EvictionConfig ec = new EvictionConfig();
More information about the jbosscache-commits
mailing list