Index: lucene/CHANGES.txt =================================================================== --- lucene/CHANGES.txt (revision 1392448) +++ lucene/CHANGES.txt (working copy) @@ -216,6 +216,11 @@ * LUCENE-4401: Fix bug where DisjunctionSumScorer would sometimes call score() on a subscorer that had already returned NO_MORE_DOCS. (Liu Chao, Robert Muir) +* 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 a Index: lucene/core/src/test/org/apache/lucene/index/TestRollingUpdates.java =================================================================== --- lucene/core/src/test/org/apache/lucene/index/TestRollingUpdates.java (revision 1392448) +++ lucene/core/src/test/org/apache/lucene/index/TestRollingUpdates.java (working copy) @@ -133,6 +133,21 @@ 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(); } Index: lucene/core/src/test/org/apache/lucene/index/TestIndexWriterDelete.java =================================================================== --- lucene/core/src/test/org/apache/lucene/index/TestIndexWriterDelete.java (revision 1392448) +++ lucene/core/src/test/org/apache/lucene/index/TestIndexWriterDelete.java (working copy) @@ -17,7 +17,9 @@ * 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 @@ 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(); + } } Index: lucene/core/src/java/org/apache/lucene/index/CheckIndex.java =================================================================== --- lucene/core/src/java/org/apache/lucene/index/CheckIndex.java (revision 1392448) +++ lucene/core/src/java/org/apache/lucene/index/CheckIndex.java (working copy) @@ -520,7 +520,7 @@ // TODO: we could append the info attributes() to the msg? - if (info.hasDeletions()) { + if (!info.hasDeletions()) { msg(" no deletions"); segInfoStat.hasDeletions = false; } Index: lucene/core/src/java/org/apache/lucene/index/SegmentInfoPerCommit.java =================================================================== --- lucene/core/src/java/org/apache/lucene/index/SegmentInfoPerCommit.java (revision 1392448) +++ lucene/core/src/java/org/apache/lucene/index/SegmentInfoPerCommit.java (working copy) @@ -67,9 +67,7 @@ * segment. */ public long sizeInBytes() throws IOException { if (sizeInBytes == -1) { - final Collection files = new HashSet(); - info.getCodec().liveDocsFormat().files(this, files); - long sum = info.sizeInBytes(); + long sum = 0; for (final String fileName : files()) { sum += info.dir.fileLength(fileName); }