db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r577224 - /db/derby/code/trunk/java/engine/org/apache/derby/impl/services/cache/ConcurrentCache.java
Date Wed, 19 Sep 2007 09:56:24 GMT
Author: kahatlen
Date: Wed Sep 19 02:56:24 2007
New Revision: 577224

URL: http://svn.apache.org/viewvc?rev=577224&view=rev
Log:
DERBY-2911 (partial) Implement a buffer manager using java.util.concurrent classes

Changed signatures of ConcurrentCache.findFreeCacheable() and ConcurrentCache.removeEntry().

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/cache/ConcurrentCache.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/cache/ConcurrentCache.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/cache/ConcurrentCache.java?rev=577224&r1=577223&r2=577224&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/cache/ConcurrentCache.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/cache/ConcurrentCache.java
Wed Sep 19 02:56:24 2007
@@ -125,15 +125,16 @@
     }
 
     /**
-     * Find a free cacheable. If a free one cannot be found, allocate a new
-     * one.
+     * Find a free cacheable and give the specified entry a pointer to it. If
+     * a free cacheable cannot be found, allocate a new one. The entry must be
+     * locked by the current thread.
      *
-     * @return a cacheable with no identity
+     * @param entry the entry for which a <code>Cacheable</code> is needed
      */
-    private Cacheable findFreeCacheable() {
+    private void findFreeCacheable(CacheEntry entry) {
         // TODO - When the replacement algorithm has been implemented, we
         // should reuse a cacheable if possible.
-        return holderFactory.newCacheable(this);
+        entry.setCacheable(holderFactory.newCacheable(this));
     }
 
     /**
@@ -141,13 +142,12 @@
      * and made available for other entries. This method should only be called
      * if the entry is locked by the current thread.
      *
-     * @param entry the entry to remove from the cache
+     * @param key the identity of the entry to remove
      */
-    private void removeEntry(CacheEntry entry) {
-        Cacheable c = entry.getCacheable();
-        cache.remove(c.getIdentity());
+    private void removeEntry(Object key) {
+        CacheEntry entry = cache.remove(key);
+        entry.getCacheable().clearIdentity();
         entry.setCacheable(null);
-        c.clearIdentity();
         // TODO - When replacement policy is implemented, return the
         // cacheable to the free list
     }
@@ -173,17 +173,12 @@
             Cacheable item = entry.getCacheable();
             if (item == null) {
                 // not currently in the cache
-                Cacheable free = findFreeCacheable();
-                item = free.setIdentity(key);
+                findFreeCacheable(entry);
+                item = entry.getCacheable().setIdentity(key);
                 if (item == null) {
                     // Could not find an object with that identity. Remove its
                     // entry from the cache and return null.
-                    cache.remove(key);
-
-                    // TODO - When the replacement algorithm has been
-                    // implemented, the cacheable (free) should be returned to
-                    // the free list.
-
+                    removeEntry(key);
                     return null;
                 }
                 entry.setCacheable(item);
@@ -258,14 +253,16 @@
                 throw StandardException.newException(
                     SQLState.OBJECT_EXISTS_IN_CACHE, name, key);
             }
-            Cacheable free = findFreeCacheable();
-            Cacheable c = free.createIdentity(key, createParameter);
+            findFreeCacheable(entry);
+            Cacheable c =
+                    entry.getCacheable().createIdentity(key, createParameter);
             if (c != null) {
                 entry.setCacheable(c);
                 entry.keep();
             } else {
-                // TODO - When replacement policy is implemented, return the
-                // cacheable (free) to the free list
+                // Could not create an object with that identity. Remove the
+                // entry from the cache.
+                removeEntry(key);
             }
             return c;
         } finally {
@@ -305,7 +302,8 @@
      */
     public void remove(Cacheable item) throws StandardException {
         // The entry must be present, so we don't need to call getEntry().
-        CacheEntry entry = cache.get(item.getIdentity());
+        Object key = item.getIdentity();
+        CacheEntry entry = cache.get(key);
         entry.lock();
         try {
             if (SanityManager.DEBUG) {
@@ -313,7 +311,7 @@
             }
             entry.unkeepForRemove();
             item.clean(true);
-            removeEntry(entry);
+            removeEntry(key);
         } finally {
             entry.unlock();
         }
@@ -373,7 +371,7 @@
                     // If c is null, it's not in the cache and there's no need
                     // to remove it. If c is dirty, we can't remove it yet.
                     if (c != null && !c.isDirty()) {
-                        removeEntry(entry);
+                        removeEntry(c.getIdentity());
                     }
                 }
             } finally {
@@ -424,7 +422,7 @@
                     allRemoved = false;
                     continue;
                 }
-                removeEntry(entry);
+                removeEntry(c.getIdentity());
             } finally {
                 entry.unlock();
             }



Mime
View raw message