Skip to content

Commit

Permalink
Merge branch 'main' into curator
Browse files Browse the repository at this point in the history
  • Loading branch information
risdenk committed Oct 11, 2023
2 parents 539ca79 + 3ab1683 commit b9ec384
Show file tree
Hide file tree
Showing 74 changed files with 375 additions and 207 deletions.
10 changes: 8 additions & 2 deletions solr/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ New Features
Improvements
---------------------
* SOLR-16924: RESTORECORE now sets the UpdateLog to ACTIVE state instead of requiring a separate
REQUESTAPPLYUPDATES call in Collection restore. The latter will still happen in 9.x for
backwards-compatibility. (Julia Lamoine, David Smiley)
REQUESTAPPLYUPDATES call in Collection restore. (Julia Lamoine, David Smiley)

Optimizations
---------------------
Expand Down Expand Up @@ -260,6 +259,8 @@ Bug Fixes

* SOLR-17009: json.wrf parameter ignored in JacksonJsonWriter (Alex Deparvu)

* SOLR-17019: ZkCli should create subpaths when necessary (Houston Putman)

Dependency Upgrades
---------------------

Expand All @@ -269,6 +270,8 @@ Dependency Upgrades

* PR#1971: Update forbiddenapis to 3.6 to support Java 21/22 and commons-io up to 2.14.0 (Uwe Schindler)

* PR#2001: Update org.eclipse.jetty to 10.0.17 (Alex Deparvu)

Other Changes
---------------------

Expand Down Expand Up @@ -455,6 +458,9 @@ Improvements
* SOLR-16397: Reload core v2 endpoints have been updated to be more REST-ful.
RELOAD is now available at `POST /api/cores/coreName/reload` (Sanjay Dutt via Jason Gerlowski)

* SOLR-16397: Unload core v2 endpoints have been updated to be more REST-ful.
UNLOAD is now available at `POST /api/cores/coreName/unload` (Sanjay Dutt via Jason Gerlowski)

Optimizations
---------------------

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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.client.api.endpoint;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import org.apache.solr.client.api.model.SolrJerseyResponse;
import org.apache.solr.client.api.model.UnloadCoreRequestBody;

/** V2 API definition for unloading a Solr core. */
@Path("/cores/{coreName}/unload")
public interface UnloadCoreApi {
@POST
@Operation(
summary = "Unloads a single core specified by name",
tags = {"cores"})
SolrJerseyResponse unloadCore(
@PathParam("coreName") String coreName,
@RequestBody(description = "Additional properties related to the core unloading")
UnloadCoreRequestBody requestBody)
throws Exception;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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.client.api.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;

public class UnloadCoreRequestBody {
@Schema(description = "If true, will remove the index when unloading the core.")
@JsonProperty
public Boolean deleteIndex;

@Schema(description = "If true, removes the data directory and all sub-directories.")
@JsonProperty
public Boolean deleteDataDir;

@Schema(
description =
"If true, removes everything related to the core, including the index directory, configuration files and other related files.")
@JsonProperty
public Boolean deleteInstanceDir;

@Schema(description = "Request ID to track this action which will be processed asynchronously.")
@JsonProperty
public String async;
}
21 changes: 12 additions & 9 deletions solr/bin/solr
Original file line number Diff line number Diff line change
Expand Up @@ -1913,26 +1913,29 @@ function start_solr() {
# shellcheck disable=SC2086
nohup "$JAVA" "${SOLR_START_OPTS[@]}" $SOLR_ADDL_ARGS -Dsolr.log.muteconsole \
-jar start.jar "${SOLR_JETTY_CONFIG[@]}" $SOLR_JETTY_ADDL_CONFIG \
1>"$SOLR_LOGS_DIR/solr-$SOLR_PORT-console.log" 2>&1 & echo $! > "$SOLR_PID_DIR/solr-$SOLR_PORT.pid"
1>"$SOLR_LOGS_DIR/solr-$SOLR_PORT-console.log" 2>&1 & echo $! > "$SOLR_PID_DIR/solr-$SOLR_PORT.pid"

# Get the current entropy available
entropy_avail=$(cat /proc/sys/kernel/random/entropy_avail)
# Check and warn about low entropy on Linux systems
if [ -e /proc/sys/kernel/random ]; then
# Get the current entropy available
entropy_avail=$(cat /proc/sys/kernel/random/entropy_avail)

# Get the pool size
pool_size=$(cat /proc/sys/kernel/random/poolsize)
# Get the pool size
pool_size=$(cat /proc/sys/kernel/random/poolsize)

# Check if entropy is available and pool size is non-zero
if [[ $entropy_avail -gt 0 && $pool_size -ne 0 ]]; then
# Check if entropy is available and pool size is non-zero
if [[ $entropy_avail -gt 0 && $pool_size -ne 0 ]]; then
# Compute the ratio of entropy available to pool size
ratio=$(awk -v ea="$entropy_avail" -v ps="$pool_size" 'BEGIN {print (ea/ps)*100}')

# Check if the ratio is less than 25%
if (( $(echo "$ratio < 25" | bc -l) )); then
echo "Warning: Available entropy is low. As a result, use of the UUIDField, SSL, or any other features that require"
echo "RNG might not work properly. To check for the amount of available entropy, use 'cat /proc/sys/kernel/random/entropy_avail'."
fi
else
else
echo "Error: Either no entropy is available or the pool size is zero."
fi
fi

# no lsof on cygwin though
Expand Down
4 changes: 4 additions & 0 deletions solr/core/src/java/org/apache/solr/api/V2HttpCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,10 @@ protected void executeCoreRequest(SolrQueryResponse rsp) {
rsp,
suppressNotFoundProp);
if (!resourceFound) {
// Whatever this API call is, it's not a core-level request so make sure we free our
// SolrCore counter
core.close();
core = null;
response.getHeaderNames().stream().forEach(name -> response.setHeader(name, null));
invokeJerseyRequest(
cores, null, cores.getJerseyApplicationHandler(), cores.getRequestHandlers(), rsp);
Expand Down
4 changes: 2 additions & 2 deletions solr/core/src/java/org/apache/solr/cloud/ZkCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ public static void main(String[] args)
if (zkClient.exists(path)) {
zkClient.setData(path, data);
} else {
zkClient.create(path, data, CreateMode.PERSISTENT);
zkClient.makePath(path, data, CreateMode.PERSISTENT);
}
} else if (line.getOptionValue(CMD).equalsIgnoreCase(PUT_FILE)) {
List<String> arglist = line.getArgList();
Expand All @@ -437,7 +437,7 @@ public static void main(String[] args)
if (zkClient.exists(path)) {
zkClient.setData(path, data);
} else {
zkClient.create(path, data, CreateMode.PERSISTENT);
zkClient.makePath(path, data, CreateMode.PERSISTENT);
}
} else if (line.getOptionValue(CMD).equalsIgnoreCase(GET)) {
List<String> arglist = line.getArgList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
import org.apache.solr.handler.admin.api.SingleCoreStatusAPI;
import org.apache.solr.handler.admin.api.SplitCoreAPI;
import org.apache.solr.handler.admin.api.SwapCoresAPI;
import org.apache.solr.handler.admin.api.UnloadCoreAPI;
import org.apache.solr.handler.admin.api.UnloadCore;
import org.apache.solr.logging.MDCLoggingContext;
import org.apache.solr.metrics.SolrMetricManager;
import org.apache.solr.metrics.SolrMetricsContext;
Expand Down Expand Up @@ -385,7 +385,6 @@ public Collection<Api> getApis() {
apis.addAll(AnnotatedApi.getApis(new OverseerOperationAPI(this)));
apis.addAll(AnnotatedApi.getApis(new SwapCoresAPI(this)));
apis.addAll(AnnotatedApi.getApis(new RenameCoreAPI(this)));
apis.addAll(AnnotatedApi.getApis(new UnloadCoreAPI(this)));
apis.addAll(AnnotatedApi.getApis(new MergeIndexesAPI(this)));
apis.addAll(AnnotatedApi.getApis(new SplitCoreAPI(this)));
apis.addAll(AnnotatedApi.getApis(new RequestCoreCommandStatusAPI(this)));
Expand All @@ -406,7 +405,8 @@ public Collection<Class<? extends JerseyResource>> getJerseyResources() {
InstallCoreData.class,
BackupCoreAPI.class,
RestoreCore.class,
ReloadCore.class);
ReloadCore.class,
UnloadCore.class);
}

public interface CoreAdminOp {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.apache.solr.client.api.model.ListCoreSnapshotsResponse;
import org.apache.solr.client.api.model.ReloadCoreRequestBody;
import org.apache.solr.client.api.model.SolrJerseyResponse;
import org.apache.solr.client.api.model.UnloadCoreRequestBody;
import org.apache.solr.cloud.ZkController;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
Expand All @@ -76,6 +77,7 @@
import org.apache.solr.handler.admin.CoreAdminHandler.CoreAdminOp;
import org.apache.solr.handler.admin.api.CoreSnapshot;
import org.apache.solr.handler.admin.api.ReloadCore;
import org.apache.solr.handler.admin.api.UnloadCore;
import org.apache.solr.handler.api.V2ApiUtils;
import org.apache.solr.search.SolrIndexSearcher;
import org.apache.solr.update.UpdateLog;
Expand Down Expand Up @@ -122,14 +124,17 @@ public enum CoreAdminOperation implements CoreAdminOp {
it -> {
SolrParams params = it.req.getParams();
String cname = params.required().get(CoreAdminParams.CORE);

boolean deleteIndexDir = params.getBool(CoreAdminParams.DELETE_INDEX, false);
boolean deleteDataDir = params.getBool(CoreAdminParams.DELETE_DATA_DIR, false);
boolean deleteInstanceDir = params.getBool(CoreAdminParams.DELETE_INSTANCE_DIR, false);
CoreDescriptor cdescr = it.handler.coreContainer.getCoreDescriptor(cname);
it.handler.coreContainer.unload(cname, deleteIndexDir, deleteDataDir, deleteInstanceDir);

assert TestInjection.injectNonExistentCoreExceptionAfterUnload(cname);
final var unloadCoreRequestBody = new UnloadCoreRequestBody();
unloadCoreRequestBody.deleteIndex = params.getBool(CoreAdminParams.DELETE_INDEX, false);
unloadCoreRequestBody.deleteDataDir =
params.getBool(CoreAdminParams.DELETE_DATA_DIR, false);
unloadCoreRequestBody.deleteInstanceDir =
params.getBool(CoreAdminParams.DELETE_INSTANCE_DIR, false);
UnloadCore unloadCoreAPI =
new UnloadCore(
it.handler.coreContainer, it.handler.getCoreAdminAsyncTracker(), it.req, it.rsp);
SolrJerseyResponse response = unloadCoreAPI.unloadCore(cname, unloadCoreRequestBody);
V2ApiUtils.squashIntoSolrResponseWithoutHeader(it.rsp, response);
}),
RELOAD_OP(
RELOAD,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* 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 static org.apache.solr.security.PermissionNameProvider.Name.CORE_EDIT_PERM;

import javax.inject.Inject;
import org.apache.solr.client.api.endpoint.UnloadCoreApi;
import org.apache.solr.client.api.model.SolrJerseyResponse;
import org.apache.solr.client.api.model.UnloadCoreRequestBody;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.CoreDescriptor;
import org.apache.solr.handler.admin.CoreAdminHandler;
import org.apache.solr.jersey.PermissionName;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.util.TestInjection;

/**
* V2 API implementation for unloading a Solr core.
*
* <p>The API (POST /v2/cores/coreName/unload is equivalent to the v1 /admin/cores?action=unload
* command.
*/
public class UnloadCore extends CoreAdminAPIBase implements UnloadCoreApi {

@Inject
public UnloadCore(
CoreContainer coreContainer,
CoreAdminHandler.CoreAdminAsyncTracker coreAdminAsyncTracker,
SolrQueryRequest solrQueryRequest,
SolrQueryResponse solrQueryResponse) {
super(coreContainer, coreAdminAsyncTracker, solrQueryRequest, solrQueryResponse);
}

@PermissionName(CORE_EDIT_PERM)
@Override
public SolrJerseyResponse unloadCore(String coreName, UnloadCoreRequestBody requestBody)
throws Exception {
ensureRequiredParameterProvided("coreName", coreName);
SolrJerseyResponse solrJerseyResponse = instantiateJerseyResponse(SolrJerseyResponse.class);
if (requestBody == null) {
requestBody = new UnloadCoreRequestBody();
}
final var requestBodyFinal = requestBody; // Lambda below requires a 'final' variable
return handlePotentiallyAsynchronousTask(
solrJerseyResponse,
coreName,
requestBody.async,
"unload",
() -> {
CoreDescriptor cdescr = coreContainer.getCoreDescriptor(coreName);
coreContainer.unload(
coreName,
requestBodyFinal.deleteIndex == null ? false : requestBodyFinal.deleteIndex,
requestBodyFinal.deleteDataDir == null ? false : requestBodyFinal.deleteDataDir,
requestBodyFinal.deleteInstanceDir == null
? false
: requestBodyFinal.deleteInstanceDir);
assert TestInjection.injectNonExistentCoreExceptionAfterUnload(coreName);
return solrJerseyResponse;
});
}
}
Loading

0 comments on commit b9ec384

Please sign in to comment.