incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [1/3] git commit: Adding some optimizations.
Date Fri, 11 Oct 2013 00:47:15 GMT
Updated Branches:
  refs/heads/apache-blur-0.2 b909193ef -> 99ad04166


Adding some optimizations.


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

Branch: refs/heads/apache-blur-0.2
Commit: 21b6f3043318aa23782695fe44f48f4bcb096ed8
Parents: b909193
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Thu Oct 10 20:00:54 2013 -0400
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Thu Oct 10 20:00:54 2013 -0400

----------------------------------------------------------------------
 .../blur/store/BlockCacheDirectoryFactory.java  |  5 ++-
 .../store/BlockCacheDirectoryFactoryV1.java     |  2 +-
 .../store/BlockCacheDirectoryFactoryV2.java     |  2 +-
 .../store/blockcache_v2/CacheIndexInput.java    | 33 ++++++++++++++
 .../blur/store/blockcache_v2/CacheValue.java    |  6 +++
 .../cachevalue/BaseCacheValue.java              | 37 ++++++++++++++++
 .../blockcache_v2/CacheIndexInputTest.java      | 45 ++++++++++++++++++++
 7 files changed, 126 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/21b6f304/blur-store/src/main/java/org/apache/blur/store/BlockCacheDirectoryFactory.java
----------------------------------------------------------------------
diff --git a/blur-store/src/main/java/org/apache/blur/store/BlockCacheDirectoryFactory.java
b/blur-store/src/main/java/org/apache/blur/store/BlockCacheDirectoryFactory.java
index a8d31ab..4b10ced 100644
--- a/blur-store/src/main/java/org/apache/blur/store/BlockCacheDirectoryFactory.java
+++ b/blur-store/src/main/java/org/apache/blur/store/BlockCacheDirectoryFactory.java
@@ -21,8 +21,9 @@ import java.util.Set;
 
 import org.apache.lucene.store.Directory;
 
-public interface BlockCacheDirectoryFactory {
+public abstract class BlockCacheDirectoryFactory {
 
-  Directory newDirectory(String name, Directory directory, Set<String> blockCacheFileTypes)
throws IOException;
+  public abstract Directory newDirectory(String name, Directory directory, Set<String>
blockCacheFileTypes)
+      throws IOException;
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/21b6f304/blur-store/src/main/java/org/apache/blur/store/BlockCacheDirectoryFactoryV1.java
----------------------------------------------------------------------
diff --git a/blur-store/src/main/java/org/apache/blur/store/BlockCacheDirectoryFactoryV1.java
b/blur-store/src/main/java/org/apache/blur/store/BlockCacheDirectoryFactoryV1.java
index 8e9aa11..e4ad073 100644
--- a/blur-store/src/main/java/org/apache/blur/store/BlockCacheDirectoryFactoryV1.java
+++ b/blur-store/src/main/java/org/apache/blur/store/BlockCacheDirectoryFactoryV1.java
@@ -31,7 +31,7 @@ import org.apache.blur.store.blockcache.BlockDirectoryCache;
 import org.apache.blur.store.blockcache.Cache;
 import org.apache.lucene.store.Directory;
 
-public class BlockCacheDirectoryFactoryV1 implements BlockCacheDirectoryFactory {
+public class BlockCacheDirectoryFactoryV1 extends BlockCacheDirectoryFactory {
 
   private static final Log LOG = LogFactory.getLog(BlockCacheDirectoryFactoryV1.class);
 

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/21b6f304/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 6f32092..9e44253 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
@@ -28,7 +28,7 @@ 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 {
+public class BlockCacheDirectoryFactoryV2 extends BlockCacheDirectoryFactory {
 
   private Cache _cache;
 

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/21b6f304/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 344f598..2f61f2d 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
@@ -77,6 +77,39 @@ public class CacheIndexInput extends IndexInput {
     }
   }
 
+  @Override
+  public short readShort() throws IOException {
+    if (_cacheValue != null && remaining() >= 2) {
+      short s = _cacheValue.readShort(_blockPosition);
+      _blockPosition += 2;
+      _position += 2;
+      return s;
+    }
+    return super.readShort();
+  }
+
+  @Override
+  public int readInt() throws IOException {
+    if (_cacheValue != null && remaining() >= 4) {
+      int i = _cacheValue.readInt(_blockPosition);
+      _blockPosition += 4;
+      _position += 4;
+      return i;
+    }
+    return super.readInt();
+  }
+
+  @Override
+  public long readLong() throws IOException {
+    if (_cacheValue != null && remaining() >= 8) {
+      long l = _cacheValue.readLong(_blockPosition);
+      _blockPosition += 8;
+      _position += 8;
+      return l;
+    }
+    return super.readLong();
+  }
+
   private int remaining() {
     return _cacheValue.length() - _blockPosition;
   }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/21b6f304/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 0f7b976..c5c7759 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
@@ -90,4 +90,10 @@ public interface CacheValue {
    */
   void release();
 
+  short readShort(int position);
+
+  int readInt(int position);
+
+  long readLong(int position);
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/21b6f304/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/cachevalue/BaseCacheValue.java
----------------------------------------------------------------------
diff --git a/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/cachevalue/BaseCacheValue.java
b/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/cachevalue/BaseCacheValue.java
index 0f36086..13b6299 100644
--- a/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/cachevalue/BaseCacheValue.java
+++ b/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/cachevalue/BaseCacheValue.java
@@ -60,6 +60,43 @@ public abstract class BaseCacheValue extends AtomicLong implements CacheValue
{
     return readInternal(position);
   }
 
+  @Override
+  public short readShort(int position) {
+    if (position + 2 > _length) {
+      throw new ArrayIndexOutOfBoundsException(position + 2);
+    }
+    return readShortInternal(position);
+  }
+
+  protected short readShortInternal(int position) {
+    return (short) (((readInternal(position) & 0xFF) << 8) | (readInternal(position
+ 1) & 0xFF));
+  }
+
+  @Override
+  public int readInt(int position) {
+    if (position + 4 > _length) {
+      throw new ArrayIndexOutOfBoundsException(position + 4);
+    }
+    return readIntInternal(position);
+  }
+
+  protected int readIntInternal(int position) {
+    return ((readInternal(position) & 0xFF) << 24) | ((readInternal(position +
1) & 0xFF) << 16)
+        | ((readInternal(position + 2) & 0xFF) << 8) | (readInternal(position +
3) & 0xFF);
+  }
+
+  @Override
+  public long readLong(int position) {
+    if (position + 8 > _length) {
+      throw new ArrayIndexOutOfBoundsException(position + 4);
+    }
+    return readLongInternal(position);
+  }
+
+  protected long readLongInternal(int position) {
+    return (((long) readIntInternal(position)) << 32) | (readIntInternal(position +
4) & 0xFFFFFFFFL);
+  }
+
   protected abstract void writeInternal(int position, byte[] buf, int offset, int length);
 
   protected abstract byte readInternal(int position);

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/21b6f304/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 5a936a4..b4ca742 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
@@ -91,6 +91,9 @@ public class CacheIndexInputTest {
     IndexInput input = directory.openInput(name, IOContext.DEFAULT);
     IndexInput testInput = new CacheIndexInput(null, name, input.clone(), cache);
     readRandomData(input, testInput, random, sampleSize, maxBufSize, maxOffset);
+    readRandomDataShort(input, testInput, random, sampleSize);
+    readRandomDataInt(input, testInput, random, sampleSize);
+    readRandomDataLong(input, testInput, random, sampleSize);
     testInput.close();
     input.close();
     directory.close();
@@ -117,6 +120,48 @@ public class CacheIndexInputTest {
     }
   }
 
+  public static void readRandomDataInt(IndexInput baseInput, IndexInput testInput, Random
random, int sampleSize)
+      throws IOException {
+    assertEquals(baseInput.length(), testInput.length());
+    int fileLength = (int) baseInput.length();
+    for (int i = 0; i < sampleSize; i++) {
+      int position = random.nextInt(fileLength - 4);
+      baseInput.seek(position);
+      int i1 = baseInput.readInt();
+      testInput.seek(position);
+      int i2 = testInput.readInt();
+      assertEquals("Read [" + i + "] The position is [" + position + "]", i1, i2);
+    }
+  }
+
+  public static void readRandomDataShort(IndexInput baseInput, IndexInput testInput, Random
random, int sampleSize)
+      throws IOException {
+    assertEquals(baseInput.length(), testInput.length());
+    int fileLength = (int) baseInput.length();
+    for (int i = 0; i < sampleSize; i++) {
+      int position = random.nextInt(fileLength - 2);
+      baseInput.seek(position);
+      short i1 = baseInput.readShort();
+      testInput.seek(position);
+      short i2 = testInput.readShort();
+      assertEquals("Read [" + i + "] The position is [" + position + "]", i1, i2);
+    }
+  }
+
+  public static void readRandomDataLong(IndexInput baseInput, IndexInput testInput, Random
random, int sampleSize)
+      throws IOException {
+    assertEquals(baseInput.length(), testInput.length());
+    int fileLength = (int) baseInput.length();
+    for (int i = 0; i < sampleSize; i++) {
+      int position = random.nextInt(fileLength - 8);
+      baseInput.seek(position);
+      long i1 = baseInput.readLong();
+      testInput.seek(position);
+      long i2 = testInput.readLong();
+      assertEquals("Read [" + i + "] The position is [" + position + "]", i1, i2);
+    }
+  }
+
   public static void writeRandomData(long size, Random random, IndexOutput... outputs) throws
IOException {
     byte[] buf = new byte[1024];
     for (long l = 0; l < size; l += buf.length) {


Mime
View raw message