[infinispan-commits] Infinispan SVN: r1401 - in trunk/core/src: test/java/org/infinispan/loaders/file and 1 other directory.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Wed Jan 20 10:22:57 EST 2010


Author: manik.surtani at jboss.com
Date: 2010-01-20 10:22:57 -0500 (Wed, 20 Jan 2010)
New Revision: 1401

Modified:
   trunk/core/src/main/java/org/infinispan/interceptors/CacheLoaderInterceptor.java
   trunk/core/src/test/java/org/infinispan/loaders/file/FileCacheStoreFunctionalTest.java
   trunk/core/src/test/java/org/infinispan/loaders/file/FileCacheStoreTest.java
Log:
[ISPN-337] ( Cache Store implementations are inefficient with containsKey() calls)

Modified: trunk/core/src/main/java/org/infinispan/interceptors/CacheLoaderInterceptor.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/interceptors/CacheLoaderInterceptor.java	2010-01-20 12:17:24 UTC (rev 1400)
+++ trunk/core/src/main/java/org/infinispan/interceptors/CacheLoaderInterceptor.java	2010-01-20 15:22:57 UTC (rev 1401)
@@ -116,7 +116,8 @@
       if (e == null || e.isNull()) {
 
          // we *may* need to load this.
-         if (!loader.containsKey(key)) {
+         InternalCacheEntry loaded = loader.load(key);
+         if (loaded == null) {
             if (log.isTraceEnabled()) log.trace("No need to load.  Key doesn't exist in the loader.");
             return false;
          }
@@ -133,7 +134,7 @@
 
          // Reuse the lock and create a new entry for loading
          MVCCEntry n = entryFactory.wrapEntryForWriting(ctx, key, true, false, keyLocked, false);
-         loadEntry(ctx, key, n);
+         putLoadedEntryInContainer(ctx, key, n, loaded);
          return true;
       } else {
          return true;
@@ -141,13 +142,10 @@
    }
 
    /**
-    * Loads an entry from loader
+    * Puts a loaded cache entry into the data container.
     */
-   private MVCCEntry loadEntry(InvocationContext ctx, Object key, MVCCEntry entry) throws Exception {
-      log.trace("Loading key {0}", key);
-
-      InternalCacheEntry storedEntry = loader.load(key);
-      boolean entryExists = (storedEntry != null);
+   private MVCCEntry putLoadedEntryInContainer(InvocationContext ctx, Object key, MVCCEntry entry, InternalCacheEntry loadedEntry) throws Exception {
+      boolean entryExists = (loadedEntry != null);
       if (log.isTraceEnabled()) log.trace("Entry exists in loader? " + entryExists);
 
       if (getStatisticsEnabled()) {
@@ -160,8 +158,10 @@
 
       if (entryExists) {
          sendNotification(key, true, ctx);
-         entry.setValue(storedEntry.getValue());
-         entry.setLifespan(storedEntry.getLifespan());
+         entry.setValue(loadedEntry.getValue());
+         entry.setLifespan(loadedEntry.getLifespan());
+         entry.setMaxIdle(loadedEntry.getMaxIdle());
+         // TODO shouldn't we also be setting last used and created timestamps?
          entry.setValid(true);
 
          notifier.notifyCacheEntryLoaded(key, false, ctx);

Modified: trunk/core/src/test/java/org/infinispan/loaders/file/FileCacheStoreFunctionalTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/loaders/file/FileCacheStoreFunctionalTest.java	2010-01-20 12:17:24 UTC (rev 1400)
+++ trunk/core/src/test/java/org/infinispan/loaders/file/FileCacheStoreFunctionalTest.java	2010-01-20 15:22:57 UTC (rev 1401)
@@ -27,6 +27,7 @@
 import org.infinispan.loaders.CacheStoreConfig;
 import org.infinispan.test.TestingUtil;
 import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
 import org.testng.annotations.BeforeTest;
 import org.testng.annotations.Optional;
 import org.testng.annotations.Parameters;
@@ -37,7 +38,7 @@
 
    private String tmpDirectory;
 
-   @BeforeTest
+   @BeforeClass
    @Parameters({"basedir"})
    protected void setUpTempDir(@Optional(value = "/tmp") String basedir) {
       tmpDirectory = TestingUtil.tmpDirectory(basedir, this);

Modified: trunk/core/src/test/java/org/infinispan/loaders/file/FileCacheStoreTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/loaders/file/FileCacheStoreTest.java	2010-01-20 12:17:24 UTC (rev 1400)
+++ trunk/core/src/test/java/org/infinispan/loaders/file/FileCacheStoreTest.java	2010-01-20 15:22:57 UTC (rev 1401)
@@ -11,6 +11,7 @@
 import org.infinispan.marshall.Marshaller;
 import org.infinispan.test.TestingUtil;
 import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
 import org.testng.annotations.BeforeTest;
 import org.testng.annotations.Optional;
 import org.testng.annotations.Parameters;
@@ -30,7 +31,7 @@
    private FileCacheStore fcs;
    private String tmpDirectory;
 
-   @BeforeTest
+   @BeforeClass
    @Parameters({"basedir"})
    protected void setUpTempDir(@Optional(value = "/tmp") String basedir) {
       tmpDirectory = TestingUtil.tmpDirectory(basedir, this);      



More information about the infinispan-commits mailing list