Handle discards
This commit is contained in:
parent
d8419a4c1b
commit
fd202d8dfa
@ -14,6 +14,7 @@ import it.cavallium.dbengine.database.LLSearchResultShard.ResourcesLLSearchResul
|
||||
import it.cavallium.dbengine.database.LLSnapshot;
|
||||
import it.cavallium.dbengine.database.LLTerm;
|
||||
import it.cavallium.dbengine.database.LLUpdateDocument;
|
||||
import it.cavallium.dbengine.database.LLUtils;
|
||||
import it.cavallium.dbengine.database.SafeCloseable;
|
||||
import it.cavallium.dbengine.lucene.LuceneCloseable;
|
||||
import it.cavallium.dbengine.lucene.LuceneUtils;
|
||||
@ -117,7 +118,7 @@ public class LuceneIndexImpl<T, U> implements LuceneIndex<T, U> {
|
||||
.mapNotNull(shards -> mergeResults(queryParams, shards))
|
||||
.map(llSearchResult -> mapResults(llSearchResult))
|
||||
.defaultIfEmpty(Hits.empty())
|
||||
.doOnDiscard(DiscardingCloseable.class, DiscardingCloseable::close);
|
||||
.doOnDiscard(DiscardingCloseable.class, LLUtils::onDiscard);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -131,7 +132,7 @@ public class LuceneIndexImpl<T, U> implements LuceneIndex<T, U> {
|
||||
.mapNotNull(shards -> mergeResults(queryParams, shards))
|
||||
.map(llSearchResult -> mapResults(llSearchResult))
|
||||
.defaultIfEmpty(Hits.empty())
|
||||
.doOnDiscard(DiscardingCloseable.class, DiscardingCloseable::close);
|
||||
.doOnDiscard(DiscardingCloseable.class, LLUtils::onDiscard);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -158,7 +159,7 @@ public class LuceneIndexImpl<T, U> implements LuceneIndex<T, U> {
|
||||
public Mono<TotalHitsCount> count(@Nullable CompositeSnapshot snapshot, Query query) {
|
||||
return luceneIndex
|
||||
.count(resolveSnapshot(snapshot), query, MAX_COUNT_TIME)
|
||||
.doOnDiscard(DiscardingCloseable.class, DiscardingCloseable::close);
|
||||
.doOnDiscard(DiscardingCloseable.class, LLUtils::onDiscard);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -130,7 +130,7 @@ public class LLMultiLuceneIndex implements LLLuceneIndex {
|
||||
queryParams,
|
||||
keyFieldName,
|
||||
mltDocumentFields
|
||||
)).doOnDiscard(DiscardingCloseable.class, SafeCloseable::close);
|
||||
)).doOnDiscard(DiscardingCloseable.class, LLUtils::onDiscard);
|
||||
}
|
||||
|
||||
private Mono<Buckets> mergeShards(List<Buckets> shards) {
|
||||
@ -166,7 +166,7 @@ public class LLMultiLuceneIndex implements LLLuceneIndex {
|
||||
return luceneIndicesFlux.flatMap(luceneIndex -> luceneIndex.search(snapshot,
|
||||
queryParams,
|
||||
keyFieldName
|
||||
)).doOnDiscard(DiscardingCloseable.class, SafeCloseable::close);
|
||||
)).doOnDiscard(DiscardingCloseable.class, LLUtils::onDiscard);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -178,7 +178,7 @@ public class LLMultiLuceneIndex implements LLLuceneIndex {
|
||||
queries,
|
||||
normalizationQuery,
|
||||
bucketParams
|
||||
)).collectList().flatMap(this::mergeShards).doOnDiscard(DiscardingCloseable.class, SafeCloseable::close);
|
||||
)).collectList().flatMap(this::mergeShards).doOnDiscard(DiscardingCloseable.class, LLUtils::onDiscard);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -115,7 +115,7 @@ public class DatabaseMapDictionary<T, U> extends DatabaseMapDictionaryDeep<T, U,
|
||||
return stagesFlux.doOnNext(e -> e.getValue().close())
|
||||
.doOnDiscard(Entry.class, e -> {
|
||||
if (e.getValue() instanceof DatabaseStageEntry<?> resource) {
|
||||
resource.close();
|
||||
LLUtils.onDiscard(resource);
|
||||
}
|
||||
})
|
||||
.map(Entry::getKey);
|
||||
|
@ -164,7 +164,7 @@ public class LLLocalMultiLuceneIndex extends SimpleResource implements LLLuceneI
|
||||
.collectList()
|
||||
.doOnDiscard(LLIndexSearcher.class, indexSearcher -> {
|
||||
try {
|
||||
indexSearcher.close();
|
||||
LLUtils.onDiscard(indexSearcher);
|
||||
} catch (UncheckedIOException ex) {
|
||||
LOG.error("Failed to close an index searcher", ex);
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ public class CountMultiSearcher implements MultiSearcher {
|
||||
|
||||
return new LuceneSearchResult(totalHitsCount, Flux.empty());
|
||||
})
|
||||
.doOnDiscard(LuceneSearchResult.class, luceneSearchResult -> luceneSearchResult.close()),
|
||||
.doOnDiscard(LuceneSearchResult.class, LLUtils::onDiscard),
|
||||
LLUtils::finalizeResource);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user