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/03/24 03:21:20 UTC

[GitHub] [solr] sonatype-lift[bot] commented on a change in pull request #716: SOLR-15715 : Dedicated query aggregator nodes in the solr cluster

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



##########
File path: solr/core/src/java/org/apache/solr/servlet/CoordinatorHttpSolrCall.java
##########
@@ -0,0 +1,275 @@
+/*
+ * 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.api.CoordinatorV2HttpSolrCall;
+import org.apache.solr.client.solrj.request.CollectionAdminRequest;
+import org.apache.solr.cloud.CloudDescriptor;
+import org.apache.solr.cloud.api.collections.Assign;
+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 = Assign.SYSTEM_COLL_PREFIX+ "COORDINATOR-COLL-";
+  private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+  private String collectionName;
+  private final Factory factory;
+
+  public CoordinatorHttpSolrCall(Factory factory, SolrDispatchFilter solrDispatchFilter, CoreContainer cores, HttpServletRequest request,
+                                 HttpServletResponse response, boolean retry) {
+    super(solrDispatchFilter, cores, request, response, retry);
+    this.factory = factory;
+  }
+
+  @Override
+  protected SolrCore getCoreByCollection(String collectionName, boolean isPreferLeader) {
+    this.collectionName = collectionName;
+    SolrCore core = super.getCoreByCollection(collectionName, isPreferLeader);
+    if (core != null) return core;
+    if (!path.endsWith("/select")) return null;
+    return getCore(factory,this, collectionName, isPreferLeader);
+  }
+
+  public static  SolrCore getCore( Factory factory, HttpSolrCall solrCall, String collectionName, boolean isPreferLeader) {
+    String sytheticCoreName = factory.collectionVsCoreNameMapping.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) {
+          factory.collectionVsCoreNameMapping.put(collectionName, core.getName());
+          solrCall.cores.getZkController().getZkStateReader().registerCore(collectionName);
+          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 117 is not released after line 114.
   **Note**: potential exception at line 114
   
   (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,275 @@
+/*
+ * 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.api.CoordinatorV2HttpSolrCall;
+import org.apache.solr.client.solrj.request.CollectionAdminRequest;
+import org.apache.solr.cloud.CloudDescriptor;
+import org.apache.solr.cloud.api.collections.Assign;
+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 = Assign.SYSTEM_COLL_PREFIX+ "COORDINATOR-COLL-";
+  private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+  private String collectionName;
+  private final Factory factory;
+
+  public CoordinatorHttpSolrCall(Factory factory, SolrDispatchFilter solrDispatchFilter, CoreContainer cores, HttpServletRequest request,
+                                 HttpServletResponse response, boolean retry) {
+    super(solrDispatchFilter, cores, request, response, retry);
+    this.factory = factory;
+  }
+
+  @Override
+  protected SolrCore getCoreByCollection(String collectionName, boolean isPreferLeader) {
+    this.collectionName = collectionName;
+    SolrCore core = super.getCoreByCollection(collectionName, isPreferLeader);
+    if (core != null) return core;
+    if (!path.endsWith("/select")) return null;
+    return getCore(factory,this, collectionName, isPreferLeader);
+  }
+
+  public static  SolrCore getCore( Factory factory, HttpSolrCall solrCall, String collectionName, boolean isPreferLeader) {
+    String sytheticCoreName = factory.collectionVsCoreNameMapping.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) {
+          factory.collectionVsCoreNameMapping.put(collectionName, core.getName());
+          solrCall.cores.getZkController().getZkStateReader().registerCore(collectionName);
+          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 137 is not released after line 138.
   **Note**: potential exception at line 138
   
   (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