You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@solr.apache.org by GitBox <gi...@apache.org> on 2022/01/24 14:17:02 UTC

[GitHub] [solr] sonatype-lift[bot] commented on a change in pull request #559: SOLR-15715: coordinator role

sonatype-lift[bot] commented on a change in pull request #559:
URL: https://github.com/apache/solr/pull/559#discussion_r790784841



##########
File path: solr/contrib/analytics/src/java/org/apache/solr/handler/component/AnalyticsComponent.java
##########
@@ -109,7 +109,7 @@ public int distributedProcess(ResponseBuilder rb) throws IOException {
 
     // Send out a request to each shard and merge the responses into our AnalyticsRequestManager
     reqManager.shardStream.sendRequests(rb.req.getCore().getCoreDescriptor().getCollectionName(),
-        rb.req.getCore().getCoreContainer().getZkController().getZkServerAddress());
+        rb.req.getCoreContainer().getZkController().getZkServerAddress());

Review comment:
       *NULL_DEREFERENCE:*  object returned by `rb.req.getCoreContainer()` could be null and is dereferenced at line 112.
   (at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with `help` or `ignore`)

##########
File path: solr/contrib/ltr/src/java/org/apache/solr/ltr/response/transform/LTRFeatureLoggerTransformerFactory.java
##########
@@ -216,7 +216,7 @@ public void setContext(ResultContext context) {
       }
       leafContexts = searcher.getTopReaderContext().leaves();
       if (threadManager != null) {
-        threadManager.setExecutor(context.getRequest().getCore().getCoreContainer().getUpdateShardHandler().getUpdateExecutor());
+        threadManager.setExecutor(context.getRequest().getCoreContainer().getUpdateShardHandler().getUpdateExecutor());

Review comment:
       *NULL_DEREFERENCE:*  object returned by `context.getRequest().getCoreContainer()` could be null and is dereferenced at line 219.
   (at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with `help` or `ignore`)

##########
File path: solr/core/src/java/org/apache/solr/cloud/api/collections/CategoryRoutedAlias.java
##########
@@ -225,7 +225,7 @@ public String computeInitialCollectionName() {
   public CandidateCollection findCandidateGivenValue(AddUpdateCommand cmd) {
     Object value = cmd.getSolrInputDocument().getFieldValue(getRouteField());
     String targetColName = buildCollectionNameFromValue(String.valueOf(value));
-    ZkStateReader zkStateReader = cmd.getReq().getCore().getCoreContainer().getZkController().zkStateReader;
+    ZkStateReader zkStateReader = cmd.getReq().getCoreContainer().getZkController().zkStateReader;

Review comment:
       *NULL_DEREFERENCE:*  object returned by `cmd.getReq().getCoreContainer()` could be null and is dereferenced at line 228.
   (at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with `help` or `ignore`)

##########
File path: solr/core/src/java/org/apache/solr/cloud/api/collections/CategoryRoutedAlias.java
##########
@@ -121,7 +121,7 @@ public RoutedAliasTypes getRoutedAliasType() {
   @Override
   public void validateRouteValue(AddUpdateCommand cmd) throws SolrException {
     if (this.aliases == null) {
-      updateParsedCollectionAliases(cmd.getReq().getCore().getCoreContainer().getZkController().zkStateReader, false);
+      updateParsedCollectionAliases(cmd.getReq().getCoreContainer().getZkController().zkStateReader, false);

Review comment:
       *NULL_DEREFERENCE:*  object returned by `cmd.getReq().getCoreContainer()` could be null and is dereferenced at line 124.
   (at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with `help` or `ignore`)

##########
File path: solr/core/src/java/org/apache/solr/cloud/api/collections/RoutedAlias.java
##########
@@ -333,7 +331,7 @@ private String createAllRequiredCollections(AddUpdateCommand cmd, CandidateColle
           targetCollectionDesc = doSynchronous( cmd, targetCollectionDesc, coreContainer);

Review comment:
       *NULL_DEREFERENCE:*  object `coreContainer` last assigned on line 325 could be null and is dereferenced by call to `doSynchronous(...)` at line 331.
   (at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with `help` or `ignore`)

##########
File path: solr/core/src/java/org/apache/solr/cloud/api/collections/TimeRoutedAlias.java
##########
@@ -449,7 +448,7 @@ private Instant parseRouteKey(Object routeKey) {
   @Override
   public CandidateCollection findCandidateGivenValue(AddUpdateCommand cmd) {
     Object value = cmd.getSolrInputDocument().getFieldValue(getRouteField());
-    ZkStateReader zkStateReader = cmd.getReq().getCore().getCoreContainer().getZkController().zkStateReader;
+    ZkStateReader zkStateReader = cmd.getReq().getCoreContainer().getZkController().zkStateReader;

Review comment:
       *NULL_DEREFERENCE:*  object returned by `cmd.getReq().getCoreContainer()` could be null and is dereferenced at line 451.
   (at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with `help` or `ignore`)

##########
File path: solr/core/src/java/org/apache/solr/handler/component/HttpShardHandler.java
##########
@@ -262,12 +262,12 @@ public void prepDistributed(ResponseBuilder rb) {
     final String shards = params.get(ShardParams.SHARDS);
 
     CoreDescriptor coreDescriptor = req.getCore().getCoreDescriptor();
-    CloudDescriptor cloudDescriptor = coreDescriptor.getCloudDescriptor();
-    ZkController zkController = req.getCore().getCoreContainer().getZkController();
+    CloudDescriptor cloudDescriptor = req.getCloudDescriptor();
+    ZkController zkController = req.getCoreContainer().getZkController();

Review comment:
       *NULL_DEREFERENCE:*  object returned by `req.getCoreContainer()` could be null and is dereferenced at line 266.
   (at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with `help` or `ignore`)

##########
File path: solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java
##########
@@ -1569,7 +1569,7 @@ private void doProcessUngroupedSearch(ResponseBuilder rb, QueryCommand cmd, Quer
   }
 
   private static String generateQueryID(SolrQueryRequest req) {
-    ZkController zkController = req.getCore().getCoreContainer().getZkController();
+    ZkController zkController = req.getCoreContainer().getZkController();

Review comment:
       *NULL_DEREFERENCE:*  object returned by `req.getCoreContainer()` could be null and is dereferenced at line 1572.
   (at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with `help` or `ignore`)

##########
File path: solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java
##########
@@ -288,7 +288,7 @@ protected void prepareGrouping(ResponseBuilder rb) throws IOException {
     groupingSpec.setResponseFormat(responseFormat);
 
     // See SOLR-12249. Disallow grouping on text fields that are not SortableText in cloud mode
-    if (req.getCore().getCoreContainer().isZooKeeperAware()) {
+    if (req.getCoreContainer().isZooKeeperAware()) {

Review comment:
       *NULL_DEREFERENCE:*  object returned by `req.getCoreContainer()` could be null and is dereferenced at line 291.
   (at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with `help` or `ignore`)

##########
File path: solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java
##########
@@ -1208,7 +1208,7 @@ public void processSync(ResponseBuilder rb, int nVersions, String sync) {
     boolean onlyIfActive = rb.req.getParams().getBool("onlyIfActive", false);
     
     if (onlyIfActive) {
-      if (rb.req.getCore().getCoreDescriptor().getCloudDescriptor().getLastPublished() != Replica.State.ACTIVE) {
+      if (rb.req.getCloudDescriptor().getLastPublished() != Replica.State.ACTIVE) {

Review comment:
       *NULL_DEREFERENCE:*  object returned by `rb.req.getCloudDescriptor()` could be null and is dereferenced at line 1211.
   (at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with `help` or `ignore`)

##########
File path: solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java
##########
@@ -585,7 +585,7 @@ public static String getOrGenerateRequestId(SolrQueryRequest req) {
   }
 
   private static String generateRid(SolrQueryRequest req) {
-    String hostName = req.getCore().getCoreContainer().getHostName();
+    String hostName = req.getCoreContainer().getHostName();

Review comment:
       *NULL_DEREFERENCE:*  object returned by `req.getCoreContainer()` could be null and is dereferenced at line 588.
   (at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with `help` or `ignore`)

##########
File path: solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java
##########
@@ -236,7 +236,7 @@ private void initComponents() {
   public ShardHandler getAndPrepShardHandler(SolrQueryRequest req, ResponseBuilder rb) {
     ShardHandler shardHandler = null;
 
-    CoreContainer cc = req.getCore().getCoreContainer();
+    CoreContainer cc = req.getCoreContainer();
     boolean isZkAware = cc.isZooKeeperAware();

Review comment:
       *NULL_DEREFERENCE:*  object `cc` last assigned on line 239 could be null and is dereferenced at line 240.
   (at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with `help` or `ignore`)

##########
File path: solr/core/src/java/org/apache/solr/handler/component/TaskManagementHandler.java
##########
@@ -132,7 +132,7 @@ protected void processRequest(SolrQueryRequest req, ResponseBuilder rb, Map<Stri
 
     public static ResponseBuilder buildResponseBuilder(SolrQueryRequest req, SolrQueryResponse rsp,
                                                        List<SearchComponent> components) {
-        CoreContainer cc = req.getCore().getCoreContainer();
+        CoreContainer cc = req.getCoreContainer();
         boolean isZkAware = cc.isZooKeeperAware();

Review comment:
       *NULL_DEREFERENCE:*  object `cc` last assigned on line 135 could be null and is dereferenced at line 136.
   (at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with `help` or `ignore`)

##########
File path: solr/core/src/java/org/apache/solr/request/SimpleFacets.java
##########
@@ -167,7 +167,7 @@ public SimpleFacets(SolrQueryRequest req,
     this.docsOrig = docs;
     this.global = params;
     this.rb = rb;
-    this.facetExecutor = req.getCore().getCoreContainer().getUpdateShardHandler().getUpdateExecutor();
+    this.facetExecutor = req.getCoreContainer().getUpdateShardHandler().getUpdateExecutor();

Review comment:
       *NULL_DEREFERENCE:*  object returned by `req.getCoreContainer()` could be null and is dereferenced at line 170.
   (at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with `help` or `ignore`)

##########
File path: solr/core/src/java/org/apache/solr/search/JoinQParserPlugin.java
##########
@@ -137,7 +137,7 @@ JoinParams parseJoin(QParser qparser) throws SyntaxError {
       long fromCoreOpenTime = 0;
 
       if (fromIndex != null && !fromIndex.equals(qparser.req.getCore().getCoreDescriptor().getName()) ) {
-        CoreContainer container = qparser.req.getCore().getCoreContainer();
+        CoreContainer container = qparser.req.getCoreContainer();
 
         // if in SolrCloud mode, fromIndex should be the name of a single-sharded collection
         coreName = ScoreJoinQParserPlugin.getCoreName(fromIndex, container);

Review comment:
       *NULL_DEREFERENCE:*  object `container` last assigned on line 140 could be null and is dereferenced by call to `getCoreName(...)` at line 143.
   (at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with `help` or `ignore`)

##########
File path: solr/core/src/java/org/apache/solr/search/join/ScoreJoinQParserPlugin.java
##########
@@ -228,7 +228,7 @@ private Query createQuery(final String fromField, final String fromQueryStr,
         final String myCore = req.getCore().getCoreDescriptor().getName();
 
         if (fromIndex != null && (!fromIndex.equals(myCore) || byPassShortCircutCheck)) {
-          CoreContainer container = req.getCore().getCoreContainer();
+          CoreContainer container = req.getCoreContainer();
 
           final String coreName = getCoreName(fromIndex, container);

Review comment:
       *NULL_DEREFERENCE:*  object `container` last assigned on line 231 could be null and is dereferenced by call to `getCoreName(...)` at line 233.
   (at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with `help` or `ignore`)

##########
File path: solr/core/src/java/org/apache/solr/search/join/ScoreJoinQParserPlugin.java
##########
@@ -90,7 +90,7 @@ public OtherCoreJoinQuery(Query fromQuery, String fromField,
     public Weight createWeight(IndexSearcher searcher, org.apache.lucene.search.ScoreMode scoreMode, float boost) throws IOException {
       SolrRequestInfo info = SolrRequestInfo.getRequestInfo();
 
-      CoreContainer container = info.getReq().getCore().getCoreContainer();
+      CoreContainer container = info.getReq().getCoreContainer();
 
       final SolrCore fromCore = container.getCore(fromIndex);

Review comment:
       *NULL_DEREFERENCE:*  object returned by `getRequestInfo().getReq().getCoreContainer()` could be null and is dereferenced at line 95.
   (at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with `help` or `ignore`)

##########
File path: solr/core/src/java/org/apache/solr/search/stats/ExactStatsCache.java
##########
@@ -230,10 +230,10 @@ protected void doSendGlobalStats(ResponseBuilder rb, ShardRequest outgoing) {
       Map<String,TermStats> globalTermStats = new HashMap<>();
       Map<String,CollectionStats> globalColStats = new HashMap<>();
       // aggregate collection stats, only for the field in terms
-      String collectionName = rb.req.getCore().getCoreDescriptor().getCollectionName();
-      if (collectionName == null) {
+      String collectionName = rb.req.getCloudDescriptor().getCollectionName();

Review comment:
       *NULL_DEREFERENCE:*  object returned by `rb.req.getCloudDescriptor()` could be null and is dereferenced at line 233.
   (at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with `help` or `ignore`)

##########
File path: solr/core/src/java/org/apache/solr/update/processor/DistributedUpdateProcessorFactory.java
##########
@@ -50,7 +50,7 @@ public static void addParamToDistributedRequestWhitelist(final SolrQueryRequest
   public UpdateRequestProcessor getInstance(SolrQueryRequest req,
       SolrQueryResponse rsp, UpdateRequestProcessor next) {
 
-    final boolean isZkAware = req.getCore().getCoreContainer().isZooKeeperAware();
+    final boolean isZkAware = req.getCoreContainer().isZooKeeperAware();

Review comment:
       *NULL_DEREFERENCE:*  object returned by `req.getCoreContainer()` could be null and is dereferenced at line 53.
   (at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with `help` or `ignore`)

##########
File path: solr/core/src/java/org/apache/solr/update/processor/DistributedZkUpdateProcessor.java
##########
@@ -111,8 +111,8 @@
   public DistributedZkUpdateProcessor(SolrQueryRequest req,
                                       SolrQueryResponse rsp, UpdateRequestProcessor next) {
     super(req, rsp, next);
-    CoreContainer cc = req.getCore().getCoreContainer();
-    cloudDesc = req.getCore().getCoreDescriptor().getCloudDescriptor();
+    CoreContainer cc = req.getCoreContainer();
+    cloudDesc = req.getCloudDescriptor();
     zkController = cc.getZkController();

Review comment:
       *NULL_DEREFERENCE:*  object `cc` last assigned on line 114 could be null and is dereferenced at line 116.
   (at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with `help` or `ignore`)

##########
File path: solr/core/src/java/org/apache/solr/update/processor/DistributedZkUpdateProcessor.java
##########
@@ -757,7 +757,7 @@ private void checkReplicationTracker(UpdateCommand cmd) {
     // a batch we need to use the _same_ leader replication tracker.
     if (isLeader && leaderReplicationTracker == null) {
       leaderReplicationTracker = new LeaderRequestReplicationTracker(
-          req.getCore().getCoreDescriptor().getCloudDescriptor().getShardId());
+          req.getCloudDescriptor().getShardId());

Review comment:
       *NULL_DEREFERENCE:*  object returned by `DistributedUpdateProcessor.req.getCloudDescriptor()` could be null and is dereferenced at line 760.
   (at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with `help` or `ignore`)

##########
File path: solr/core/src/java/org/apache/solr/update/processor/DistributedZkUpdateProcessor.java
##########
@@ -149,7 +149,7 @@ private boolean isCloneRequiredOnLeader(UpdateRequestProcessor next) {
   @Override
   protected Replica.Type computeReplicaType() {
     // can't use cloudDesc since this is called by super class, before the constructor instantiates cloudDesc.
-    return req.getCore().getCoreDescriptor().getCloudDescriptor().getReplicaType();
+    return req.getCloudDescriptor().getReplicaType();

Review comment:
       *NULL_DEREFERENCE:*  object returned by `DistributedUpdateProcessor.req.getCloudDescriptor()` could be null and is dereferenced at line 152.
   (at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with `help` or `ignore`)

##########
File path: solr/core/src/java/org/apache/solr/update/processor/DistributedZkUpdateProcessor.java
##########
@@ -1246,7 +1246,7 @@ private void zkCheck() {
     // Streaming updates can delay shutdown and cause big update reorderings (new streams can't be
     // initiated, but existing streams carry on).  This is why we check if the CC is shutdown.
     // See SOLR-8203 and loop HdfsChaosMonkeyNothingIsSafeTest (and check for inconsistent shards) to test.
-    if (req.getCore().getCoreContainer().isShutDown()) {
+    if (req.getCoreContainer().isShutDown()) {

Review comment:
       *NULL_DEREFERENCE:*  object returned by `DistributedUpdateProcessor.req.getCoreContainer()` could be null and is dereferenced at line 1249.
   (at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with `help` or `ignore`)

##########
File path: solr/core/src/java/org/apache/solr/update/processor/RoutedAliasUpdateProcessor.java
##########
@@ -127,7 +127,7 @@ public static UpdateRequestProcessor wrap(SolrQueryRequest req, UpdateRequestPro
   }
 
   private static Map<String, String> getAliasProps(SolrQueryRequest req, String aliasName) {
-    ZkController zkController = req.getCore().getCoreContainer().getZkController();
+    ZkController zkController = req.getCoreContainer().getZkController();

Review comment:
       *NULL_DEREFERENCE:*  object returned by `req.getCoreContainer()` could be null and is dereferenced at line 130.
   (at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with `help` or `ignore`)

##########
File path: solr/core/src/java/org/apache/solr/update/processor/TolerantUpdateProcessor.java
##########
@@ -134,7 +134,7 @@ public TolerantUpdateProcessor(SolrQueryRequest req, SolrQueryResponse rsp, Upda
     this.distribPhase = distribPhase;
     assert ! DistribPhase.FROMLEADER.equals(distribPhase);
     
-    this.zkController = this.req.getCore().getCoreContainer().getZkController();
+    this.zkController = this.req.getCoreContainer().getZkController();

Review comment:
       *NULL_DEREFERENCE:*  object returned by `TolerantUpdateProcessor.req.getCoreContainer()` could be null and is dereferenced at line 137.
   (at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with `help` or `ignore`)

##########
File path: solr/core/src/java/org/apache/solr/servlet/CoordinatorHttpSolrCall.java
##########
@@ -0,0 +1,255 @@
+/*
+ * 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.servlet;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import java.lang.invoke.MethodHandles;
+import java.security.Principal;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.ConcurrentHashMap;
+import org.apache.solr.client.solrj.request.CollectionAdminRequest;
+import org.apache.solr.cloud.CloudDescriptor;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.cloud.ClusterState;
+import org.apache.solr.common.cloud.DocCollection;
+import org.apache.solr.common.cloud.Replica;
+import org.apache.solr.common.cloud.ZkStateReader;
+import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.common.util.ContentStream;
+import org.apache.solr.common.util.Utils;
+import org.apache.solr.core.CoreContainer;
+import org.apache.solr.core.CoreDescriptor;
+import org.apache.solr.core.SolrCore;
+import org.apache.solr.request.LocalSolrQueryRequest;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.response.SolrQueryResponse;
+import org.apache.solr.schema.IndexSchema;
+import org.apache.solr.search.SolrIndexSearcher;
+import org.apache.solr.util.RTimerTree;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class CoordinatorHttpSolrCall extends HttpSolrCall {
+  public static final String SYNTHETIC_COLL_PREFIX = "SYNTHETIC-CONF-COLL_";
+  private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+  private String collectionName;
+
+  public CoordinatorHttpSolrCall(SolrDispatchFilter solrDispatchFilter, CoreContainer cores, HttpServletRequest request,
+                                 HttpServletResponse response, boolean retry) {
+    super(solrDispatchFilter, cores, request, response, retry);
+  }
+
+  @Override
+  protected SolrCore getCoreByCollection(String collectionName, boolean isPreferLeader) {
+    this.collectionName = collectionName;
+    SolrCore core = super.getCoreByCollection(collectionName, isPreferLeader);
+    if (core != null) return core;
+    return getCore(this, collectionName, isPreferLeader);
+  }
+
+  @SuppressWarnings("unchecked")
+  public static  SolrCore getCore(HttpSolrCall solrCall, String collectionName, boolean isPreferLeader) {
+     Map<String, String> coreNameMapping= (Map<String, String>) solrCall.cores.getObjectCache().computeIfAbsent(CoordinatorHttpSolrCall.class.getName(),
+             s -> new ConcurrentHashMap<>());
+    String sytheticCoreName = coreNameMapping.get(collectionName);
+    if (sytheticCoreName != null) {
+      return solrCall.cores.getCore(sytheticCoreName);
+    } else {
+      ZkStateReader zkStateReader = solrCall.cores.getZkController().getZkStateReader();
+      ClusterState clusterState = zkStateReader.getClusterState();
+      DocCollection coll = clusterState.getCollectionOrNull(collectionName, true);
+      if (coll != null) {
+        String confName = coll.getConfigName();
+        String syntheticCollectionName = SYNTHETIC_COLL_PREFIX + confName;
+        DocCollection syntheticColl = clusterState.getCollectionOrNull(syntheticCollectionName);
+        if (syntheticColl == null) {
+          // no such collection. let's create one
+          log.info("synthetic collection: {} does not exist, creating.. ", syntheticCollectionName);
+          createColl(syntheticCollectionName, solrCall.cores, confName);
+        }
+        SolrCore core = solrCall.getCoreByCollection(syntheticCollectionName, isPreferLeader);
+        if (core != null) {
+          coreNameMapping.put(collectionName, core.getName());
+          log.info("coordinator NODE , returns synthetic core " + core.getName());
+        } else {
+          //this node does not have a replica. add one
+          log.info("this node does not have a replica of the synthetic collection: {} , adding replica ", syntheticCollectionName);
+
+          addReplica(syntheticCollectionName, solrCall.cores);
+          core = solrCall.getCoreByCollection(syntheticCollectionName, isPreferLeader);
+        }
+        return core;
+
+      }
+      return null;
+    }
+
+  }
+  private static void addReplica(String syntheticCollectionName, CoreContainer cores) {
+    SolrQueryResponse rsp = new SolrQueryResponse();
+    try {
+      cores.getCollectionsHandler().handleRequestBody(new LocalSolrQueryRequest(null,

Review comment:
       *RESOURCE_LEAK:*  resource of type `org.apache.solr.request.LocalSolrQueryRequest` acquired by call to `LocalSolrQueryRequest(...)` at line 112 is not released after line 109.
   **Note**: potential exception at line 109
   (at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with `help` or `ignore`)

##########
File path: solr/core/src/java/org/apache/solr/servlet/CoordinatorHttpSolrCall.java
##########
@@ -0,0 +1,255 @@
+/*
+ * 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.servlet;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import java.lang.invoke.MethodHandles;
+import java.security.Principal;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.ConcurrentHashMap;
+import org.apache.solr.client.solrj.request.CollectionAdminRequest;
+import org.apache.solr.cloud.CloudDescriptor;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.cloud.ClusterState;
+import org.apache.solr.common.cloud.DocCollection;
+import org.apache.solr.common.cloud.Replica;
+import org.apache.solr.common.cloud.ZkStateReader;
+import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.common.util.ContentStream;
+import org.apache.solr.common.util.Utils;
+import org.apache.solr.core.CoreContainer;
+import org.apache.solr.core.CoreDescriptor;
+import org.apache.solr.core.SolrCore;
+import org.apache.solr.request.LocalSolrQueryRequest;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.response.SolrQueryResponse;
+import org.apache.solr.schema.IndexSchema;
+import org.apache.solr.search.SolrIndexSearcher;
+import org.apache.solr.util.RTimerTree;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class CoordinatorHttpSolrCall extends HttpSolrCall {
+  public static final String SYNTHETIC_COLL_PREFIX = "SYNTHETIC-CONF-COLL_";
+  private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+  private String collectionName;
+
+  public CoordinatorHttpSolrCall(SolrDispatchFilter solrDispatchFilter, CoreContainer cores, HttpServletRequest request,
+                                 HttpServletResponse response, boolean retry) {
+    super(solrDispatchFilter, cores, request, response, retry);
+  }
+
+  @Override
+  protected SolrCore getCoreByCollection(String collectionName, boolean isPreferLeader) {
+    this.collectionName = collectionName;
+    SolrCore core = super.getCoreByCollection(collectionName, isPreferLeader);
+    if (core != null) return core;
+    return getCore(this, collectionName, isPreferLeader);
+  }
+
+  @SuppressWarnings("unchecked")
+  public static  SolrCore getCore(HttpSolrCall solrCall, String collectionName, boolean isPreferLeader) {
+     Map<String, String> coreNameMapping= (Map<String, String>) solrCall.cores.getObjectCache().computeIfAbsent(CoordinatorHttpSolrCall.class.getName(),
+             s -> new ConcurrentHashMap<>());
+    String sytheticCoreName = coreNameMapping.get(collectionName);
+    if (sytheticCoreName != null) {
+      return solrCall.cores.getCore(sytheticCoreName);
+    } else {
+      ZkStateReader zkStateReader = solrCall.cores.getZkController().getZkStateReader();
+      ClusterState clusterState = zkStateReader.getClusterState();
+      DocCollection coll = clusterState.getCollectionOrNull(collectionName, true);
+      if (coll != null) {
+        String confName = coll.getConfigName();
+        String syntheticCollectionName = SYNTHETIC_COLL_PREFIX + confName;
+        DocCollection syntheticColl = clusterState.getCollectionOrNull(syntheticCollectionName);
+        if (syntheticColl == null) {
+          // no such collection. let's create one
+          log.info("synthetic collection: {} does not exist, creating.. ", syntheticCollectionName);
+          createColl(syntheticCollectionName, solrCall.cores, confName);
+        }
+        SolrCore core = solrCall.getCoreByCollection(syntheticCollectionName, isPreferLeader);
+        if (core != null) {
+          coreNameMapping.put(collectionName, core.getName());
+          log.info("coordinator NODE , returns synthetic core " + core.getName());
+        } else {
+          //this node does not have a replica. add one
+          log.info("this node does not have a replica of the synthetic collection: {} , adding replica ", syntheticCollectionName);
+
+          addReplica(syntheticCollectionName, solrCall.cores);
+          core = solrCall.getCoreByCollection(syntheticCollectionName, isPreferLeader);
+        }
+        return core;
+
+      }
+      return null;
+    }
+
+  }
+  private static void addReplica(String syntheticCollectionName, CoreContainer cores) {
+    SolrQueryResponse rsp = new SolrQueryResponse();
+    try {
+      cores.getCollectionsHandler().handleRequestBody(new LocalSolrQueryRequest(null,
+              CollectionAdminRequest.addReplicaToShard(syntheticCollectionName, "shard1")
+                      .setCreateNodeSet(cores.getZkController().getNodeName())
+                      .getParams()
+      ), rsp);
+      if (rsp.getValues().get("success") == null) {
+        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Could not auto-create collection: " + Utils.toJSONString(rsp.getValues()));
+      }
+    } catch (SolrException e) {
+      throw e;
+
+    } catch (Exception e) {
+      throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
+    }
+
+  }
+
+  private static void createColl(String syntheticCollectionName, CoreContainer cores, String confName) {
+    SolrQueryResponse rsp = new SolrQueryResponse();
+    try {
+      SolrParams params = CollectionAdminRequest.createCollection(syntheticCollectionName, confName, 1, 1)
+              .setCreateNodeSet(cores.getZkController().getNodeName()).getParams();
+      log.info("sending collection admin command : {}", Utils.toJSONString(params));
+      cores.getCollectionsHandler()
+              .handleRequestBody(new LocalSolrQueryRequest(null,

Review comment:
       *RESOURCE_LEAK:*  resource of type `org.apache.solr.request.LocalSolrQueryRequest` acquired by call to `LocalSolrQueryRequest(...)` at line 132 is not released after line 133.
   **Note**: potential exception at line 133
   (at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with `help` or `ignore`)




-- 
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: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org