mkhludnev commented on code in PR #4749: URL: https://github.com/apache/solr/pull/4749#discussion_r3834155502
########## solr/core/src/java/org/apache/solr/search/join/aijoin/AIJoinIndex.java: ########## @@ -0,0 +1,447 @@ +/* + * 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. + */ +package org.apache.solr.search.join.aijoin; + +import java.io.Closeable; +import java.io.IOException; +import java.lang.invoke.MethodHandles; +import java.util.AbstractMap; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionException; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.function.Predicate; +import org.apache.lucene.index.ConcurrentMergeScheduler; +import org.apache.lucene.index.FieldInfo; +import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.IndexWriter; +import org.apache.lucene.index.IndexWriterConfig; +import org.apache.lucene.index.LeafReaderContext; +import org.apache.lucene.index.MergeScheduler; +import org.apache.lucene.search.IndexSearcher; +import org.apache.lucene.search.Query; +import org.apache.lucene.search.SearcherManager; +import org.apache.lucene.store.Directory; +import org.apache.lucene.util.IOUtils; +import org.apache.solr.search.join.aijoin.AIJoinUtil.JoinColumnModel; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * The auxiliary join index: a self-maintaining sidecar persisting per (from-segment, to-segment) + * doc id mappings, so query-time joining reduces to bitset translation. It owns the sidecar's + * {@link IndexWriter} and {@link SearcherManager}; pair columns are built lazily when an {@link + * AIJoinQuery} first needs them, so users only construct an instance once, create queries with + * {@link #newJoinQuery} and search them with a bare to-side {@link IndexSearcher}: + * + * <pre class="prettyprint"> + * AIJoinIndex joinIndex = new AIJoinIndex(joinDir); // once per process + * Query q = joinIndex.newJoinQuery(fromField, fromQuery, fromSearcher, toField); + * TopDocs hits = toSearcher.search(q, 10); + * ... + * joinIndex.close(); // app shutdown + * </pre> + * + * <p>After either side reopens, the next query builds only the missing (from, to) segment pairs: + * pair columns are addressed by both sides' persistent segment keys, which survive reopens. Pair + * columns orphaned by merges are not reclaimed yet; see {@code README.md} in this package. + */ +public final class AIJoinIndex implements Closeable { + + private final IndexWriter writer; + private final SearcherManager manager; + + /** + * Dedups concurrent builders per pair field name: the thread that installs the future writes the + * pair, others wait on it. Completed futures stay put so a builder that raced a not-yet-visible + * refresh cannot write a duplicate pair column. + */ + private final ConcurrentHashMap<String, CompletableFuture<Map.Entry<String, JoinColumnModel>>> + pairBuilds = new ConcurrentHashMap<>(); Review Comment: fixed by 486014263b15db333378d1da58a96815577749bc -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
