Skip to content

Apache Lucene open-source search software

LUCENE-6533: don't cache live docs in SlowCompositeReaderWrapper

Michael McCandless42b8b47b27fb
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 088c1dc6e8e..6812e0209f4 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -95,6 +95,10 @@ Bug fixes
* LUCENE-6527: Queries now get a dummy Similarity when scores are not needed
in order to not load unnecessary information like norms. (Adrien Grand)
+* LUCENE-6533: SlowCompositeReaderWrapper no longer caches its live docs
+ instance since this can prevent future improvements like a
+ disk-backed live docs (Adrien Grand, Mike McCandless)
+
Changes in Runtime Behavior
* LUCENE-6501: The subreader structure in ParallelCompositeReader
diff --git a/lucene/core/src/java/org/apache/lucene/index/SlowCompositeReaderWrapper.java b/lucene/core/src/java/org/apache/lucene/index/SlowCompositeReaderWrapper.java
index 1213ab4adc6..16b42349616 100644
--- a/lucene/core/src/java/org/apache/lucene/index/SlowCompositeReaderWrapper.java
+++ b/lucene/core/src/java/org/apache/lucene/index/SlowCompositeReaderWrapper.java
@@ -46,7 +46,6 @@ public final class SlowCompositeReaderWrapper extends LeafReader {
private final CompositeReader in;
private final Fields fields;
- private final Bits liveDocs;
private final boolean merging;
/** This method is sugar for getting an {@link LeafReader} from
@@ -66,7 +65,6 @@ public final class SlowCompositeReaderWrapper extends LeafReader {
super();
in = reader;
fields = MultiFields.getFields(in);
- liveDocs = MultiFields.getLiveDocs(in);
in.registerParentReader(this);
this.merging = merging;
}
@@ -230,7 +228,7 @@ public final class SlowCompositeReaderWrapper extends LeafReader {
@Override
public Bits getLiveDocs() {
ensureOpen();
- return liveDocs;
+ return MultiFields.getLiveDocs(in);
}
@Override
diff --git a/lucene/test-framework/src/test/org/apache/lucene/index/TestAssertingLeafReader.java b/lucene/test-framework/src/test/org/apache/lucene/index/TestAssertingLeafReader.java
new file mode 100644
index 00000000000..96c040df0f5
--- /dev/null
+++ b/lucene/test-framework/src/test/org/apache/lucene/index/TestAssertingLeafReader.java
@@ -0,0 +1,74 @@
+package org.apache.lucene.index;
+
+/*
+ * 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.
+ */
+
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.search.QueryUtils.FCInvisibleMultiReader;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.util.Bits;
+import org.apache.lucene.util.IOUtils;
+import org.apache.lucene.util.LuceneTestCase;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+public class TestAssertingLeafReader extends LuceneTestCase {
+ public void testAssertBits() throws Exception {
+ Directory dir = newDirectory();
+ IndexWriter w = new IndexWriter(dir, newIndexWriterConfig());
+ // Not deleted:
+ w.addDocument(new Document());
+
+ // Does get deleted:
+ Document doc = new Document();
+ doc.add(newStringField("id", "0", Field.Store.NO));
+ w.addDocument(doc);
+ w.commit();
+
+ w.deleteDocuments(new Term("id", "0"));
+ w.close();
+
+ // Now we have index with 1 segment with 2 docs one of which is marked deleted
+
+ IndexReader r = DirectoryReader.open(dir);
+ assertEquals(1, r.leaves().size());
+ assertEquals(2, r.maxDoc());
+ assertEquals(1, r.numDocs());
+
+ r = new AssertingDirectoryReader((DirectoryReader) r);
+
+ final IndexReader r2 = SlowCompositeReaderWrapper.wrap(r);
+
+ Thread thread = new Thread() {
+ @Override
+ public void run() {
+ for(LeafReaderContext context : r2.leaves()) {
+ context.reader().getLiveDocs().get(0);
+ }
+ }
+ };
+ thread.start();
+ thread.join();
+
+ IOUtils.close(r2, dir);
+ }
+}