You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ka...@apache.org on 2008/03/10 15:00:47 UTC
svn commit: r635556 -
/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/cache/ConcurrentCache.java
Author: kahatlen
Date: Mon Mar 10 07:00:43 2008
New Revision: 635556
URL: http://svn.apache.org/viewvc?rev=635556&view=rev
Log:
DERBY-2911: Implement a buffer manager using java.util.concurrent classes
Improved comments as suggested in the review.
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=635556&r1=635555&r2=635556&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 Mon Mar 10 07:00:43 2008
@@ -168,11 +168,16 @@
}
/**
- * Remove an entry from the cache. Clear the identity of its
- * <code>Cacheable</code> and set it to null. This method is called when
- * the replacement algorithm needs to evict an entry from the cache in
- * order to make room for a new entry. The caller must have locked the
- * entry that is about to be evicted.
+ * Evict an entry to make room for a new entry that is being inserted into
+ * the cache. Clear the identity of its {@code Cacheable} and set it to
+ * {@code null}. When this method is called, the caller has already chosen
+ * the {@code Cacheable} for reuse. Therefore, this method won't call
+ * {@code CacheEntry.free()} as that would make the {@code Cacheable} free
+ * for reuse by other entries as well.
+ *
+ * <p>
+ *
+ * The caller must have locked the entry that is about to be evicted.
*
* @param key identity of the entry to remove
*/
@@ -310,8 +315,8 @@
return null;
}
- // We don't want to insert it if it's not there, so there's no need to
- // use getEntry().
+ // Use get() instead of getEntry() so that we don't insert an empty
+ // entry if the requested object isn't there.
CacheEntry entry = cache.get(key);
if (entry == null) {
// No such object was found in the cache.
@@ -392,7 +397,10 @@
* @param item a <code>Cacheable</code> value
*/
public void release(Cacheable item) {
- // The entry must be present, so we don't need to call getEntry().
+ // The entry must be present and kept when this method is called, so we
+ // don't need the complexity of getEntry() to ensure that the entry is
+ // not added to or removed from the cache before we have locked
+ // it. Just call get() which is cheaper.
CacheEntry entry = cache.get(item.getIdentity());
entry.lock();
try {
@@ -416,9 +424,14 @@
* @param item the object to remove from the cache
*/
public void remove(Cacheable item) throws StandardException {
- // The entry must be present, so we don't need to call getEntry().
Object key = item.getIdentity();
+
+ // The entry must be present and kept when this method is called, so we
+ // don't need the complexity of getEntry() to ensure that the entry is
+ // not added to or removed from the cache before we have locked
+ // it. Just call get() which is cheaper.
CacheEntry entry = cache.get(key);
+
entry.lock();
try {
if (SanityManager.DEBUG) {