incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [3/7] git commit: Fixing a NPE when accessing the length of a evicted detachable cache value.
Date Tue, 28 Oct 2014 01:59:30 GMT
Fixing a NPE when accessing the length of a evicted detachable cache value.


Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/d9ebd44f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/d9ebd44f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/d9ebd44f

Branch: refs/heads/master
Commit: d9ebd44f0d4dd5b9c3cacef0fbe0cddae271e865
Parents: 87f6fa5
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Mon Oct 27 20:42:47 2014 -0400
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Mon Oct 27 20:42:47 2014 -0400

----------------------------------------------------------------------
 .../apache/blur/store/blockcache_v2/BaseCache.java    |  6 +++++-
 .../blur/store/blockcache_v2/CacheIndexInput.java     |  6 +++++-
 .../apache/blur/store/blockcache_v2/CacheValue.java   |  3 ++-
 .../store/blockcache_v2/CacheValueBufferPool.java     | 14 +++++++++-----
 .../cachevalue/DetachableCacheValue.java              |  3 ++-
 .../blur/store/blockcache_v2/CacheIndexInputTest.java |  6 +++++-
 6 files changed, 28 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/d9ebd44f/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/BaseCache.java
----------------------------------------------------------------------
diff --git a/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/BaseCache.java b/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/BaseCache.java
index 0be0378..d98637b 100644
--- a/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/BaseCache.java
+++ b/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/BaseCache.java
@@ -74,7 +74,11 @@ public class BaseCache extends Cache implements Closeable {
   class BaseCacheWeigher implements Weigher<CacheValue> {
     @Override
     public int weightOf(CacheValue value) {
-      return value.length();
+      try {
+        return value.length();
+      } catch (EvictionException e) {
+        return 0;
+      }
     }
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/d9ebd44f/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/CacheIndexInput.java
----------------------------------------------------------------------
diff --git a/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/CacheIndexInput.java
b/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/CacheIndexInput.java
index 7d9f933..dfdbccc 100644
--- a/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/CacheIndexInput.java
+++ b/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/CacheIndexInput.java
@@ -364,7 +364,11 @@ public class CacheIndexInput extends IndexInput {
   }
 
   private int remaining() {
-    return _cacheValue.length() - _blockPosition;
+    try {
+      return _cacheValue.length() - _blockPosition;
+    } catch (EvictionException e) {
+      return 0;
+    }
   }
 
   private void tryToFill() throws IOException {

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/d9ebd44f/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/CacheValue.java
----------------------------------------------------------------------
diff --git a/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/CacheValue.java
b/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/CacheValue.java
index b9fa8f6..2d5c567 100644
--- a/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/CacheValue.java
+++ b/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/CacheValue.java
@@ -32,8 +32,9 @@ public interface CacheValue {
    * The length of the data in this block.
    * 
    * @return the length.
+   * @throws EvictionException 
    */
-  int length();
+  int length() throws EvictionException;
 
   /**
    * Writes data out to a given position in this block.

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/d9ebd44f/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/CacheValueBufferPool.java
----------------------------------------------------------------------
diff --git a/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/CacheValueBufferPool.java
b/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/CacheValueBufferPool.java
index 7929df2..968edab 100644
--- a/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/CacheValueBufferPool.java
+++ b/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/CacheValueBufferPool.java
@@ -91,13 +91,17 @@ public class CacheValueBufferPool implements Closeable {
   }
 
   public void returnToPool(CacheValue cacheValue) {
-    if (cacheValue == null) {
+    if (cacheValue == null || cacheValue.isEvicted()) {
       return;
     }
-    BlockingQueue<CacheValue> blockingQueue = getPool(cacheValue.length());
-    if (!blockingQueue.offer(cacheValue)) {
-      _detroyed.mark();
-      cacheValue.release();
+    try {
+      BlockingQueue<CacheValue> blockingQueue = getPool(cacheValue.length());
+      if (!blockingQueue.offer(cacheValue)) {
+        _detroyed.mark();
+        cacheValue.release();
+      }
+    } catch (EvictionException e) {
+      return;
     }
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/d9ebd44f/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/cachevalue/DetachableCacheValue.java
----------------------------------------------------------------------
diff --git a/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/cachevalue/DetachableCacheValue.java
b/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/cachevalue/DetachableCacheValue.java
index 25c994c..e5ce99d 100644
--- a/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/cachevalue/DetachableCacheValue.java
+++ b/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/cachevalue/DetachableCacheValue.java
@@ -63,7 +63,8 @@ public class DetachableCacheValue implements CacheValue {
   }
 
   @Override
-  public int length() {
+  public int length() throws EvictionException {
+    checkEviction();
     return _baseCacheValue.length();
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/d9ebd44f/blur-store/src/test/java/org/apache/blur/store/blockcache_v2/CacheIndexInputTest.java
----------------------------------------------------------------------
diff --git a/blur-store/src/test/java/org/apache/blur/store/blockcache_v2/CacheIndexInputTest.java
b/blur-store/src/test/java/org/apache/blur/store/blockcache_v2/CacheIndexInputTest.java
index 9cbab58..a87f28f 100644
--- a/blur-store/src/test/java/org/apache/blur/store/blockcache_v2/CacheIndexInputTest.java
+++ b/blur-store/src/test/java/org/apache/blur/store/blockcache_v2/CacheIndexInputTest.java
@@ -184,7 +184,11 @@ public class CacheIndexInputTest {
     Weigher<CacheValue> weigher = new Weigher<CacheValue>() {
       @Override
       public int weightOf(CacheValue value) {
-        return value.length();
+        try {
+          return value.length();
+        } catch (EvictionException e) {
+          return 0;
+        }
       }
     };
     long maximumWeightedCapacity = 1 * 1024 * 1024;


Mime
View raw message