incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cr...@apache.org
Subject [16/27] git commit: Refactoring some of the code.
Date Wed, 16 Oct 2013 03:32:59 GMT
Refactoring some of the code.


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

Branch: refs/heads/blur-console-v2
Commit: ab3c7283f92568b2694528834087f68ed5e0c2a2
Parents: dc94a2c
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Thu Oct 10 15:18:37 2013 -0400
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Thu Oct 10 16:23:02 2013 -0400

----------------------------------------------------------------------
 .../store/BlockCacheDirectoryFactoryV2.java     | 21 +++++++----
 .../blur/store/blockcache_v2/BaseCache.java     | 22 ++++++------
 .../apache/blur/store/blockcache_v2/Cache.java  | 38 ++++++++++++++------
 .../store/blockcache_v2/FileNameBlockSize.java  | 24 -------------
 .../apache/blur/store/blockcache_v2/Size.java   | 22 ++++++++++++
 .../cachevalue/UnsafeCacheValue.java            |  1 -
 .../blur/store/CacheDirectoryTestSuite.java     | 23 ++++++++----
 .../store/blockcache_v2/CacheDirectoryTest.java | 19 ++++++----
 .../blockcache_v2/CacheIndexInputTest.java      | 10 +++---
 9 files changed, 108 insertions(+), 72 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/ab3c7283/blur-store/src/main/java/org/apache/blur/store/BlockCacheDirectoryFactoryV2.java
----------------------------------------------------------------------
diff --git a/blur-store/src/main/java/org/apache/blur/store/BlockCacheDirectoryFactoryV2.java
b/blur-store/src/main/java/org/apache/blur/store/BlockCacheDirectoryFactoryV2.java
index d61dd73..6f32092 100644
--- a/blur-store/src/main/java/org/apache/blur/store/BlockCacheDirectoryFactoryV2.java
+++ b/blur-store/src/main/java/org/apache/blur/store/BlockCacheDirectoryFactoryV2.java
@@ -24,8 +24,8 @@ import org.apache.blur.store.blockcache_v2.BaseCache;
 import org.apache.blur.store.blockcache_v2.BaseCache.STORE;
 import org.apache.blur.store.blockcache_v2.Cache;
 import org.apache.blur.store.blockcache_v2.CacheDirectory;
-import org.apache.blur.store.blockcache_v2.FileNameBlockSize;
 import org.apache.blur.store.blockcache_v2.FileNameFilter;
+import org.apache.blur.store.blockcache_v2.Size;
 import org.apache.lucene.store.Directory;
 
 public class BlockCacheDirectoryFactoryV2 implements BlockCacheDirectoryFactory {
@@ -33,14 +33,21 @@ public class BlockCacheDirectoryFactoryV2 implements BlockCacheDirectoryFactory
   private Cache _cache;
 
   public BlockCacheDirectoryFactoryV2(BlurConfiguration configuration, long totalNumberOfBytes)
{
-    final int fileBufferSize = 8192;
-    final int blockSize = 8192;
+    final int fileBufferSizeInt = 8192;
+    final int cacheBlockSizeInt = 8192;
     final STORE store = STORE.OFF_HEAP;
     
-    FileNameBlockSize fileNameBlockSize = new FileNameBlockSize() {
+    Size fileBufferSize = new Size() {
       @Override
-      public int getBlockSize(String directoryName, String fileName) {
-        return blockSize;
+      public int getSize(String directoryName, String fileName) {
+        return fileBufferSizeInt;
+      }
+    };
+    
+    Size cacheBlockSize = new Size() {
+      @Override
+      public int getSize(String directoryName, String fileName) {
+        return cacheBlockSizeInt;
       }
     };
     
@@ -64,7 +71,7 @@ public class BlockCacheDirectoryFactoryV2 implements BlockCacheDirectoryFactory
       }
     };
     
-    _cache = new BaseCache(totalNumberOfBytes, fileBufferSize, fileNameBlockSize, readFilter,
writeFilter,
+    _cache = new BaseCache(totalNumberOfBytes, fileBufferSize, cacheBlockSize, readFilter,
writeFilter,
         store);
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/ab3c7283/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 d403778..35f7d83 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
@@ -35,7 +35,7 @@ import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
 import com.googlecode.concurrentlinkedhashmap.EvictionListener;
 import com.googlecode.concurrentlinkedhashmap.Weigher;
 
-public class BaseCache implements Cache {
+public class BaseCache extends Cache {
 
   private static final Log LOG = LogFactory.getLog(BaseCache.class);
 
@@ -58,23 +58,23 @@ public class BaseCache implements Cache {
   }
 
   private final ConcurrentLinkedHashMap<CacheKey, CacheValue> _cacheMap;
-  private final int _fileBufferSize;
   private final FileNameFilter _readFilter;
   private final FileNameFilter _writeFilter;
   private final STORE _store;
-  private final FileNameBlockSize _fileNameBlockSize;
+  private final Size _cacheBlockSize;
+  private final Size _fileBufferSize;
   private final Map<FileIdKey, Long> _fileNameToId = new ConcurrentHashMap<FileIdKey,
Long>();
   private final AtomicLong _fileId = new AtomicLong();
 
-  public BaseCache(long totalNumberOfBytes, int fileBufferSize, FileNameBlockSize fileNameBlockSize,
-      FileNameFilter readFilter, FileNameFilter writeFilter, STORE store) {
+  public BaseCache(long totalNumberOfBytes, Size fileBufferSize, Size cacheBlockSize, FileNameFilter
readFilter,
+      FileNameFilter writeFilter, STORE store) {
     _cacheMap = new ConcurrentLinkedHashMap.Builder<CacheKey, CacheValue>().weigher(new
BaseCacheWeigher())
         .maximumWeightedCapacity(totalNumberOfBytes).listener(new BaseCacheEvictionListener()).build();
     _fileBufferSize = fileBufferSize;
     _readFilter = readFilter;
     _writeFilter = writeFilter;
     _store = store;
-    _fileNameBlockSize = fileNameBlockSize;
+    _cacheBlockSize = cacheBlockSize;
   }
 
   private void addToReleaseQueue(CacheValue value) {
@@ -88,12 +88,12 @@ public class BaseCache implements Cache {
   }
 
   @Override
-  public CacheValue newInstance(CacheDirectory directory, String fileName) {
+  public CacheValue newInstance(CacheDirectory directory, String fileName, int cacheBlockSize)
{
     switch (_store) {
     case ON_HEAP:
-      return new ByteArrayCacheValue(getCacheBlockSize(directory, fileName));
+      return new ByteArrayCacheValue(cacheBlockSize);
     case OFF_HEAP:
-      return new UnsafeCacheValue(getCacheBlockSize(directory, fileName));
+      return new UnsafeCacheValue(cacheBlockSize);
     default:
       throw new RuntimeException("Unknown type [" + _store + "]");
     }
@@ -124,12 +124,12 @@ public class BaseCache implements Cache {
 
   @Override
   public int getCacheBlockSize(CacheDirectory directory, String fileName) {
-    return _fileNameBlockSize.getBlockSize(directory.getDirectoryName(), fileName);
+    return _cacheBlockSize.getSize(directory.getDirectoryName(), fileName);
   }
 
   @Override
   public int getFileBufferSize(CacheDirectory directory, String fileName) {
-    return _fileBufferSize;
+    return _fileBufferSize.getSize(directory.getDirectoryName(), fileName);
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/ab3c7283/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/Cache.java
----------------------------------------------------------------------
diff --git a/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/Cache.java b/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/Cache.java
index 66e60f7..552d3db 100644
--- a/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/Cache.java
+++ b/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/Cache.java
@@ -21,7 +21,7 @@ import java.io.IOException;
 
 import org.apache.lucene.store.IOContext;
 
-public interface Cache {
+public abstract class Cache {
 
   /**
    * Creates a new instance of CacheValue, the cache capacity should be used for
@@ -33,7 +33,23 @@ public interface Cache {
    *          the file name.
    * @return the new CacheValue instance.
    */
-  CacheValue newInstance(CacheDirectory directory, String fileName);
+  public CacheValue newInstance(CacheDirectory directory, String fileName) {
+    return newInstance(directory, fileName, getCacheBlockSize(directory, fileName));
+  }
+
+  /**
+   * Creates a new instance of CacheValue, the cache capacity should be used for
+   * the given file.
+   * 
+   * @param directory
+   *          the directory.
+   * @param fileName
+   *          the file name.
+   * @param cacheBlockSize
+   *          the length of the {@link CacheValue}.
+   * @return the new CacheValue instance.
+   */
+  public abstract CacheValue newInstance(CacheDirectory directory, String fileName, int cacheBlockSize);
 
   /**
    * Gets unique id for the given file. This is assumed to be unique even if the
@@ -46,7 +62,7 @@ public interface Cache {
    * @return the file id.
    * @throws IOException
    */
-  long getFileId(CacheDirectory directory, String fileName) throws IOException;
+  public abstract long getFileId(CacheDirectory directory, String fileName) throws IOException;
 
   /**
    * Get capacity of each cache entry for the given file.
@@ -57,7 +73,7 @@ public interface Cache {
    *          the file name.
    * @return the capacity.
    */
-  int getCacheBlockSize(CacheDirectory directory, String fileName);
+  public abstract int getCacheBlockSize(CacheDirectory directory, String fileName);
 
   /**
    * Gets buffer size of the buffer used while interacting with the underlying
@@ -69,7 +85,7 @@ public interface Cache {
    *          the file name.
    * @return the buffer size.
    */
-  int getFileBufferSize(CacheDirectory directory, String fileName);
+  public abstract int getFileBufferSize(CacheDirectory directory, String fileName);
 
   /**
    * Checks whether file should be cached or not during reading.
@@ -82,7 +98,7 @@ public interface Cache {
    *          the IOContext from Lucene.
    * @return boolean.
    */
-  boolean cacheFileForReading(CacheDirectory directory, String fileName, IOContext context);
+  public abstract boolean cacheFileForReading(CacheDirectory directory, String fileName,
IOContext context);
 
   /**
    * Checks whether file should be cached or not during writing.
@@ -95,7 +111,7 @@ public interface Cache {
    *          the IOContext from Lucene.
    * @return boolean.
    */
-  boolean cacheFileForWriting(CacheDirectory directory, String fileName, IOContext context);
+  public abstract boolean cacheFileForWriting(CacheDirectory directory, String fileName,
IOContext context);
 
   /**
    * Gets the cache value for the given key. Null if missing.
@@ -104,7 +120,7 @@ public interface Cache {
    *          the key.
    * @return the cache value or null.
    */
-  CacheValue get(CacheKey key);
+  public abstract CacheValue get(CacheKey key);
 
   /**
    * Puts the cache entry into the cache.
@@ -114,7 +130,7 @@ public interface Cache {
    * @param value
    *          the value.
    */
-  void put(CacheKey key, CacheValue value);
+  public abstract void put(CacheKey key, CacheValue value);
 
   /**
    * Removes the file from the cache.
@@ -125,7 +141,7 @@ public interface Cache {
    *          the file name.
    * @throws IOException
    */
-  void removeFile(CacheDirectory directory, String fileName) throws IOException;
+  public abstract void removeFile(CacheDirectory directory, String fileName) throws IOException;
 
   /**
    * This is called when the CacheDirectory is finalized.
@@ -133,6 +149,6 @@ public interface Cache {
    * @param directoryName
    *          the directory name.
    */
-  void releaseDirectory(String directoryName);
+  public abstract void releaseDirectory(String directoryName);
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/ab3c7283/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/FileNameBlockSize.java
----------------------------------------------------------------------
diff --git a/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/FileNameBlockSize.java
b/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/FileNameBlockSize.java
deleted file mode 100644
index 8890459..0000000
--- a/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/FileNameBlockSize.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.blur.store.blockcache_v2;
-
-public interface FileNameBlockSize {
-
-  int getBlockSize(String directoryName, String fileName);
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/ab3c7283/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/Size.java
----------------------------------------------------------------------
diff --git a/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/Size.java b/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/Size.java
new file mode 100644
index 0000000..c392a06
--- /dev/null
+++ b/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/Size.java
@@ -0,0 +1,22 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.blur.store.blockcache_v2;
+
+public interface Size {
+  int getSize(String directoryName, String fileName);
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/ab3c7283/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/cachevalue/UnsafeCacheValue.java
----------------------------------------------------------------------
diff --git a/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/cachevalue/UnsafeCacheValue.java
b/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/cachevalue/UnsafeCacheValue.java
index c532f62..3ea3796 100644
--- a/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/cachevalue/UnsafeCacheValue.java
+++ b/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/cachevalue/UnsafeCacheValue.java
@@ -52,7 +52,6 @@ public class UnsafeCacheValue extends BaseCacheValue {
 
   private final long _address;
   private final int _capacity;
-  private volatile boolean _released = false;
 
   public UnsafeCacheValue(int length) {
     super(length);

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/ab3c7283/blur-store/src/test/java/org/apache/blur/store/CacheDirectoryTestSuite.java
----------------------------------------------------------------------
diff --git a/blur-store/src/test/java/org/apache/blur/store/CacheDirectoryTestSuite.java b/blur-store/src/test/java/org/apache/blur/store/CacheDirectoryTestSuite.java
index ae7c356..db59271 100644
--- a/blur-store/src/test/java/org/apache/blur/store/CacheDirectoryTestSuite.java
+++ b/blur-store/src/test/java/org/apache/blur/store/CacheDirectoryTestSuite.java
@@ -23,8 +23,8 @@ import org.apache.blur.store.blockcache_v2.BaseCache;
 import org.apache.blur.store.blockcache_v2.BaseCache.STORE;
 import org.apache.blur.store.blockcache_v2.Cache;
 import org.apache.blur.store.blockcache_v2.CacheDirectory;
-import org.apache.blur.store.blockcache_v2.FileNameBlockSize;
 import org.apache.blur.store.blockcache_v2.FileNameFilter;
+import org.apache.blur.store.blockcache_v2.Size;
 import org.apache.blur.store.buffer.BufferStore;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.FSDirectory;
@@ -34,14 +34,23 @@ public abstract class CacheDirectoryTestSuite extends BaseDirectoryTestSuite
{
   @Override
   protected Directory setupDirectory() throws IOException {
     int totalNumberOfBytes = 1000000;
-    int fileBufferSize = numberBetween(113, 215);
-    final int blockSize = numberBetween(111, 251);
-    FileNameBlockSize fileNameBlockSize = new FileNameBlockSize() {
+    final int fileBufferSizeInt = numberBetween(113, 215);
+    final int cacheBlockSizeInt = numberBetween(111, 251);
+    
+    Size fileBufferSize = new Size() {
       @Override
-      public int getBlockSize(String directoryName, String fileName) {
-        return blockSize;
+      public int getSize(String directoryName, String fileName) {
+        return fileBufferSizeInt;
       }
     };
+    
+    Size cacheBlockSize = new Size() {
+      @Override
+      public int getSize(String directoryName, String fileName) {
+        return cacheBlockSizeInt;
+      }
+    };
+    
     FileNameFilter writeFilter = new FileNameFilter() {
       @Override
       public boolean accept(String directoryName, String fileName) {
@@ -55,7 +64,7 @@ public abstract class CacheDirectoryTestSuite extends BaseDirectoryTestSuite
{
       }
     };
 
-    Cache cache = new BaseCache(totalNumberOfBytes, fileBufferSize, fileNameBlockSize, readFilter,
writeFilter,
+    Cache cache = new BaseCache(totalNumberOfBytes, fileBufferSize, cacheBlockSize, readFilter,
writeFilter,
         getStore());
     Directory dir = FSDirectory.open(new File(file, "cache"));
 

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/ab3c7283/blur-store/src/test/java/org/apache/blur/store/blockcache_v2/CacheDirectoryTest.java
----------------------------------------------------------------------
diff --git a/blur-store/src/test/java/org/apache/blur/store/blockcache_v2/CacheDirectoryTest.java
b/blur-store/src/test/java/org/apache/blur/store/blockcache_v2/CacheDirectoryTest.java
index f27842e..97d8adc 100644
--- a/blur-store/src/test/java/org/apache/blur/store/blockcache_v2/CacheDirectoryTest.java
+++ b/blur-store/src/test/java/org/apache/blur/store/blockcache_v2/CacheDirectoryTest.java
@@ -53,12 +53,18 @@ public class CacheDirectoryTest {
   @Before
   public void setup() {
     int totalNumberOfBytes = 1000000;
-    int fileBufferSize = 127;
-    final int blockSize = 131;
-    FileNameBlockSize fileNameBlockSize = new FileNameBlockSize() {
+    final int fileBufferSizeInt = 127;
+    final int cacheBlockSizeInt = 131;
+    Size fileBufferSize = new Size() {
       @Override
-      public int getBlockSize(String directoryName, String fileName) {
-        return blockSize;
+      public int getSize(String directoryName, String fileName) {
+        return fileBufferSizeInt;
+      }
+    };
+    Size cacheBlockSize = new Size() {
+      @Override
+      public int getSize(String directoryName, String fileName) {
+        return cacheBlockSizeInt;
       }
     };
     FileNameFilter writeFilter = new FileNameFilter() {
@@ -73,7 +79,8 @@ public class CacheDirectoryTest {
         return true;
       }
     };
-    Cache cache = new BaseCache(totalNumberOfBytes, fileBufferSize, fileNameBlockSize, readFilter,
writeFilter,
+
+    Cache cache = new BaseCache(totalNumberOfBytes, fileBufferSize, cacheBlockSize, readFilter,
writeFilter,
         STORE.ON_HEAP);
     Directory directory = newDirectory();
     BufferStore.init(128, 128);

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/ab3c7283/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 3f455b8..5a936a4 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
@@ -128,7 +128,6 @@ public class CacheIndexInputTest {
     }
   }
 
-
   public static Cache getCache() {
     EvictionListener<CacheKey, CacheValue> listener = new EvictionListener<CacheKey,
CacheValue>() {
       @Override
@@ -153,8 +152,8 @@ public class CacheIndexInputTest {
     Cache cacheFactory = new Cache() {
 
       @Override
-      public CacheValue newInstance(CacheDirectory directory, String fileName) {
-        return new ByteArrayCacheValue(getCacheBlockSize(directory, fileName));
+      public CacheValue newInstance(CacheDirectory directory, String fileName, int cacheBlockSize)
{
+        return new ByteArrayCacheValue(cacheBlockSize);
       }
 
       @Override
@@ -194,13 +193,14 @@ public class CacheIndexInputTest {
 
       @Override
       public void removeFile(CacheDirectory directory, String fileName) throws IOException
{
-        
+
       }
 
       @Override
       public void releaseDirectory(String directoryName) {
-        
+
       }
+
     };
     return cacheFactory;
   }


Mime
View raw message