Apache Solr open-source search software
LUCENE-4455: fix SIPC.sizeInBytes() to not double-count; fix CheckIndex to not reverse 'has deletions'/'no deletions'
Michael McCandless26e87af090ab
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 7d6e9c18a2d..1d4c7066c36 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -214,6 +214,11 @@ Bug Fixesparameter is reset to the default (1), even if set otherwise.(Gilad Barkai via Shai Erera)+* LUCENE-4455: Fix bug in SegmentInfoPerCommit.sizeInBytes() that was+ returning 2X the true size, inefficiently. Also fixed bug in+ CheckIndex that would report no deletions when a segment has+ deletions, and vice/versa. (Uwe Schindler, Robert Muir, Mike McCandless)+Optimizations* LUCENE-4322: Decrease lucene-core JAR size. The core JAR size had increased adiff --git a/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java b/lucene/core/src/java/org/apache/lucene/index/CheckIndex.javaindex b4cf8927f3c..227d316a769 100644--- a/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java+++ b/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java@@ -520,7 +520,7 @@ public class CheckIndex {// TODO: we could append the info attributes() to the msg?- if (info.hasDeletions()) {+ if (!info.hasDeletions()) {msg(" no deletions");segInfoStat.hasDeletions = false;}diff --git a/lucene/core/src/java/org/apache/lucene/index/SegmentInfoPerCommit.java b/lucene/core/src/java/org/apache/lucene/index/SegmentInfoPerCommit.javaindex fc7cfd01deb..6f0bb3a21b9 100644--- a/lucene/core/src/java/org/apache/lucene/index/SegmentInfoPerCommit.java+++ b/lucene/core/src/java/org/apache/lucene/index/SegmentInfoPerCommit.java@@ -67,9 +67,7 @@ public class SegmentInfoPerCommit {* segment. */public long sizeInBytes() throws IOException {if (sizeInBytes == -1) {- final Collection<String> files = new HashSet<String>();- info.getCodec().liveDocsFormat().files(this, files);- long sum = info.sizeInBytes();+ long sum = 0;for (final String fileName : files()) {sum += info.dir.fileLength(fileName);}diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterDelete.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterDelete.javaindex a92c4902ae4..d47b2f4f868 100644--- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterDelete.java+++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterDelete.java@@ -17,7 +17,9 @@ package org.apache.lucene.index;* limitations under the License.*/+import java.io.ByteArrayOutputStream;import java.io.IOException;+import java.io.PrintStream;import java.io.Reader;import java.util.ArrayList;import java.util.Collections;@@ -1071,4 +1073,47 @@ public class TestIndexWriterDelete extends LuceneTestCase {w.close();dir.close();}++ // LUCENE-4455+ public void testDeletesCheckIndexOutput() throws Exception {+ Directory dir = newDirectory();+ IndexWriterConfig iwc = new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()));+ iwc.setMaxBufferedDocs(2);+ IndexWriter w = new IndexWriter(dir, iwc);+ Document doc = new Document();+ doc.add(newField("field", "0", StringField.TYPE_NOT_STORED));+ w.addDocument(doc);++ doc = new Document();+ doc.add(newField("field", "1", StringField.TYPE_NOT_STORED));+ w.addDocument(doc);+ w.commit();+ assertEquals(1, w.getSegmentCount());++ w.deleteDocuments(new Term("field", "0"));+ w.commit();+ assertEquals(1, w.getSegmentCount());+ w.close();++ ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);+ CheckIndex checker = new CheckIndex(dir);+ checker.setInfoStream(new PrintStream(bos, false, "UTF-8"), false);+ CheckIndex.Status indexStatus = checker.checkIndex(null);+ assertTrue(indexStatus.clean);+ String s = bos.toString("UTF-8");++ // Segment should have deletions:+ assertTrue(s.contains("has deletions"));+ w = new IndexWriter(dir, iwc);+ w.forceMerge(1);+ w.close();++ bos = new ByteArrayOutputStream(1024);+ checker.setInfoStream(new PrintStream(bos, false, "UTF-8"), false);+ indexStatus = checker.checkIndex(null);+ assertTrue(indexStatus.clean);+ s = bos.toString("UTF-8");+ assertFalse(s.contains("has deletions"));+ dir.close();+ }}diff --git a/lucene/core/src/test/org/apache/lucene/index/TestRollingUpdates.java b/lucene/core/src/test/org/apache/lucene/index/TestRollingUpdates.javaindex d4607dd0a7d..09157df9d7d 100644--- a/lucene/core/src/test/org/apache/lucene/index/TestRollingUpdates.java+++ b/lucene/core/src/test/org/apache/lucene/index/TestRollingUpdates.java@@ -133,6 +133,21 @@ public class TestRollingUpdates extends LuceneTestCase {docs.close();_TestUtil.checkIndex(dir);++ // LUCENE-4455:+ SegmentInfos infos = new SegmentInfos();+ infos.read(dir);+ long totalBytes = 0;+ for(SegmentInfoPerCommit sipc : infos) {+ totalBytes += sipc.sizeInBytes();+ }+ long totalBytes2 = 0;+ for(String fileName : dir.listAll()) {+ if (!fileName.startsWith(IndexFileNames.SEGMENTS)) {+ totalBytes2 += dir.fileLength(fileName);+ }+ }+ assertEquals(totalBytes2, totalBytes);dir.close();}