Do not release cached searcher
This commit is contained in:
parent
23fa46c775
commit
996165c3cc
@ -3,21 +3,16 @@ package it.cavallium.dbengine.database.disk;
|
||||
import io.net5.buffer.api.Drop;
|
||||
import io.net5.buffer.api.Owned;
|
||||
import it.cavallium.dbengine.database.LiveResourceSupport;
|
||||
import java.io.IOException;
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.search.IndexSearcher;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class LLIndexSearcher extends LiveResourceSupport<LLIndexSearcher, LLIndexSearcher> {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(LLIndexSearcher.class);
|
||||
|
||||
private IndexSearcher indexSearcher;
|
||||
private final boolean decRef;
|
||||
|
||||
public LLIndexSearcher(IndexSearcher indexSearcher, boolean decRef, Drop<LLIndexSearcher> drop) {
|
||||
super(new CloseOnDrop(drop));
|
||||
super(drop);
|
||||
this.indexSearcher = indexSearcher;
|
||||
this.decRef = decRef;
|
||||
}
|
||||
@ -51,26 +46,4 @@ public class LLIndexSearcher extends LiveResourceSupport<LLIndexSearcher, LLInde
|
||||
this.indexSearcher = null;
|
||||
}
|
||||
|
||||
private static class CloseOnDrop implements Drop<LLIndexSearcher> {
|
||||
|
||||
private final Drop<LLIndexSearcher> delegate;
|
||||
|
||||
public CloseOnDrop(Drop<LLIndexSearcher> drop) {
|
||||
if (drop instanceof CloseOnDrop closeOnDrop) {
|
||||
this.delegate = closeOnDrop.delegate;
|
||||
} else {
|
||||
this.delegate = drop;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drop(LLIndexSearcher obj) {
|
||||
try {
|
||||
obj.indexSearcher.getIndexReader().decRef();
|
||||
} catch (IOException ex) {
|
||||
logger.error("Failed to drop IndexReader", ex);
|
||||
}
|
||||
delegate.drop(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user