Index: lucene/CHANGES.txt =================================================================== --- lucene/CHANGES.txt (revision 1057985) +++ lucene/CHANGES.txt (working copy) @@ -308,6 +308,9 @@ false EOF after seeking to EOF then seeking back to same block you were just in and then calling readBytes (Robert Muir, Mike McCandless) +* LUCENE-2860: Fixed SegmentInfo.sizeInBytes to factor includeDocStores when it + decides whether to return the cached computed size or not. (Shai Erera) + New features * LUCENE-2128: Parallelized fetching document frequencies during weight Index: lucene/src/test/org/apache/lucene/index/TestSegmentInfo.java =================================================================== --- lucene/src/test/org/apache/lucene/index/TestSegmentInfo.java (revision 0) +++ lucene/src/test/org/apache/lucene/index/TestSegmentInfo.java (revision 0) @@ -0,0 +1,48 @@ +package org.apache.lucene.index; + +import org.apache.lucene.analysis.MockAnalyzer; +import org.apache.lucene.document.Document; +import org.apache.lucene.document.Field; +import org.apache.lucene.document.Field.Index; +import org.apache.lucene.document.Field.Store; +import org.apache.lucene.store.Directory; +import org.apache.lucene.util.LuceneTestCase; + +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +public class TestSegmentInfo extends LuceneTestCase { + + public void testSizeInBytesCache() throws Exception { + Directory dir = newDirectory(); + IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()); + IndexWriter writer = new IndexWriter(dir, conf); + Document doc = new Document(); + doc.add(new Field("a", "value", Store.YES, Index.ANALYZED)); + writer.addDocument(doc); + writer.close(); + + SegmentInfos sis = new SegmentInfos(); + sis.read(dir); + SegmentInfo si = sis.info(0); + long sizeInBytesNoStore = si.sizeInBytes(false); + long sizeInBytesWithStore = si.sizeInBytes(true); + assertTrue("sizeInBytesNoStore=" + sizeInBytesNoStore + " sizeInBytesWithStore=" + sizeInBytesWithStore, sizeInBytesWithStore > sizeInBytesNoStore); + dir.close(); + } + +} Property changes on: lucene/src/test/org/apache/lucene/index/TestSegmentInfo.java ___________________________________________________________________ Added: svn:keywords + Date Author Id Revision HeadURL Added: svn:eol-style + native Index: lucene/src/java/org/apache/lucene/index/SegmentInfo.java =================================================================== --- lucene/src/java/org/apache/lucene/index/SegmentInfo.java (revision 1057985) +++ lucene/src/java/org/apache/lucene/index/SegmentInfo.java (working copy) @@ -72,10 +72,11 @@ // and true for newly created merged segments (both // compound and non compound). - private List files; // cached list of files that this segment uses + private List files; // cached list of files that this segment uses // in the Directory - long sizeInBytes = -1; // total byte size of all of our files (computed on demand) + private long sizeInBytesNoStore = -1; // total byte size of all but the store files (computed on demand) + private long sizeInBytesWithStore = -1; // total byte size of all of our files (computed on demand) private int docStoreOffset; // if this segment shares stored fields & vectors, this // offset is where in that file this segment's docs begin @@ -265,25 +266,33 @@ } } - /** Returns total size in bytes of all of files used by - * this segment. */ + /** + * Returns total size in bytes of all of files used by this segment (if + * {@code includeDocStores} is true), or the size of all files except the store + * files otherwise. + */ public long sizeInBytes(boolean includeDocStores) throws IOException { - if (sizeInBytes == -1) { - List files = files(); - final int size = files.size(); - sizeInBytes = 0; - for(int i=0;i