You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sh...@apache.org on 2011/01/12 15:06:16 UTC
svn commit: r1058147 - in /lucene/dev/branches/branch_3x/lucene: CHANGES.txt
src/java/org/apache/lucene/index/SegmentInfo.java
src/test/org/apache/lucene/index/TestSegmentInfo.java
Author: shaie
Date: Wed Jan 12 14:06:15 2011
New Revision: 1058147
URL: http://svn.apache.org/viewvc?rev=1058147&view=rev
Log:
LUCENE-2860: SegmentInfo.sizeInBytes ignore includeDocStore when caching
Added:
lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestSegmentInfo.java (with props)
Modified:
lucene/dev/branches/branch_3x/lucene/CHANGES.txt
lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/SegmentInfo.java
Modified: lucene/dev/branches/branch_3x/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/CHANGES.txt?rev=1058147&r1=1058146&r2=1058147&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/branch_3x/lucene/CHANGES.txt Wed Jan 12 14:06:15 2011
@@ -308,6 +308,9 @@ Bug fixes
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
Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/SegmentInfo.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/SegmentInfo.java?rev=1058147&r1=1058146&r2=1058147&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/SegmentInfo.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/SegmentInfo.java Wed Jan 12 14:06:15 2011
@@ -72,10 +72,11 @@ public final class SegmentInfo {
// and true for newly created merged segments (both
// compound and non compound).
- private List<String> files; // cached list of files that this segment uses
+ private List<String> 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 @@ public final class SegmentInfo {
}
}
- /** 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<String> files = files();
- final int size = files.size();
- sizeInBytes = 0;
- for(int i=0;i<size;i++) {
- final String fileName = files.get(i);
- if (!includeDocStores && IndexFileNames.isDocStoreFile(fileName)) {
+ if (includeDocStores) {
+ if (sizeInBytesWithStore != -1) return sizeInBytesWithStore;
+ sizeInBytesWithStore = 0;
+ for (final String fileName : files()) {
+ // We don't count bytes used by a shared doc store against this segment
+ if (docStoreOffset == -1 || !IndexFileNames.isDocStoreFile(fileName)) {
+ sizeInBytesWithStore += dir.fileLength(fileName);
+ }
+ }
+ return sizeInBytesWithStore;
+ } else {
+ if (sizeInBytesNoStore != -1) return sizeInBytesNoStore;
+ sizeInBytesNoStore = 0;
+ for (final String fileName : files()) {
+ if (IndexFileNames.isDocStoreFile(fileName)) {
continue;
}
- // We don't count bytes used by a shared doc store
- // against this segment:
- if (docStoreOffset == -1 || !IndexFileNames.isDocStoreFile(fileName))
- sizeInBytes += dir.fileLength(fileName);
+ sizeInBytesNoStore += dir.fileLength(fileName);
}
+ return sizeInBytesNoStore;
}
- return sizeInBytes;
}
public boolean getHasVectors() throws IOException {
@@ -708,7 +717,8 @@ public final class SegmentInfo {
* files this segment has. */
private void clearFiles() {
files = null;
- sizeInBytes = -1;
+ sizeInBytesNoStore = -1;
+ sizeInBytesWithStore = -1;
}
/** {@inheritDoc} */
Added: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestSegmentInfo.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestSegmentInfo.java?rev=1058147&view=auto
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestSegmentInfo.java (added)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestSegmentInfo.java Wed Jan 12 14:06:15 2011
@@ -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();
+ }
+
+}