You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2014/08/27 05:27:46 UTC
svn commit: r1620777 - in /lucene/dev/branches/lucene5904/lucene/core/src:
java/org/apache/lucene/index/IndexFileDeleter.java
test/org/apache/lucene/index/TestIndexFileDeleter.java
Author: rmuir
Date: Wed Aug 27 03:27:46 2014
New Revision: 1620777
URL: http://svn.apache.org/r1620777
Log:
LUCENE-5904: don't parse segments.gen as a segments file and overinflate
Modified:
lucene/dev/branches/lucene5904/lucene/core/src/java/org/apache/lucene/index/IndexFileDeleter.java
lucene/dev/branches/lucene5904/lucene/core/src/test/org/apache/lucene/index/TestIndexFileDeleter.java
Modified: lucene/dev/branches/lucene5904/lucene/core/src/java/org/apache/lucene/index/IndexFileDeleter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5904/lucene/core/src/java/org/apache/lucene/index/IndexFileDeleter.java?rev=1620777&r1=1620776&r2=1620777&view=diff
==============================================================================
--- lucene/dev/branches/lucene5904/lucene/core/src/java/org/apache/lucene/index/IndexFileDeleter.java (original)
+++ lucene/dev/branches/lucene5904/lucene/core/src/java/org/apache/lucene/index/IndexFileDeleter.java Wed Aug 27 03:27:46 2014
@@ -236,7 +236,8 @@ final class IndexFileDeleter implements
// We keep commits list in sorted order (oldest to newest):
CollectionUtil.timSort(commits);
- inflateGens(segmentInfos);
+ // refCounts only includes "normal" filenames (does not include segments.gen, write.lock)
+ inflateGens(segmentInfos, refCounts.keySet(), infoStream);
// Now delete anything with ref count at 0. These are
// presumably abandoned files eg due to crash of
@@ -267,7 +268,7 @@ final class IndexFileDeleter implements
/** Set all gens beyond what we currently see in the directory, to avoid double-write in cases where the previous IndexWriter did not
* gracefully close/rollback (e.g. os/machine crashed or lost power). */
- private void inflateGens(SegmentInfos infos) {
+ static void inflateGens(SegmentInfos infos, Collection<String> files, InfoStream infoStream) {
long maxSegmentGen = Long.MIN_VALUE;
int maxSegmentName = Integer.MIN_VALUE;
@@ -279,9 +280,10 @@ final class IndexFileDeleter implements
// codec which file is which:
Map<String,Long> maxPerSegmentGen = new HashMap<>();
- // refCounts only includes "normal" filenames (does not include segments.gen, write.lock)
- for(String fileName : refCounts.keySet()) {
- if (fileName.startsWith(IndexFileNames.SEGMENTS)) {
+ for(String fileName : files) {
+ if (fileName.equals(IndexFileNames.SEGMENTS_GEN)) {
+ // do nothing
+ } else if (fileName.startsWith(IndexFileNames.SEGMENTS)) {
maxSegmentGen = Math.max(SegmentInfos.generationFromSegmentsFileName(fileName), maxSegmentGen);
} else {
String segmentName = IndexFileNames.parseSegmentName(fileName);
Modified: lucene/dev/branches/lucene5904/lucene/core/src/test/org/apache/lucene/index/TestIndexFileDeleter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5904/lucene/core/src/test/org/apache/lucene/index/TestIndexFileDeleter.java?rev=1620777&r1=1620776&r2=1620777&view=diff
==============================================================================
--- lucene/dev/branches/lucene5904/lucene/core/src/test/org/apache/lucene/index/TestIndexFileDeleter.java (original)
+++ lucene/dev/branches/lucene5904/lucene/core/src/test/org/apache/lucene/index/TestIndexFileDeleter.java Wed Aug 27 03:27:46 2014
@@ -31,8 +31,8 @@ import org.apache.lucene.store.IOContext
import org.apache.lucene.store.IndexInput;
import org.apache.lucene.store.IndexOutput;
import org.apache.lucene.store.MockDirectoryWrapper;
+import org.apache.lucene.util.InfoStream;
import org.apache.lucene.util.LuceneTestCase;
-import org.junit.Ignore;
/*
Verify we can read the pre-2.1 file format, do searches
@@ -243,4 +243,21 @@ public class TestIndexFileDeleter extend
iw.close();
dir.close();
}
+
+ public void testNoSegmentsDotGenInflation() throws IOException {
+ Directory dir = newMockDirectory();
+
+ // empty commit
+ new IndexWriter(dir, new IndexWriterConfig(null)).close();
+
+ SegmentInfos sis = new SegmentInfos();
+ sis.read(dir);
+ assertEquals(1, sis.getGeneration());
+
+ // no inflation
+ IndexFileDeleter.inflateGens(sis, Arrays.asList(dir.listAll()), InfoStream.getDefault());
+ assertEquals(1, sis.getGeneration());
+
+ dir.close();
+ }
}