2020-12-07 22:15:18 +01:00
|
|
|
package it.cavallium.dbengine.database.disk;
|
|
|
|
|
2023-02-09 23:34:25 +01:00
|
|
|
import static it.cavallium.dbengine.lucene.LuceneUtils.getLuceneIndexId;
|
2023-03-29 00:47:53 +02:00
|
|
|
import static it.cavallium.dbengine.utils.StreamUtils.LUCENE_POOL;
|
2023-02-24 17:19:25 +01:00
|
|
|
import static it.cavallium.dbengine.utils.StreamUtils.collectOn;
|
|
|
|
import static it.cavallium.dbengine.utils.StreamUtils.executing;
|
|
|
|
import static it.cavallium.dbengine.utils.StreamUtils.fastListing;
|
|
|
|
import static it.cavallium.dbengine.utils.StreamUtils.fastReducing;
|
|
|
|
import static it.cavallium.dbengine.utils.StreamUtils.fastSummingLong;
|
|
|
|
import static it.cavallium.dbengine.utils.StreamUtils.partitionByInt;
|
2023-02-09 23:34:25 +01:00
|
|
|
import static java.util.stream.Collectors.groupingBy;
|
2021-12-16 16:14:44 +01:00
|
|
|
|
2022-01-28 19:31:25 +01:00
|
|
|
import com.google.common.collect.Multimap;
|
2023-02-09 23:34:25 +01:00
|
|
|
import com.google.common.collect.Streams;
|
2021-10-30 11:13:46 +02:00
|
|
|
import io.micrometer.core.instrument.MeterRegistry;
|
2022-08-15 23:07:17 +02:00
|
|
|
import it.cavallium.dbengine.client.IBackuppable;
|
2021-11-19 19:03:31 +01:00
|
|
|
import it.cavallium.dbengine.client.query.QueryParser;
|
|
|
|
import it.cavallium.dbengine.client.query.current.data.Query;
|
2021-03-02 01:53:36 +01:00
|
|
|
import it.cavallium.dbengine.client.query.current.data.QueryParams;
|
2022-07-02 11:44:13 +02:00
|
|
|
import it.cavallium.dbengine.client.query.current.data.TotalHitsCount;
|
2021-11-07 17:46:40 +01:00
|
|
|
import it.cavallium.dbengine.database.LLIndexRequest;
|
2021-01-24 03:15:05 +01:00
|
|
|
import it.cavallium.dbengine.database.LLLuceneIndex;
|
2021-03-27 03:35:27 +01:00
|
|
|
import it.cavallium.dbengine.database.LLSearchResultShard;
|
2021-01-24 03:15:05 +01:00
|
|
|
import it.cavallium.dbengine.database.LLSnapshot;
|
2023-02-09 23:34:25 +01:00
|
|
|
import it.cavallium.dbengine.database.LLSnapshottable;
|
2021-01-24 03:15:05 +01:00
|
|
|
import it.cavallium.dbengine.database.LLTerm;
|
2022-01-28 19:31:25 +01:00
|
|
|
import it.cavallium.dbengine.database.LLUpdateDocument;
|
2023-02-09 23:34:25 +01:00
|
|
|
import it.cavallium.dbengine.database.SafeCloseable;
|
2022-07-23 02:42:48 +02:00
|
|
|
import it.cavallium.dbengine.lucene.LuceneCloseable;
|
2021-10-13 12:25:32 +02:00
|
|
|
import it.cavallium.dbengine.lucene.LuceneHacks;
|
2021-07-06 01:30:37 +02:00
|
|
|
import it.cavallium.dbengine.lucene.LuceneUtils;
|
2021-11-19 19:03:31 +01:00
|
|
|
import it.cavallium.dbengine.lucene.collector.Buckets;
|
2022-01-28 19:31:25 +01:00
|
|
|
import it.cavallium.dbengine.lucene.mlt.MoreLikeThisTransformer;
|
2021-10-13 12:25:32 +02:00
|
|
|
import it.cavallium.dbengine.lucene.searcher.AdaptiveMultiSearcher;
|
2021-11-18 17:13:53 +01:00
|
|
|
import it.cavallium.dbengine.lucene.searcher.BucketParams;
|
|
|
|
import it.cavallium.dbengine.lucene.searcher.DecimalBucketMultiSearcher;
|
2022-01-28 21:12:10 +01:00
|
|
|
import it.cavallium.dbengine.lucene.searcher.GlobalQueryRewrite;
|
2021-07-06 01:30:37 +02:00
|
|
|
import it.cavallium.dbengine.lucene.searcher.LocalQueryParams;
|
2022-07-02 11:44:13 +02:00
|
|
|
import it.cavallium.dbengine.lucene.searcher.LuceneSearchResult;
|
2021-10-13 12:25:32 +02:00
|
|
|
import it.cavallium.dbengine.lucene.searcher.MultiSearcher;
|
2022-03-05 15:46:40 +01:00
|
|
|
import it.cavallium.dbengine.rpc.current.data.IndicizerAnalyzers;
|
|
|
|
import it.cavallium.dbengine.rpc.current.data.IndicizerSimilarities;
|
|
|
|
import it.cavallium.dbengine.rpc.current.data.LuceneOptions;
|
2023-02-09 23:34:25 +01:00
|
|
|
import it.cavallium.dbengine.utils.DBException;
|
2022-06-30 13:54:55 +02:00
|
|
|
import it.cavallium.dbengine.utils.SimpleResource;
|
2023-02-24 17:19:25 +01:00
|
|
|
import it.cavallium.dbengine.utils.StreamUtils;
|
2022-03-05 15:46:40 +01:00
|
|
|
import it.unimi.dsi.fastutil.ints.IntList;
|
2021-10-13 00:23:56 +02:00
|
|
|
import java.io.Closeable;
|
2020-12-07 22:15:18 +01:00
|
|
|
import java.io.IOException;
|
2022-07-02 11:44:13 +02:00
|
|
|
import java.time.Duration;
|
2021-05-11 21:59:05 +02:00
|
|
|
import java.util.ArrayList;
|
2022-03-05 15:46:40 +01:00
|
|
|
import java.util.HashSet;
|
2021-05-28 16:04:59 +02:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map.Entry;
|
2022-03-05 15:46:40 +01:00
|
|
|
import java.util.Objects;
|
2021-02-04 22:42:57 +01:00
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
2020-12-07 22:15:18 +01:00
|
|
|
import java.util.concurrent.atomic.AtomicLong;
|
2023-02-26 21:41:20 +01:00
|
|
|
import java.util.function.Function;
|
2023-02-09 23:34:25 +01:00
|
|
|
import java.util.stream.Stream;
|
2022-03-13 11:01:51 +01:00
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
|
import org.apache.logging.log4j.Logger;
|
2021-09-20 11:52:21 +02:00
|
|
|
import org.apache.lucene.analysis.miscellaneous.PerFieldAnalyzerWrapper;
|
|
|
|
import org.apache.lucene.search.similarities.PerFieldSimilarityWrapper;
|
2021-11-19 19:03:31 +01:00
|
|
|
import org.jetbrains.annotations.NotNull;
|
2020-12-07 22:15:18 +01:00
|
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
|
2022-07-23 02:42:48 +02:00
|
|
|
public class LLLocalMultiLuceneIndex extends SimpleResource implements LLLuceneIndex, LuceneCloseable {
|
2020-12-07 22:15:18 +01:00
|
|
|
|
2022-03-13 11:01:51 +01:00
|
|
|
private static final Logger LOG = LogManager.getLogger(LLLuceneIndex.class);
|
|
|
|
|
2022-03-05 15:46:40 +01:00
|
|
|
private final String clusterName;
|
|
|
|
private final boolean lowMemory;
|
2021-10-30 11:13:46 +02:00
|
|
|
private final MeterRegistry meterRegistry;
|
2022-03-05 15:46:40 +01:00
|
|
|
private final ConcurrentHashMap<Long, List<LLSnapshot>> registeredSnapshots = new ConcurrentHashMap<>();
|
2020-12-07 22:15:18 +01:00
|
|
|
private final AtomicLong nextSnapshotNumber = new AtomicLong(1);
|
2022-03-05 15:46:40 +01:00
|
|
|
private final LLLocalLuceneIndex[] luceneIndicesById;
|
|
|
|
private final List<LLLocalLuceneIndex> luceneIndicesSet;
|
|
|
|
private final int totalShards;
|
2021-09-20 11:52:21 +02:00
|
|
|
private final PerFieldAnalyzerWrapper luceneAnalyzer;
|
|
|
|
private final PerFieldSimilarityWrapper luceneSimilarity;
|
2021-06-25 20:07:19 +02:00
|
|
|
|
2021-10-13 12:25:32 +02:00
|
|
|
private final MultiSearcher multiSearcher;
|
2021-11-18 17:13:53 +01:00
|
|
|
private final DecimalBucketMultiSearcher decimalBucketMultiSearcher = new DecimalBucketMultiSearcher();
|
2021-06-25 20:07:19 +02:00
|
|
|
|
2023-02-09 23:34:25 +01:00
|
|
|
public LLLocalMultiLuceneIndex(MeterRegistry meterRegistry,
|
2021-12-30 17:28:06 +01:00
|
|
|
String clusterName,
|
2022-03-05 15:46:40 +01:00
|
|
|
IntList activeShards,
|
|
|
|
int totalShards,
|
2021-05-28 16:04:59 +02:00
|
|
|
IndicizerAnalyzers indicizerAnalyzers,
|
|
|
|
IndicizerSimilarities indicizerSimilarities,
|
2021-10-13 00:23:56 +02:00
|
|
|
LuceneOptions luceneOptions,
|
2023-02-09 23:34:25 +01:00
|
|
|
@Nullable LuceneHacks luceneHacks) {
|
2020-12-07 22:15:18 +01:00
|
|
|
|
2022-03-05 15:46:40 +01:00
|
|
|
if (totalShards <= 1 || totalShards > 100) {
|
2023-02-09 23:34:25 +01:00
|
|
|
throw new DBException("Unsupported instances count: " + totalShards);
|
2020-12-07 22:15:18 +01:00
|
|
|
}
|
|
|
|
|
2021-10-30 11:13:46 +02:00
|
|
|
this.meterRegistry = meterRegistry;
|
2022-03-05 15:46:40 +01:00
|
|
|
LLLocalLuceneIndex[] luceneIndices = new LLLocalLuceneIndex[totalShards];
|
|
|
|
for (int i = 0; i < totalShards; i++) {
|
|
|
|
if (!activeShards.contains(i)) {
|
|
|
|
continue;
|
2020-12-07 22:15:18 +01:00
|
|
|
}
|
2023-02-09 23:34:25 +01:00
|
|
|
luceneIndices[i] = new LLLocalLuceneIndex(meterRegistry,
|
2021-12-30 17:28:06 +01:00
|
|
|
clusterName,
|
2022-03-05 15:46:40 +01:00
|
|
|
i,
|
2021-05-28 16:04:59 +02:00
|
|
|
indicizerAnalyzers,
|
|
|
|
indicizerSimilarities,
|
2021-10-13 00:23:56 +02:00
|
|
|
luceneOptions,
|
2023-02-09 23:34:25 +01:00
|
|
|
luceneHacks
|
2020-12-07 22:15:18 +01:00
|
|
|
);
|
|
|
|
}
|
2022-03-05 15:46:40 +01:00
|
|
|
this.clusterName = clusterName;
|
|
|
|
this.totalShards = totalShards;
|
|
|
|
this.luceneIndicesById = luceneIndices;
|
|
|
|
var luceneIndicesSet = new HashSet<LLLocalLuceneIndex>();
|
|
|
|
for (var luceneIndex : luceneIndices) {
|
|
|
|
if (luceneIndex != null) {
|
|
|
|
luceneIndicesSet.add(luceneIndex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.luceneIndicesSet = new ArrayList<>(luceneIndicesSet);
|
2021-09-20 11:52:21 +02:00
|
|
|
this.luceneAnalyzer = LuceneUtils.toPerFieldAnalyzerWrapper(indicizerAnalyzers);
|
|
|
|
this.luceneSimilarity = LuceneUtils.toPerFieldSimilarityWrapper(indicizerSimilarities);
|
2022-03-05 15:46:40 +01:00
|
|
|
this.lowMemory = luceneOptions.lowMemory();
|
2021-10-13 00:23:56 +02:00
|
|
|
|
2021-12-12 23:40:30 +01:00
|
|
|
var maxInMemoryResultEntries = luceneOptions.maxInMemoryResultEntries();
|
2021-10-13 00:23:56 +02:00
|
|
|
if (luceneHacks != null && luceneHacks.customMultiSearcher() != null) {
|
|
|
|
multiSearcher = luceneHacks.customMultiSearcher().get();
|
|
|
|
} else {
|
2023-02-09 23:34:25 +01:00
|
|
|
multiSearcher = new AdaptiveMultiSearcher(maxInMemoryResultEntries);
|
2021-10-13 00:23:56 +02:00
|
|
|
}
|
2020-12-07 22:15:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private LLLocalLuceneIndex getLuceneIndex(LLTerm id) {
|
2022-03-05 15:46:40 +01:00
|
|
|
return Objects.requireNonNull(luceneIndicesById[LuceneUtils.getLuceneIndexId(id, totalShards)]);
|
2020-12-07 22:15:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getLuceneIndexName() {
|
2022-03-05 15:46:40 +01:00
|
|
|
return clusterName;
|
2020-12-07 22:15:18 +01:00
|
|
|
}
|
|
|
|
|
2023-02-09 23:34:25 +01:00
|
|
|
private LLIndexSearchers getIndexSearchers(LLSnapshot snapshot) {
|
|
|
|
// Resolve the snapshot of each shard
|
2023-03-29 00:47:53 +02:00
|
|
|
return LLIndexSearchers.of(StreamUtils.toListOn(StreamUtils.LUCENE_POOL,
|
2023-02-24 17:19:25 +01:00
|
|
|
Streams.mapWithIndex(this.luceneIndicesSet.stream(), (luceneIndex, index) -> {
|
|
|
|
var subSnapshot = resolveSnapshot(snapshot, (int) index);
|
|
|
|
return luceneIndex.retrieveSearcher(subSnapshot);
|
|
|
|
})
|
|
|
|
));
|
2021-09-19 19:59:37 +02:00
|
|
|
}
|
|
|
|
|
2020-12-07 22:15:18 +01:00
|
|
|
@Override
|
2023-02-09 23:34:25 +01:00
|
|
|
public void addDocument(LLTerm id, LLUpdateDocument doc) {
|
|
|
|
getLuceneIndex(id).addDocument(id, doc);
|
2020-12-07 22:15:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-02-09 23:34:25 +01:00
|
|
|
public long addDocuments(boolean atomic, Stream<Entry<LLTerm, LLUpdateDocument>> documents) {
|
2023-03-29 00:47:53 +02:00
|
|
|
return collectOn(LUCENE_POOL,
|
2023-02-24 17:19:25 +01:00
|
|
|
partitionByInt(term -> getLuceneIndexId(term.getKey(), totalShards), documents)
|
|
|
|
.map(entry -> luceneIndicesById[entry.key()].addDocuments(atomic, entry.values().stream())),
|
|
|
|
fastSummingLong()
|
|
|
|
);
|
2020-12-07 22:15:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-02-09 23:34:25 +01:00
|
|
|
public void deleteDocument(LLTerm id) {
|
|
|
|
getLuceneIndex(id).deleteDocument(id);
|
2020-12-07 22:15:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-02-09 23:34:25 +01:00
|
|
|
public void update(LLTerm id, LLIndexRequest request) {
|
|
|
|
getLuceneIndex(id).update(id, request);
|
2020-12-07 22:15:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-02-09 23:34:25 +01:00
|
|
|
public long updateDocuments(Stream<Entry<LLTerm, LLUpdateDocument>> documents) {
|
2023-03-29 00:47:53 +02:00
|
|
|
return collectOn(LUCENE_POOL,
|
2023-02-24 17:19:25 +01:00
|
|
|
partitionByInt(term -> getLuceneIndexId(term.getKey(), totalShards), documents)
|
|
|
|
.map(entry -> luceneIndicesById[entry.key()].updateDocuments(entry.values().stream())),
|
|
|
|
fastSummingLong()
|
|
|
|
);
|
2020-12-07 22:15:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-02-09 23:34:25 +01:00
|
|
|
public void deleteAll() {
|
|
|
|
luceneIndicesSet.forEach(LLLuceneIndex::deleteAll);
|
2020-12-07 22:15:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private LLSnapshot resolveSnapshot(LLSnapshot multiSnapshot, int instanceId) {
|
|
|
|
if (multiSnapshot != null) {
|
2022-03-05 15:46:40 +01:00
|
|
|
return registeredSnapshots.get(multiSnapshot.getSequenceNumber()).get(instanceId);
|
2020-12-07 22:15:18 +01:00
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-02-09 23:34:25 +01:00
|
|
|
public Stream<LLSearchResultShard> moreLikeThis(@Nullable LLSnapshot snapshot,
|
2021-03-02 01:53:36 +01:00
|
|
|
QueryParams queryParams,
|
|
|
|
String keyFieldName,
|
2022-01-28 19:31:25 +01:00
|
|
|
Multimap<String, String> mltDocumentFields) {
|
2021-11-16 23:19:23 +01:00
|
|
|
LocalQueryParams localQueryParams = LuceneUtils.toLocalQueryParams(queryParams, luceneAnalyzer);
|
2023-02-26 21:41:20 +01:00
|
|
|
try (var searchers = this.getIndexSearchers(snapshot)) {
|
|
|
|
var transformer = new MoreLikeThisTransformer(mltDocumentFields, luceneAnalyzer, luceneSimilarity);
|
2021-09-19 19:59:37 +02:00
|
|
|
|
2023-02-26 21:41:20 +01:00
|
|
|
// Collect all the shards results into a single global result
|
|
|
|
LuceneSearchResult result = multiSearcher.collectMulti(searchers,
|
|
|
|
localQueryParams,
|
|
|
|
keyFieldName,
|
|
|
|
transformer,
|
|
|
|
Function.identity()
|
|
|
|
);
|
2023-02-09 23:34:25 +01:00
|
|
|
|
2023-02-26 21:41:20 +01:00
|
|
|
// Transform the result type
|
|
|
|
return Stream.of(new LLSearchResultShard(result.results(), result.totalHitsCount()));
|
|
|
|
}
|
2020-12-07 22:15:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-02-09 23:34:25 +01:00
|
|
|
public Stream<LLSearchResultShard> search(@Nullable LLSnapshot snapshot,
|
2021-03-02 01:53:36 +01:00
|
|
|
QueryParams queryParams,
|
2022-02-26 03:28:20 +01:00
|
|
|
@Nullable String keyFieldName) {
|
2023-02-09 23:34:25 +01:00
|
|
|
LuceneSearchResult result = searchInternal(snapshot, queryParams, keyFieldName);
|
|
|
|
// Transform the result type
|
2023-02-22 23:31:05 +01:00
|
|
|
var shard = new LLSearchResultShard(result.results(), result.totalHitsCount());
|
2023-02-26 21:41:20 +01:00
|
|
|
return Stream.of(shard);
|
2022-07-02 11:44:13 +02:00
|
|
|
}
|
|
|
|
|
2023-02-09 23:34:25 +01:00
|
|
|
private LuceneSearchResult searchInternal(@Nullable LLSnapshot snapshot,
|
2022-07-02 11:44:13 +02:00
|
|
|
QueryParams queryParams,
|
|
|
|
@Nullable String keyFieldName) {
|
2021-11-16 23:19:23 +01:00
|
|
|
LocalQueryParams localQueryParams = LuceneUtils.toLocalQueryParams(queryParams, luceneAnalyzer);
|
2023-02-26 21:41:20 +01:00
|
|
|
try (var searchers = getIndexSearchers(snapshot)) {
|
2021-04-14 02:37:03 +02:00
|
|
|
|
2023-02-26 21:41:20 +01:00
|
|
|
// Collect all the shards results into a single global result
|
|
|
|
return multiSearcher.collectMulti(searchers,
|
|
|
|
localQueryParams,
|
|
|
|
keyFieldName,
|
|
|
|
GlobalQueryRewrite.NO_REWRITE,
|
|
|
|
Function.identity()
|
|
|
|
);
|
|
|
|
}
|
2022-07-02 11:44:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-02-09 23:34:25 +01:00
|
|
|
public TotalHitsCount count(@Nullable LLSnapshot snapshot, Query query, @Nullable Duration timeout) {
|
2022-07-02 11:44:13 +02:00
|
|
|
var params = LuceneUtils.getCountQueryParams(query);
|
2023-02-09 23:34:25 +01:00
|
|
|
var result = this.searchInternal(snapshot, params, null);
|
|
|
|
return result != null ? result.totalHitsCount() : TotalHitsCount.of(0, true);
|
2020-12-07 22:15:18 +01:00
|
|
|
}
|
|
|
|
|
2021-11-18 17:13:53 +01:00
|
|
|
@Override
|
2023-02-09 23:34:25 +01:00
|
|
|
public Buckets computeBuckets(@Nullable LLSnapshot snapshot,
|
2021-11-19 19:03:31 +01:00
|
|
|
@NotNull List<Query> queries,
|
|
|
|
@Nullable Query normalizationQuery,
|
2021-11-18 17:13:53 +01:00
|
|
|
BucketParams bucketParams) {
|
2021-11-19 19:03:31 +01:00
|
|
|
List<org.apache.lucene.search.Query> localQueries = new ArrayList<>(queries.size());
|
|
|
|
for (Query query : queries) {
|
|
|
|
localQueries.add(QueryParser.toQuery(query, luceneAnalyzer));
|
|
|
|
}
|
|
|
|
var localNormalizationQuery = QueryParser.toQuery(normalizationQuery, luceneAnalyzer);
|
2023-02-26 21:41:20 +01:00
|
|
|
try (var searchers = getIndexSearchers(snapshot)) {
|
2021-11-18 17:13:53 +01:00
|
|
|
|
2023-02-26 21:41:20 +01:00
|
|
|
// Collect all the shards results into a single global result
|
|
|
|
return decimalBucketMultiSearcher.collectMulti(searchers, bucketParams, localQueries, localNormalizationQuery);
|
|
|
|
}
|
2021-11-18 17:13:53 +01:00
|
|
|
}
|
|
|
|
|
2020-12-07 22:15:18 +01:00
|
|
|
@Override
|
2022-06-30 13:54:55 +02:00
|
|
|
protected void onClose() {
|
2023-03-29 00:47:53 +02:00
|
|
|
collectOn(StreamUtils.LUCENE_POOL, luceneIndicesSet.stream(), executing(SafeCloseable::close));
|
2023-02-09 23:34:25 +01:00
|
|
|
if (multiSearcher instanceof Closeable closeable) {
|
|
|
|
try {
|
|
|
|
closeable.close();
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
2020-12-07 22:15:18 +01:00
|
|
|
}
|
|
|
|
|
2021-02-03 13:48:30 +01:00
|
|
|
@Override
|
2023-02-09 23:34:25 +01:00
|
|
|
public void flush() {
|
2023-03-29 00:47:53 +02:00
|
|
|
collectOn(StreamUtils.LUCENE_POOL, luceneIndicesSet.stream(), executing(LLLuceneIndex::flush));
|
2022-06-21 14:35:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-02-09 23:34:25 +01:00
|
|
|
public void waitForMerges() {
|
2023-03-29 00:47:53 +02:00
|
|
|
collectOn(StreamUtils.LUCENE_POOL, luceneIndicesSet.stream(), executing(LLLuceneIndex::waitForMerges));
|
2022-06-21 14:35:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-02-09 23:34:25 +01:00
|
|
|
public void waitForLastMerges() {
|
2023-03-29 00:47:53 +02:00
|
|
|
collectOn(StreamUtils.LUCENE_POOL, luceneIndicesSet.stream(), executing(LLLuceneIndex::waitForLastMerges));
|
2021-02-03 13:48:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-02-09 23:34:25 +01:00
|
|
|
public void refresh(boolean force) {
|
2023-03-29 00:47:53 +02:00
|
|
|
collectOn(StreamUtils.LUCENE_POOL, luceneIndicesSet.stream(), executing(index -> index.refresh(force)));
|
2021-02-03 13:48:30 +01:00
|
|
|
}
|
|
|
|
|
2020-12-07 22:15:18 +01:00
|
|
|
@Override
|
2023-02-09 23:34:25 +01:00
|
|
|
public LLSnapshot takeSnapshot() {
|
|
|
|
// Generate next snapshot index
|
|
|
|
var snapshotIndex = nextSnapshotNumber.getAndIncrement();
|
2023-03-29 00:47:53 +02:00
|
|
|
var snapshot = collectOn(StreamUtils.LUCENE_POOL,
|
2023-02-24 17:19:25 +01:00
|
|
|
luceneIndicesSet.stream().map(LLSnapshottable::takeSnapshot),
|
|
|
|
fastListing()
|
|
|
|
);
|
2023-02-09 23:34:25 +01:00
|
|
|
registeredSnapshots.put(snapshotIndex, snapshot);
|
|
|
|
return new LLSnapshot(snapshotIndex);
|
2020-12-07 22:15:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-02-09 23:34:25 +01:00
|
|
|
public void releaseSnapshot(LLSnapshot snapshot) {
|
|
|
|
var list = registeredSnapshots.remove(snapshot.getSequenceNumber());
|
|
|
|
for (int shardIndex = 0; shardIndex < list.size(); shardIndex++) {
|
|
|
|
var luceneIndex = luceneIndicesSet.get(shardIndex);
|
|
|
|
LLSnapshot instanceSnapshot = list.get(shardIndex);
|
|
|
|
luceneIndex.releaseSnapshot(instanceSnapshot);
|
|
|
|
}
|
2020-12-07 22:15:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isLowMemoryMode() {
|
2022-03-05 15:46:40 +01:00
|
|
|
return lowMemory;
|
2020-12-07 22:15:18 +01:00
|
|
|
}
|
2022-08-15 23:07:17 +02:00
|
|
|
|
|
|
|
@Override
|
2023-02-09 23:34:25 +01:00
|
|
|
public void pauseForBackup() {
|
2023-03-29 00:47:53 +02:00
|
|
|
collectOn(StreamUtils.LUCENE_POOL, luceneIndicesSet.stream(), executing(LLLuceneIndex::pauseForBackup));
|
2022-08-15 23:07:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-02-09 23:34:25 +01:00
|
|
|
public void resumeAfterBackup() {
|
2023-03-29 00:47:53 +02:00
|
|
|
collectOn(StreamUtils.LUCENE_POOL, luceneIndicesSet.stream(), executing(LLLuceneIndex::resumeAfterBackup));
|
2022-08-15 23:07:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isPaused() {
|
2023-02-09 23:34:25 +01:00
|
|
|
return this.luceneIndicesSet.stream().anyMatch(IBackuppable::isPaused);
|
2022-08-15 23:07:17 +02:00
|
|
|
}
|
2020-12-07 22:15:18 +01:00
|
|
|
}
|