incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [33/45] git commit: Closing resources that need to be closed.
Date Sat, 28 Sep 2013 02:12:19 GMT
Closing resources that need to be closed.


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

Branch: refs/heads/apache-blur-0.2
Commit: 28be85a9fb3528a7c22f426ad32d6400b0c222e7
Parents: 862691a
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Fri Sep 20 14:07:03 2013 -0400
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Fri Sep 20 14:07:03 2013 -0400

----------------------------------------------------------------------
 .../apache/blur/lucene/warmup/IndexWarmup.java  | 63 ++++++++++----------
 .../blockcache_v2/CacheIndexInputTest.java      |  2 +
 .../blockcache_v2/CacheIndexOutputTest.java     |  3 +
 3 files changed, 38 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/28be85a9/blur-store/src/main/java/org/apache/blur/lucene/warmup/IndexWarmup.java
----------------------------------------------------------------------
diff --git a/blur-store/src/main/java/org/apache/blur/lucene/warmup/IndexWarmup.java b/blur-store/src/main/java/org/apache/blur/lucene/warmup/IndexWarmup.java
index d592cde..21e6977 100644
--- a/blur-store/src/main/java/org/apache/blur/lucene/warmup/IndexWarmup.java
+++ b/blur-store/src/main/java/org/apache/blur/lucene/warmup/IndexWarmup.java
@@ -145,39 +145,42 @@ public class IndexWarmup {
     long length = endingPosition - startingPosition;
     final long totalLength = length;
     IndexInput input = new ThrottledIndexInput(dir.openInput(fileName, IOContext.READ), _maxBytesPerSec);
-    input.seek(startingPosition);
-    byte[] buf = new byte[8192];
-    long start = System.nanoTime();
-    long bytesReadPerPass = 0;
-    while (length > 0) {
-      long now = System.nanoTime();
-      if (start + _5_SECONDS < now) {
-        double seconds = (now - start) / 1000000000.0;
-        double rateMbPerSec = (bytesReadPerPass / seconds) / 1000 / 1000;
-        double complete = (((double) totalLength - (double) length) / (double) totalLength)
* 100.0;
-        LOG.debug("Context [{3}] warming field [{0}] in file [{1}] is [{2}%] complete at
rate of [{4} MB/s]",
-            fieldName, fileName, complete, context, rateMbPerSec);
-        start = System.nanoTime();
-        bytesReadPerPass = 0;
-        if (_isClosed.get()) {
-          LOG.info("Context [{0}] index closed", context);
-          return;
+    try {
+      input.seek(startingPosition);
+      byte[] buf = new byte[8192];
+      long start = System.nanoTime();
+      long bytesReadPerPass = 0;
+      while (length > 0) {
+        long now = System.nanoTime();
+        if (start + _5_SECONDS < now) {
+          double seconds = (now - start) / 1000000000.0;
+          double rateMbPerSec = (bytesReadPerPass / seconds) / 1000 / 1000;
+          double complete = (((double) totalLength - (double) length) / (double) totalLength)
* 100.0;
+          LOG.debug("Context [{3}] warming field [{0}] in file [{1}] is [{2}%] complete at
rate of [{4} MB/s]",
+              fieldName, fileName, complete, context, rateMbPerSec);
+          start = System.nanoTime();
+          bytesReadPerPass = 0;
+          if (_isClosed.get()) {
+            LOG.info("Context [{0}] index closed", context);
+            return;
+          }
         }
+        int len = (int) Math.min(length, buf.length);
+        input.readBytes(buf, 0, len);
+        length -= len;
+        bytesReadPerPass += len;
       }
-      int len = (int) Math.min(length, buf.length);
-      input.readBytes(buf, 0, len);
-      length -= len;
-      bytesReadPerPass += len;
-    }
-    long now = System.nanoTime();
-    double seconds = (now - start) / 1000000000.0;
-    if (seconds < 1) {
-      seconds = 1;
+      long now = System.nanoTime();
+      double seconds = (now - start) / 1000000000.0;
+      if (seconds < 1) {
+        seconds = 1;
+      }
+      double rateMbPerSec = (bytesReadPerPass / seconds) / 1000 / 1000;
+      LOG.debug("Context [{3}] warming field [{0}] in file [{1}] is [{2}%] complete at rate
of [{4} MB/s]", fieldName,
+          fileName, 100, context, rateMbPerSec);
+    } finally {
+      input.close();
     }
-    double rateMbPerSec = (bytesReadPerPass / seconds) / 1000 / 1000;
-    LOG.debug("Context [{3}] warming field [{0}] in file [{1}] is [{2}%] complete at rate
of [{4} MB/s]", fieldName,
-        fileName, 100, context, rateMbPerSec);
-    input.clone();
   }
 
   private Directory getDirectory(IndexReader reader, String segmentName, String context)
{

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/28be85a9/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 6e897bc..3f455b8 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
@@ -72,6 +72,7 @@ public class CacheIndexInputTest {
     cacheInput.close();
 
     assertArrayEquals(bs, buf);
+    directory.close();
   }
 
   @Test
@@ -92,6 +93,7 @@ public class CacheIndexInputTest {
     readRandomData(input, testInput, random, sampleSize, maxBufSize, maxOffset);
     testInput.close();
     input.close();
+    directory.close();
   }
 
   public static void readRandomData(IndexInput baseInput, IndexInput testInput, Random random,
int sampleSize,

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/28be85a9/blur-store/src/test/java/org/apache/blur/store/blockcache_v2/CacheIndexOutputTest.java
----------------------------------------------------------------------
diff --git a/blur-store/src/test/java/org/apache/blur/store/blockcache_v2/CacheIndexOutputTest.java
b/blur-store/src/test/java/org/apache/blur/store/blockcache_v2/CacheIndexOutputTest.java
index 2dc8b5b..393e7d8 100644
--- a/blur-store/src/test/java/org/apache/blur/store/blockcache_v2/CacheIndexOutputTest.java
+++ b/blur-store/src/test/java/org/apache/blur/store/blockcache_v2/CacheIndexOutputTest.java
@@ -71,6 +71,7 @@ public class CacheIndexOutputTest {
     input.readBytes(buf, 0, 16000);
     input.close();
     assertArrayEquals(b, buf);
+    directory.close();
   }
 
   @Test
@@ -96,6 +97,8 @@ public class CacheIndexOutputTest {
     CacheIndexInputTest.readRandomData(input, testInput, random, sampleSize, maxBufSize,
maxOffset);
     testInput.close();
     input.close();
+    directory.close();
+    directory2.close();
   }
 
 }


Mime
View raw message