[jbosscache-commits] JBoss Cache SVN: r8030 - in core/trunk/src: main/java/org/jboss/cache/commands/remote and 4 other directories.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Thu Apr 30 07:38:25 EDT 2009


Author: manik.surtani at jboss.com
Date: 2009-04-30 07:38:24 -0400 (Thu, 30 Apr 2009)
New Revision: 8030

Added:
   core/trunk/src/test/java/org/jboss/cache/loader/ChainedClusteredCacheLoaderTest.java
Modified:
   core/trunk/src/main/java/org/jboss/cache/InvocationContext.java
   core/trunk/src/main/java/org/jboss/cache/commands/remote/ClusteredGetCommand.java
   core/trunk/src/main/java/org/jboss/cache/interceptors/MarshalledValueInterceptor.java
   core/trunk/src/main/java/org/jboss/cache/loader/ClusteredCacheLoader.java
   core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationTestsBase.java
   core/trunk/src/test/java/org/jboss/cache/loader/ClusteredCacheLoaderTest.java
Log:
[JBCACHE-1508] ( ClusteredGetCommand bypasses loading from other cache loaders on remote instance) plus fixed some additional failing tests

Modified: core/trunk/src/main/java/org/jboss/cache/InvocationContext.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/InvocationContext.java	2009-04-30 11:23:30 UTC (rev 8029)
+++ core/trunk/src/main/java/org/jboss/cache/InvocationContext.java	2009-04-30 11:38:24 UTC (rev 8030)
@@ -64,6 +64,7 @@
    // defaults to true.
    private boolean originLocal = true;
    private boolean localRollbackOnly;
+   private boolean bypassUnmarshalling = false;
    @Deprecated
    private MethodCall methodCall;
    @Deprecated
@@ -423,6 +424,7 @@
       methodCall = null;
       command = null;
       fqnsLoaded = null;
+      bypassUnmarshalling = false;
    }
 
    /**
@@ -577,6 +579,7 @@
       copy.transaction = transaction;
       copy.transactionContext = transactionContext;
       copy.fqnsLoaded = fqnsLoaded;
+      copy.bypassUnmarshalling = bypassUnmarshalling;
    }
 
    /**
@@ -612,6 +615,7 @@
             ", transactionContext=" + transactionContext +
             ", optionOverrides=" + optionOverrides +
             ", originLocal=" + originLocal +
+            ", bypassUnmarshalling=" + bypassUnmarshalling +
             '}';
    }
 
@@ -624,6 +628,7 @@
       final InvocationContext that = (InvocationContext) o;
 
       if (localRollbackOnly != that.localRollbackOnly) return false;
+      if (bypassUnmarshalling != that.bypassUnmarshalling) return false;
       if (originLocal != that.originLocal) return false;
       if (globalTransaction != null ? !globalTransaction.equals(that.globalTransaction) : that.globalTransaction != null)
       {
@@ -647,6 +652,17 @@
       result = 29 * result + (optionOverrides != null ? optionOverrides.hashCode() : 0);
       result = 29 * result + (originLocal ? 1 : 0);
       result = 29 * result + (localRollbackOnly ? 1 : 0);
+      result = 29 * result + (bypassUnmarshalling ? 1 : 0);
       return result;
    }
+
+   public void setBypassUnmarshalling(boolean b)
+   {
+      this.bypassUnmarshalling = b;
+   }
+
+   public boolean isBypassUnmarshalling()
+   {
+      return bypassUnmarshalling;
+   }
 }

Modified: core/trunk/src/main/java/org/jboss/cache/commands/remote/ClusteredGetCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/remote/ClusteredGetCommand.java	2009-04-30 11:23:30 UTC (rev 8029)
+++ core/trunk/src/main/java/org/jboss/cache/commands/remote/ClusteredGetCommand.java	2009-04-30 11:38:24 UTC (rev 8030)
@@ -31,10 +31,12 @@
 import org.jboss.cache.commands.read.GetChildrenNamesCommand;
 import org.jboss.cache.commands.read.GetDataMapCommand;
 import org.jboss.cache.interceptors.InterceptorChain;
+import org.jboss.cache.loader.CacheLoaderManager;
 
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.Set;
 
 /**
  * Issues a clustered get call, for use primarily by the {@link org.jboss.cache.loader.ClusteredCacheLoader}.  This is
@@ -53,6 +55,7 @@
    private boolean searchBackupSubtrees;
    private DataContainer dataContainer;
    private InterceptorChain interceptorChain;
+   private CacheLoaderManager clm;
 
    private static final Log log = LogFactory.getLog(ClusteredGetCommand.class);
    private static final boolean trace = log.isTraceEnabled();
@@ -90,8 +93,11 @@
          if (trace) log.trace("Clustered get: invoking call with Fqn " + dataCommand.getFqn());
          InvocationContext ctx = interceptorChain.getInvocationContext();
          ctx.setOriginLocal(false);
-         // very hacky to be calling this command directly.
-         callResults = dataCommand.perform(ctx);
+         ctx.setBypassUnmarshalling(true);
+         callResults = interceptorChain.invoke(ctx, dataCommand);
+         Set mapCallRes;
+         if (dataCommand instanceof GetChildrenNamesCommand && (mapCallRes = (Set) callResults) != null && mapCallRes.isEmpty())
+            callResults = null;
          boolean found = validResult(callResults);
          if (trace) log.trace("Got result " + callResults + ", found=" + found);
          if (found && callResults == null) callResults = createEmptyResults();

Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/MarshalledValueInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/MarshalledValueInterceptor.java	2009-04-30 11:23:30 UTC (rev 8029)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/MarshalledValueInterceptor.java	2009-04-30 11:38:24 UTC (rev 8030)
@@ -69,7 +69,7 @@
       Set<MarshalledValue> marshalledValues = new HashSet<MarshalledValue>();
       command.setData(wrapMap(command.getData(), marshalledValues, ctx));
       Object retVal = invokeNextInterceptor(ctx, command);
-      return compactAndProcessRetVal(marshalledValues, retVal);
+      return ctx.isBypassUnmarshalling() ? retVal : compactAndProcessRetVal(marshalledValues, retVal);
    }
 
    @Override
@@ -80,7 +80,7 @@
       {
          if (trace) log.trace("Return value is a Map and we're retrieving data.  Wrapping as a MarshalledValueMap.");
          Map retValMap = (Map) retVal;
-         if (!retValMap.isEmpty()) retVal = new MarshalledValueMap(retValMap);
+         if (!ctx.isBypassUnmarshalling() && !retValMap.isEmpty()) retVal = new MarshalledValueMap(retValMap);
       }
       return retVal;
    }
@@ -106,21 +106,21 @@
          command.setValue(value);
       }
       Object retVal = invokeNextInterceptor(ctx, command);
-      return compactAndProcessRetVal(marshalledValues, retVal);
+      return ctx.isBypassUnmarshalling() ? retVal : compactAndProcessRetVal(marshalledValues, retVal);
    }
 
    @Override
    public Object visitGetNodeCommand(InvocationContext ctx, GetNodeCommand command) throws Throwable
    {
       Object retVal = invokeNextInterceptor(ctx, command);
-      return processRetVal(retVal);
+      return ctx.isBypassUnmarshalling() ? retVal :  processRetVal(retVal);
    }
 
    @Override
    public Object visitClearDataCommand(InvocationContext ctx, ClearDataCommand command) throws Throwable
    {
       Object retVal = invokeNextInterceptor(ctx, command);
-      return processRetVal(retVal);
+      return ctx.isBypassUnmarshalling() ? retVal :  processRetVal(retVal);
    }
 
    @Override
@@ -133,21 +133,21 @@
          command.setKey(value);
       }
       Object retVal = invokeNextInterceptor(ctx, command);
-      return compactAndProcessRetVal(marshalledValues, retVal);
+      return ctx.isBypassUnmarshalling() ? retVal :  compactAndProcessRetVal(marshalledValues, retVal);
    }
 
    @Override
    public Object visitGetChildrenNamesCommand(InvocationContext ctx, GetChildrenNamesCommand command) throws Throwable
    {
       Object retVal = invokeNextInterceptor(ctx, command);
-      return processRetVal(retVal);
+      return ctx.isBypassUnmarshalling() ? retVal :  processRetVal(retVal);
    }
 
    @Override
    public Object visitGetKeysCommand(InvocationContext ctx, GetKeysCommand command) throws Throwable
    {
       Object retVal = invokeNextInterceptor(ctx, command);
-      return processRetVal(retVal);
+      return ctx.isBypassUnmarshalling() ? retVal :  processRetVal(retVal);
    }
 
    @Override
@@ -160,7 +160,7 @@
          command.setKey(value);
       }
       Object retVal = invokeNextInterceptor(ctx, command);
-      return compactAndProcessRetVal(marshalledValues, retVal);
+      return ctx.isBypassUnmarshalling() ? retVal :  compactAndProcessRetVal(marshalledValues, retVal);
    }
 
    private Object compactAndProcessRetVal(Set<MarshalledValue> marshalledValues, Object retVal)

Modified: core/trunk/src/main/java/org/jboss/cache/loader/ClusteredCacheLoader.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/ClusteredCacheLoader.java	2009-04-30 11:23:30 UTC (rev 8029)
+++ core/trunk/src/main/java/org/jboss/cache/loader/ClusteredCacheLoader.java	2009-04-30 11:38:24 UTC (rev 8030)
@@ -185,7 +185,9 @@
    protected Map get0(Fqn name) throws Exception
    {
       // DON'T make a remote call if this is a remote call in the first place - leads to deadlocks - JBCACHE-1103
-      if (!isCacheReady() || !cache.getInvocationContext().isOriginLocal()) return Collections.emptyMap();
+      if (!isCacheReady() || !cache.getInvocationContext().isOriginLocal())
+            return null;
+//         return Collections.emptyMap();
       lock.acquireLock(name, true);
       try
       {

Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationTestsBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationTestsBase.java	2009-04-30 11:23:30 UTC (rev 8029)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationTestsBase.java	2009-04-30 11:38:24 UTC (rev 8030)
@@ -387,7 +387,7 @@
    {
       for (Cache cache : caches)
       {
-         if (cache != null) assertEquals(cache.getLocalAddress() + " still holds locks",0, ((CacheSPI) cache).getNumberOfLocksHeld());
+         if (cache != null) assert ((CacheSPI) cache).getNumberOfLocksHeld() < 1 : cache.getLocalAddress() + " still holds locks";
       }
    }
 

Added: core/trunk/src/test/java/org/jboss/cache/loader/ChainedClusteredCacheLoaderTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/ChainedClusteredCacheLoaderTest.java	                        (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/loader/ChainedClusteredCacheLoaderTest.java	2009-04-30 11:38:24 UTC (rev 8030)
@@ -0,0 +1,103 @@
+package org.jboss.cache.loader;
+
+import org.jboss.cache.AbstractMultipleCachesTest;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.UnitTestCacheFactory;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.factories.UnitTestConfigurationFactory;
+import org.jboss.cache.loader.testloaders.DummySharedInMemoryCacheLoader;
+import org.jboss.cache.loader.testloaders.DummySharedInMemoryCacheLoaderConfig;
+import org.testng.annotations.Test;
+
+import java.util.HashSet;
+import java.util.Set;
+
+ at Test(groups = {"functional"}, sequential = true, testName = "loader.ChainedClusteredCacheLoaderTest")
+public class ChainedClusteredCacheLoaderTest extends AbstractMultipleCachesTest
+{
+   private CacheSPI<Object, Object> cache1, cache2;
+   private CacheLoader loader1, loader2;
+   private Fqn fqn = Fqn.fromString("/a");
+   private Fqn fqn2 = Fqn.fromString("/a/b");
+   private String key = "key";   
+
+   protected void createCaches() throws Throwable {
+      Configuration c1 = new Configuration();
+      Configuration c2 = new Configuration();
+      c1.setStateRetrievalTimeout(2000);
+      c2.setStateRetrievalTimeout(2000);
+      c1.setCacheMode(Configuration.CacheMode.REPL_SYNC);
+      c2.setCacheMode(Configuration.CacheMode.REPL_SYNC);
+
+      c1.setCacheLoaderConfig(UnitTestConfigurationFactory.buildSingleCacheLoaderConfig(false, "", "org.jboss.cache.loader.ClusteredCacheLoader",
+            "timeout=5000", false, false, false, false, false));
+      c2.setCacheLoaderConfig(UnitTestConfigurationFactory.buildSingleCacheLoaderConfig(false, "", "org.jboss.cache.loader.ClusteredCacheLoader",
+            "timeout=5000", false, false, false, false, false));
+      DummySharedInMemoryCacheLoaderConfig cfg = new DummySharedInMemoryCacheLoaderConfig("cache-2");
+      c2.getCacheLoaderConfig().addIndividualCacheLoaderConfig(cfg);
+
+      c1.setUseRegionBasedMarshalling(false);
+      c2.setUseRegionBasedMarshalling(false);
+
+
+      cache1 = (CacheSPI<Object, Object>) new UnitTestCacheFactory<Object, Object>().createCache(c1, false, getClass());
+      cache2 = (CacheSPI<Object, Object>) new UnitTestCacheFactory<Object, Object>().createCache(c2, false, getClass());
+      cache1.getConfiguration().setSerializationExecutorPoolSize(0);
+      cache2.getConfiguration().setSerializationExecutorPoolSize(0);
+
+
+      cache1.getConfiguration().setNodeLockingScheme(Configuration.NodeLockingScheme.PESSIMISTIC);
+      cache2.getConfiguration().setNodeLockingScheme(Configuration.NodeLockingScheme.PESSIMISTIC);
+
+      cache1.start();
+      cache2.start();
+
+      loader1 = cache1.getCacheLoaderManager().getCacheLoader();
+      loader2 = cache2.getCacheLoaderManager().getCacheLoader();
+      registerCaches(cache1, cache2);
+   }
+
+   public void testClusteredGetFromSecondLoader() throws Exception {
+      cache1.put(fqn, key, "value");
+
+      assert loader1 instanceof ClusteredCacheLoader;
+      assert loader2 instanceof ChainingCacheLoader;
+      DummySharedInMemoryCacheLoader dummyLoader2 = (DummySharedInMemoryCacheLoader) ((ChainingCacheLoader) loader2).getCacheLoaders().get(1);
+
+      assert loader1.get(fqn).containsKey(key);
+      assert loader2.get(fqn).containsKey(key);
+      assert dummyLoader2.get(fqn).containsKey(key);
+
+      // evict from memory on all caches
+      cache1.evict(fqn);
+      cache2.evict(fqn);
+
+      assert dummyLoader2.get(fqn).containsKey(key);
+
+      assert "value".equals(cache1.get(fqn, key));
+   }
+
+   public void testClusteredGetChildrenNamesFromSecondLoader() throws Exception {
+      cache1.put(fqn, key, "value");
+      cache1.put(fqn2, key, "value");
+
+      assert loader1 instanceof ClusteredCacheLoader;
+      assert loader2 instanceof ChainingCacheLoader;
+      DummySharedInMemoryCacheLoader dummyLoader2 = (DummySharedInMemoryCacheLoader) ((ChainingCacheLoader) loader2).getCacheLoaders().get(1);
+
+      assert loader1.get(fqn).containsKey(key);
+      assert loader2.get(fqn).containsKey(key);
+      assert dummyLoader2.get(fqn).containsKey(key);
+
+      // evict from memory on all caches
+      cache1.evict(fqn, true);
+      cache2.evict(fqn, true);
+
+      assert dummyLoader2.get(fqn).containsKey(key);
+
+      Set s = new HashSet();
+      s.add("b");
+      assert s.equals(loader1.getChildrenNames(fqn));
+   }
+}


Property changes on: core/trunk/src/test/java/org/jboss/cache/loader/ChainedClusteredCacheLoaderTest.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: core/trunk/src/test/java/org/jboss/cache/loader/ClusteredCacheLoaderTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/ClusteredCacheLoaderTest.java	2009-04-30 11:23:30 UTC (rev 8029)
+++ core/trunk/src/test/java/org/jboss/cache/loader/ClusteredCacheLoaderTest.java	2009-04-30 11:38:24 UTC (rev 8030)
@@ -169,9 +169,18 @@
       assert cache1.peek(fqn, false) == null;
       assertEquals(3, childNames.size());
 
+//      cache1.evict(child1);
+//      cache1.evict(child2);
+//      cache1.evict(child3);
+      cache1.evict(fqn, true);
+//      cache2.evict(child1);
+//      cache2.evict(child2);
+//      cache2.evict(child3);
+//      cache2.evict(fqn, true);
       childNames = loader2.getChildrenNames(fqn);
       assertNull("should be null", childNames);
       // calling a get on cache1 should cause the loader to retrieve the node from cache2
+      cache1.evict(fqn, true);
       assertEquals("value", cache1.get(fqn, key));
       // load up children
       assertEquals("value", cache1.get(child1, key));




More information about the jbosscache-commits mailing list