Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lucene/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ Improvements
global queue min-score checking. Improves performance and consistency. (Mike Sokolov, Dzung Bui,
Ben Trent)

* GITHUB#15002: Remove synchronized WeakHashMap from IndexReader. This was added to help prevent
SIGSEGV with the old unsafe "mmap hack", which has been replaced by MemorySegments.
(Uwe Schindler, Robert Muir)

Optimizations
---------------------
* GITHUB#14011: Reduce allocation rate in HNSW concurrent merge. (Viliam Durina)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ protected BaseCompositeReader(R[] subReaders, Comparator<R> subReadersSorter) th
starts[i] = (int) maxDoc;
final IndexReader r = subReaders[i];
maxDoc += r.maxDoc(); // compute maxDocs
r.registerParentReader(this);
}

if (maxDoc > IndexWriter.getActualMaxDocs()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@ protected FilterLeafReader(LeafReader in) {
throw new NullPointerException("incoming LeafReader must not be null");
}
this.in = in;
in.registerParentReader(this);
}

@Override
Expand Down
36 changes: 1 addition & 35 deletions lucene/core/src/java/org/apache/lucene/index/IndexReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@

import java.io.Closeable;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.WeakHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.lucene.store.AlreadyClosedException;

Expand Down Expand Up @@ -146,24 +143,6 @@ public interface ClosedListener {
void onClose(CacheKey key) throws IOException;
}

private final Set<IndexReader> parentReaders =
Collections.synchronizedSet(
Collections.newSetFromMap(new WeakHashMap<IndexReader, Boolean>()));

/**
* Expert: This method is called by {@code IndexReader}s which wrap other readers (e.g. {@link
* CompositeReader} or {@link FilterLeafReader}) to register the parent at the child (this reader)
* on construction of the parent. When this reader is closed, it will mark all registered parents
* as closed, too. The references to parent readers are weak only, so they can be GCed once they
* are no longer in use.
*
* @lucene.experimental
*/
public final void registerParentReader(IndexReader reader) {
ensureOpen();
parentReaders.add(reader);
}

/**
* For test framework use only.
*
Expand All @@ -173,18 +152,6 @@ protected void notifyReaderClosedListeners() throws IOException {
// nothing to notify in the base impl
}

private void reportCloseToParentReaders() throws IOException {
synchronized (parentReaders) {
for (IndexReader parent : parentReaders) {
parent.closedByChild = true;
// cross memory barrier by a fake write:
parent.refCount.addAndGet(0);
// recurse:
parent.reportCloseToParentReaders();
}
}
}

/** Expert: returns the current refCount for this reader */
public final int getRefCount() {
// NOTE: don't ensureOpen, so that callers can see
Expand Down Expand Up @@ -253,8 +220,7 @@ public final void decRef() throws IOException {
final int rc = refCount.decrementAndGet();
if (rc == 0) {
closed = true;
try (Closeable _ = this::reportCloseToParentReaders;
Closeable _ = this::notifyReaderClosedListeners) {
try (Closeable _ = this::notifyReaderClosedListeners) {
doClose();
}
} else if (rc < 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ public ParallelLeafReader(
if (!closeSubReaders) {
reader.incRef();
}
reader.registerParentReader(this);
}
}

Expand Down
34 changes: 0 additions & 34 deletions lucene/core/src/test/org/apache/lucene/index/TestReaderClosed.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.apache.lucene.store.Directory;
import org.apache.lucene.tests.analysis.MockAnalyzer;
import org.apache.lucene.tests.analysis.MockTokenizer;
import org.apache.lucene.tests.index.OwnCacheKeyMultiReader;
import org.apache.lucene.tests.index.RandomIndexWriter;
import org.apache.lucene.tests.util.LuceneTestCase;
import org.apache.lucene.tests.util.TestUtil;
Expand Down Expand Up @@ -81,39 +80,6 @@ public void test() throws Exception {
}
}

// LUCENE-3800
public void testReaderChaining() throws Exception {
assertTrue(reader.getRefCount() > 0);
LeafReader wrappedReader = new ParallelLeafReader(getOnlyLeafReader(reader));

// We wrap with a OwnCacheKeyMultiReader so that closing the underlying reader
// does not terminate the threadpool (if that index searcher uses one)
IndexSearcher searcher = newSearcher(new OwnCacheKeyMultiReader(wrappedReader));

TermRangeQuery query = TermRangeQuery.newStringRange("field", "a", "z", true, true);
searcher.search(query, 5);
reader.close(); // close original child reader
try {
searcher.search(query, 5);
} catch (Exception e) {
AlreadyClosedException ace = null;
for (Throwable t = e; t != null; t = t.getCause()) {
if (t instanceof AlreadyClosedException) {
ace = (AlreadyClosedException) t;
}
}
if (ace == null) {
throw new AssertionError("Query failed, but not due to an AlreadyClosedException", e);
}
assertEquals(
"this IndexReader cannot be used anymore as one of its child readers was closed",
ace.getMessage());
} finally {
// close executor: in case of wrap-wrap-wrapping
searcher.getIndexReader().close();
}
}

@Override
public void tearDown() throws Exception {
dir.close();
Expand Down
Loading