LUCENE-4455: fix SIPC.sizeInBytes() to not double-count; fix CheckIndex to not reverse 'has deletions'/'no deletions'

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1392480 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2012-10-01 17:55:44 +00:00
parent b2b3a7aec3
commit 26e87af090
5 changed files with 67 additions and 4 deletions

View File

@ -214,6 +214,11 @@ Bug Fixes
parameter 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 a

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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();
}
}

View File

@ -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();
}