incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [1/2] git commit: Fixing a potential problem where the filter file could be truncated during creation because of failure. Filters with incorrect size because of the segment size will be deleted and recreated.
Date Thu, 24 Oct 2013 19:39:49 GMT
Updated Branches:
  refs/heads/apache-blur-0.2 5026bf027 -> 8fa192f24


Fixing a potential problem where the filter file could be truncated during creation because
of failure.  Filters with incorrect size because of the segment size will be deleted and recreated.


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

Branch: refs/heads/apache-blur-0.2
Commit: 8b146436e09a39857a8c3805ed3ac05c0a10bb47
Parents: 5026bf0
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Thu Oct 24 15:26:38 2013 -0400
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Thu Oct 24 15:36:31 2013 -0400

----------------------------------------------------------------------
 .../org/apache/blur/filter/IndexFileBitSet.java | 21 ++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/8b146436/blur-query/src/main/java/org/apache/blur/filter/IndexFileBitSet.java
----------------------------------------------------------------------
diff --git a/blur-query/src/main/java/org/apache/blur/filter/IndexFileBitSet.java b/blur-query/src/main/java/org/apache/blur/filter/IndexFileBitSet.java
index 4ef6031..199b8be 100644
--- a/blur-query/src/main/java/org/apache/blur/filter/IndexFileBitSet.java
+++ b/blur-query/src/main/java/org/apache/blur/filter/IndexFileBitSet.java
@@ -19,6 +19,8 @@ package org.apache.blur.filter;
 import java.io.Closeable;
 import java.io.IOException;
 
+import org.apache.blur.log.Log;
+import org.apache.blur.log.LogFactory;
 import org.apache.lucene.search.DocIdSet;
 import org.apache.lucene.search.DocIdSetIterator;
 import org.apache.lucene.store.Directory;
@@ -28,6 +30,8 @@ import org.apache.lucene.store.IndexOutput;
 
 public class IndexFileBitSet extends DocIdSet implements Closeable {
 
+  private static final Log LOG = LogFactory.getLog(IndexFileBitSet.class);
+
   public static final String EXTENSION = ".filter";
 
   private final String _id;
@@ -49,7 +53,16 @@ public class IndexFileBitSet extends DocIdSet implements Closeable {
   }
 
   public boolean exists() throws IOException {
-    return _directory.fileExists(getFileName());
+    boolean fileExists = _directory.fileExists(getFileName());
+    if (fileExists) {
+      int words = (_numBits / 64) + 1;
+      int correctLength = words * 8;
+      long length = _indexInput.length();
+      if (correctLength == length) {
+        return true;
+      }
+    }
+    return false;
   }
 
   private String getFileName() {
@@ -70,6 +83,10 @@ public class IndexFileBitSet extends DocIdSet implements Closeable {
 
   public void create(DocIdSetIterator it) throws IOException {
     String fileName = getFileName();
+    if (_directory.fileExists(getFileName())) {
+      LOG.warn("Filter [{0}] in directory [{1}] being recreated due to incorrect size.",
fileName, _directory);
+      _directory.deleteFile(fileName);
+    }
     IndexOutput output = _directory.createOutput(fileName, IOContext.READ);
     int index;
     int currentWordNum = 0;
@@ -89,7 +106,7 @@ public class IndexFileBitSet extends DocIdSet implements Closeable {
       wordValue |= bitmask;
     }
     if (_numBits > 0) {
-      int totalWords =  (_numBits / 64) + 1;
+      int totalWords = (_numBits / 64) + 1;
       while (currentWordNum < totalWords) {
         output.writeLong(wordValue);
         currentWordNum++;


Mime
View raw message