You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@solr.apache.org by "sonatype-lift[bot] (via GitHub)" <gi...@apache.org> on 2023/03/14 16:08:40 UTC

[GitHub] [solr] sonatype-lift[bot] commented on a diff in pull request #1458: SOLR-16697: Add new API to install offline-built indices into specific shards

sonatype-lift[bot] commented on code in PR #1458:
URL: https://github.com/apache/solr/pull/1458#discussion_r1135802948


##########
solr/core/src/java/org/apache/solr/handler/admin/api/InstallCoreDataAPI.java:
##########
@@ -0,0 +1,136 @@
+/*
+ * 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.handler.admin.api;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.apache.solr.cloud.CloudDescriptor;
+import org.apache.solr.cloud.ZkController;
+import org.apache.solr.cloud.ZkShardTerms;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.cloud.Slice;
+import org.apache.solr.common.params.CoreAdminParams;
+import org.apache.solr.core.CoreContainer;
+import org.apache.solr.core.SolrCore;
+import org.apache.solr.core.backup.repository.BackupRepository;
+import org.apache.solr.handler.RestoreCore;
+import org.apache.solr.handler.admin.CoreAdminHandler;
+import org.apache.solr.jersey.JacksonReflectMapWriter;
+import org.apache.solr.jersey.PermissionName;
+import org.apache.solr.jersey.SolrJerseyResponse;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.response.SolrQueryResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+
+import java.lang.invoke.MethodHandles;
+import java.net.URI;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import static org.apache.solr.client.solrj.impl.BinaryResponseParser.BINARY_CONTENT_TYPE_V2;
+import static org.apache.solr.security.PermissionNameProvider.Name.CORE_EDIT_PERM;
+
+@Path("/cores/{coreName}/install")
+public class InstallCoreDataAPI extends CoreAdminAPIBase {
+
+    private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+    public InstallCoreDataAPI(CoreContainer coreContainer, CoreAdminHandler.CoreAdminAsyncTracker coreAdminAsyncTracker, SolrQueryRequest req, SolrQueryResponse rsp) {
+        super(coreContainer, coreAdminAsyncTracker, req, rsp);
+    }
+
+    @POST
+    @Produces({"application/json", "application/xml", BINARY_CONTENT_TYPE_V2})
+    @PermissionName(CORE_EDIT_PERM)
+    public SolrJerseyResponse installCoreData(@PathParam("coreName") String coreName, InstallCoreDataRequestBody requestBody) throws Exception {
+        log.info("JEGERLOW: In install-core-data v2 API with coreName {}", coreName);
+        final SolrJerseyResponse response = instantiateJerseyResponse(SolrJerseyResponse.class);
+
+        // TODO Actual implementation (look at RESTORECORE for example)
+        final ZkController zkController = coreContainer.getZkController();
+        if (zkController == null) {
+            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Only valid for SolrCloud");
+        }
+
+        try (BackupRepository repository = coreContainer.newBackupRepository(requestBody.repository); SolrCore core = coreContainer.getCore(coreName)) {
+            String location = repository.getBackupLocation(requestBody.location);
+            if (location == null) {
+                throw new SolrException(
+                        SolrException.ErrorCode.BAD_REQUEST,
+                        "'location' is not specified as a query"
+                                + " parameter or as a default repository property");
+            }
+
+            URI locationUri = repository.createDirectoryURI(location);
+            CloudDescriptor cd = core.getCoreDescriptor().getCloudDescriptor();
+            // this core must be the only replica in its shard otherwise
+            // we cannot guarantee consistency between replicas because when we add data (or restore
+            // index) to this replica
+            Slice slice =
+                    zkController
+                            .getClusterState()
+                            .getCollection(cd.getCollectionName())
+                            .getSlice(cd.getShardId());
+            if (slice.getReplicas().size() != 1 && !core.readOnly) {
+                throw new SolrException(
+                        SolrException.ErrorCode.SERVER_ERROR,
+                        "Failed to restore core="
+                                + core.getName()
+                                + ", the core must be the only replica in its shard or it must be read only");
+            }
+
+            // TODO RestoreCore.create expects a backup 'name' that it appends to the Uri via 'BackupRepository#resolve'...how does this handle null?
+            final RestoreCore restoreCore = RestoreCore.create(repository, core, locationUri, "");
+            boolean success = restoreCore.doRestore();
+            if (!success) {
+                throw new SolrException(
+                        SolrException.ErrorCode.SERVER_ERROR, "Failed to install data to core=" + core.getName());
+            }
+
+            final Set<String> nonLeaderCoreNames = slice.getReplicas()
+                    .stream()
+                    .filter(r -> !r.isLeader())
+                    .map(r -> r.getName())
+                    .collect(Collectors.toSet());
+            log.info("JEGERLOW Non leader core names are: {} and leader is {}", nonLeaderCoreNames, coreName);

Review Comment:
   <picture><img alt="13% of developers fix this issue" src="https://lift.sonatype.com/api/commentimage/fixrate/13/display.svg"></picture>
   
   <b>*[CRLF_INJECTION_LOGS](https://find-sec-bugs.github.io/bugs.htm#CRLF_INJECTION_LOGS):</b>*  This use of org/slf4j/Logger.info(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V might be used to include CRLF characters into log messages
   
   ---
   
   <details><summary>ℹī¸ Expand to see all <b>@sonatype-lift</b> commands</summary>
   
   You can reply with the following commands. For example, reply with ***@sonatype-lift ignoreall*** to leave out all findings.
   | **Command** | **Usage** |
   | ------------- | ------------- |
   | `@sonatype-lift ignore` | Leave out the above finding from this PR |
   | `@sonatype-lift ignoreall` | Leave out all the existing findings from this PR |
   | `@sonatype-lift exclude <file\|issue\|path\|tool>` | Exclude specified `file\|issue\|path\|tool` from Lift findings by updating your config.toml file |
   
   **Note:** When talking to LiftBot, you need to **refresh** the page to see its response.
   <sub>[Click here](https://github.com/apps/sonatype-lift/installations/new) to add LiftBot to another repo.</sub></details>
   
   
   
   ---
   
   <b>Help us improve LIFT! (<i>Sonatype LiftBot external survey</i>)</b>
   
   Was this a good recommendation for you? <sub><small>Answering this survey will not impact your Lift settings.</small></sub>
   
   [ [🙁 Not relevant](https://www.sonatype.com/lift-comment-rating?comment=434169222&lift_comment_rating=1) ] - [ [😕 Won't fix](https://www.sonatype.com/lift-comment-rating?comment=434169222&lift_comment_rating=2) ] - [ [😑 Not critical, will fix](https://www.sonatype.com/lift-comment-rating?comment=434169222&lift_comment_rating=3) ] - [ [🙂 Critical, will fix](https://www.sonatype.com/lift-comment-rating?comment=434169222&lift_comment_rating=4) ] - [ [😊 Critical, fixing now](https://www.sonatype.com/lift-comment-rating?comment=434169222&lift_comment_rating=5) ]



##########
solr/core/src/java/org/apache/solr/handler/admin/api/InstallCoreDataAPI.java:
##########
@@ -0,0 +1,136 @@
+/*
+ * 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.handler.admin.api;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.apache.solr.cloud.CloudDescriptor;
+import org.apache.solr.cloud.ZkController;
+import org.apache.solr.cloud.ZkShardTerms;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.cloud.Slice;
+import org.apache.solr.common.params.CoreAdminParams;
+import org.apache.solr.core.CoreContainer;
+import org.apache.solr.core.SolrCore;
+import org.apache.solr.core.backup.repository.BackupRepository;
+import org.apache.solr.handler.RestoreCore;
+import org.apache.solr.handler.admin.CoreAdminHandler;
+import org.apache.solr.jersey.JacksonReflectMapWriter;
+import org.apache.solr.jersey.PermissionName;
+import org.apache.solr.jersey.SolrJerseyResponse;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.response.SolrQueryResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+
+import java.lang.invoke.MethodHandles;
+import java.net.URI;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import static org.apache.solr.client.solrj.impl.BinaryResponseParser.BINARY_CONTENT_TYPE_V2;
+import static org.apache.solr.security.PermissionNameProvider.Name.CORE_EDIT_PERM;
+
+@Path("/cores/{coreName}/install")
+public class InstallCoreDataAPI extends CoreAdminAPIBase {
+
+    private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+    public InstallCoreDataAPI(CoreContainer coreContainer, CoreAdminHandler.CoreAdminAsyncTracker coreAdminAsyncTracker, SolrQueryRequest req, SolrQueryResponse rsp) {
+        super(coreContainer, coreAdminAsyncTracker, req, rsp);
+    }
+
+    @POST
+    @Produces({"application/json", "application/xml", BINARY_CONTENT_TYPE_V2})
+    @PermissionName(CORE_EDIT_PERM)
+    public SolrJerseyResponse installCoreData(@PathParam("coreName") String coreName, InstallCoreDataRequestBody requestBody) throws Exception {
+        log.info("JEGERLOW: In install-core-data v2 API with coreName {}", coreName);

Review Comment:
   <picture><img alt="13% of developers fix this issue" src="https://lift.sonatype.com/api/commentimage/fixrate/13/display.svg"></picture>
   
   <b>*[CRLF_INJECTION_LOGS](https://find-sec-bugs.github.io/bugs.htm#CRLF_INJECTION_LOGS):</b>*  This use of org/slf4j/Logger.info(Ljava/lang/String;Ljava/lang/Object;)V might be used to include CRLF characters into log messages
   
   ---
   
   <details><summary>ℹī¸ Expand to see all <b>@sonatype-lift</b> commands</summary>
   
   You can reply with the following commands. For example, reply with ***@sonatype-lift ignoreall*** to leave out all findings.
   | **Command** | **Usage** |
   | ------------- | ------------- |
   | `@sonatype-lift ignore` | Leave out the above finding from this PR |
   | `@sonatype-lift ignoreall` | Leave out all the existing findings from this PR |
   | `@sonatype-lift exclude <file\|issue\|path\|tool>` | Exclude specified `file\|issue\|path\|tool` from Lift findings by updating your config.toml file |
   
   **Note:** When talking to LiftBot, you need to **refresh** the page to see its response.
   <sub>[Click here](https://github.com/apps/sonatype-lift/installations/new) to add LiftBot to another repo.</sub></details>
   
   
   
   ---
   
   <b>Help us improve LIFT! (<i>Sonatype LiftBot external survey</i>)</b>
   
   Was this a good recommendation for you? <sub><small>Answering this survey will not impact your Lift settings.</small></sub>
   
   [ [🙁 Not relevant](https://www.sonatype.com/lift-comment-rating?comment=434169315&lift_comment_rating=1) ] - [ [😕 Won't fix](https://www.sonatype.com/lift-comment-rating?comment=434169315&lift_comment_rating=2) ] - [ [😑 Not critical, will fix](https://www.sonatype.com/lift-comment-rating?comment=434169315&lift_comment_rating=3) ] - [ [🙂 Critical, will fix](https://www.sonatype.com/lift-comment-rating?comment=434169315&lift_comment_rating=4) ] - [ [😊 Critical, fixing now](https://www.sonatype.com/lift-comment-rating?comment=434169315&lift_comment_rating=5) ]



-- 
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