Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into save_models_compacted…
Browse files Browse the repository at this point in the history
…_SOLR-17050

Resolved Conflicts:
	solr/CHANGES.txt
  • Loading branch information
cpoerschke committed Nov 17, 2023
2 parents cc4a2d4 + 9eb0466 commit e369a6c
Show file tree
Hide file tree
Showing 32 changed files with 422 additions and 378 deletions.
2 changes: 1 addition & 1 deletion gradle/node.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

configure([project(":solr:packaging"), project(":solr:solr-ref-guide")]) {
configure([project(":solr:packaging"), project(":solr:solr-ref-guide"), project(":solr:webapp")]) {
apply plugin: "com.github.node-gradle.node"

ext {
Expand Down
6 changes: 3 additions & 3 deletions gradle/validation/error-prone.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

def skipReason

if (rootProject.usesAltJvm && rootProject.runtimeJavaVersion > JavaVersion.VERSION_15) {
skipReason = "won't work with JDK ${rootProject.runtimeJavaVersion} if used as alternative java toolchain"
if (rootProject.usesAltJvm) {
skipReason = "won't work with alternative java toolchain"
}

if (!propertyOrDefault("validation.errorprone", isCIBuild).asBoolean()) {
Expand All @@ -37,7 +37,7 @@ if (skipReason) {

allprojects { prj ->
plugins.withType(JavaPlugin) {
// LUCENE-9650: Errorprone on master/gradle does not work with JDK-16+ when running as plugin
// LUCENE-9650: Errorprone on master/gradle does not work when running as plugin
// inside a forked Javac process. Javac running inside Gradle works, because we have
// additional module system opens in place.
// This is a hack to keep the dependency (so that palantir's version check doesn't complain)
Expand Down
7 changes: 6 additions & 1 deletion solr/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ Deprecation Removals

* SOLR-15959: Remove deprecated feature to load solr.xml from ZK (janhoy)

* SOLR-16961: The legacy Circuit Breaker named `CircuitBreakerManager`, is removed. Please use individual Circuit Breaker plugins instead. (janhoy)

* SOLR-17042: Remove deprecated `V2RequestSupport` and associated `SolrRequest` methods `setUseV2` and `setUseBinaryV2`. (Jason Gerlowski)

Dependency Upgrades
Expand Down Expand Up @@ -96,7 +98,10 @@ Improvements

* SOLR-17041: Make CommitTracker currentTlogSize lazy (Alex Deparvu)

* SOLR-17050: Use compact JSON for Learning to Rank (LTR) feature and model storage. (Florin Babes, Christine Poerschke)
* SOLR-16397: The rename-core v2 endpoint has been updated to be more REST-ful.
RENAME is now available at `POST /api/cores/coreName/rename` (Sanjay Dutt via Jason Gerlowski)

* SOLR-17035: Add trace id to jetty thread names to improve debuggability via stack traces (Alex Deparvu)

Optimizations
---------------------
Expand Down
27 changes: 27 additions & 0 deletions solr/api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@

plugins {
id 'io.swagger.core.v3.swagger-gradle-plugin' version '2.2.2'
id "org.openapi.generator" version "6.0.1"
}

apply plugin: 'java-library'

description = 'API - Interfaces and classes used to represent Solrs APIs'

ext {
jsClientDir = "${buildDir}/generated/js"
openApiSpecDir = "${buildDir}/generated/openapi"
openApiSpecFile = "${project.openApiSpecDir}/openapi.json"
}
Expand All @@ -33,6 +35,10 @@ configurations {
canBeConsumed = true
canBeResolved = false
}
jsClient {
canBeConsumed = true
canBeResolved = false
}
}

resolve {
Expand All @@ -55,8 +61,29 @@ dependencies {
testImplementation 'org.apache.lucene:lucene-test-framework'
}

// Non-Java client generation tasks below:

task buildJSClient(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) {
generatorName.set("javascript")
inputSpec.set("$openApiSpecFile")
outputDir.set("$jsClientDir")
packageName.set("solr")
generateApiTests.set(false)
generateModelTests.set(false)
}

tasks.withType(org.openapitools.generator.gradle.plugin.tasks.GenerateTask) {
dependsOn(resolve)
}

artifacts {
// Ensure the OAS is available to other modules who want to generate code (i.e. solrj)
openapiSpec resolve.outputDir, {
builtBy resolve
}

// Makes our Javascript client available to the Admin UI build
jsClient file(project.jsClientDir), {
builtBy buildJSClient
}
}
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.RenameCoreRequestBody;
import org.apache.solr.client.api.model.SolrJerseyResponse;

/** V2 API definition for renaming a Solr core. */
@Path("/cores/{coreName}/rename")
public interface RenameCoreApi {
@POST
@Operation(
summary = "The RENAME action changes the name of a Solr core",
tags = {"cores"})
SolrJerseyResponse renameCore(
@PathParam("coreName") String coreName,
@RequestBody(description = "Additional properties related to the core renaming")
RenameCoreRequestBody requestBody)
throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.solr.client.api.model;

package org.apache.solr.util;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;

import org.junit.BeforeClass;
public class RenameCoreRequestBody {
@Schema(description = "The new name for the Solr core.", required = true)
@JsonProperty
public String to;

/** Tests the pluggable circuit breaker implementation. The actual tests are in base class. */
public class TestCircuitBreaker extends BaseTestCircuitBreaker {
@BeforeClass
public static void setUpClass() throws Exception {
System.setProperty("filterCache.enabled", "false");
System.setProperty("queryResultCache.enabled", "false");
System.setProperty("documentCache.enabled", "true");

initCore("solrconfig-pluggable-circuitbreaker.xml", "schema.xml");
BaseTestCircuitBreaker.indexDocs();
}
@Schema(description = "Request ID to track this action which will be processed asynchronously.")
@JsonProperty
public String async;
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ protected boolean checkCircuitBreakers(SolrQueryRequest req, SolrQueryResponse r
rsp.add(STATUS, FAILURE);
rsp.setException(
new SolrException(
CircuitBreaker.getErrorCode(trippedCircuitBreakers),
CircuitBreaker.getExceptionErrorCode(),
"Circuit Breakers tripped " + errorMessage));
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
import org.apache.solr.handler.admin.api.PrepareCoreRecoveryAPI;
import org.apache.solr.handler.admin.api.RejoinLeaderElectionAPI;
import org.apache.solr.handler.admin.api.ReloadCore;
import org.apache.solr.handler.admin.api.RenameCoreAPI;
import org.apache.solr.handler.admin.api.RenameCore;
import org.apache.solr.handler.admin.api.RequestApplyCoreUpdatesAPI;
import org.apache.solr.handler.admin.api.RequestBufferUpdatesAPI;
import org.apache.solr.handler.admin.api.RequestCoreCommandStatusAPI;
Expand Down Expand Up @@ -383,7 +383,6 @@ public Collection<Api> getApis() {
apis.addAll(AnnotatedApi.getApis(new CreateCoreAPI(this)));
apis.addAll(AnnotatedApi.getApis(new RejoinLeaderElectionAPI(this)));
apis.addAll(AnnotatedApi.getApis(new OverseerOperationAPI(this)));
apis.addAll(AnnotatedApi.getApis(new RenameCoreAPI(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() {
RestoreCore.class,
ReloadCore.class,
UnloadCore.class,
SwapCores.class);
SwapCores.class,
RenameCore.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.endpoint.SwapCoresApi;
import org.apache.solr.client.api.model.ListCoreSnapshotsResponse;
import org.apache.solr.client.api.model.ReloadCoreRequestBody;
import org.apache.solr.client.api.model.RenameCoreRequestBody;
import org.apache.solr.client.api.model.SolrJerseyResponse;
import org.apache.solr.client.api.model.SwapCoresRequestBody;
import org.apache.solr.client.api.model.UnloadCoreRequestBody;
Expand All @@ -79,6 +80,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.RenameCore;
import org.apache.solr.handler.admin.api.SwapCores;
import org.apache.solr.handler.admin.api.UnloadCore;
import org.apache.solr.handler.api.V2ApiUtils;
Expand Down Expand Up @@ -172,12 +174,15 @@ public enum CoreAdminOperation implements CoreAdminOp {
RENAME,
it -> {
SolrParams params = it.req.getParams();
String name = params.required().get(CoreAdminParams.OTHER);
String cname = params.required().get(CoreAdminParams.CORE);

if (cname.equals(name)) return;

it.handler.coreContainer.rename(cname, name);
final String cname = params.required().get(CoreAdminParams.CORE);
final String name = params.required().get(CoreAdminParams.OTHER);
final var renameCoreRequestBody = new RenameCoreRequestBody();
renameCoreRequestBody.to = name;
final var renameCoreApi =
new RenameCore(
it.handler.coreContainer, it.handler.getCoreAdminAsyncTracker(), it.req, it.rsp);
SolrJerseyResponse response = renameCoreApi.renameCore(cname, renameCoreRequestBody);
V2ApiUtils.squashIntoSolrResponseWithoutHeader(it.rsp, response);
}),

MERGEINDEXES_OP(MERGEINDEXES, new MergeIndexesOp()),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* 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.RenameCoreApi;
import org.apache.solr.client.api.model.RenameCoreRequestBody;
import org.apache.solr.client.api.model.SolrJerseyResponse;
import org.apache.solr.core.CoreContainer;
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;

/**
* V2 API for renaming an existing Solr core.
*
* <p>The new API (POST /v2/cores/coreName/rename is equivalent to the v1 /admin/cores?action=rename
* command.
*/
public class RenameCore extends CoreAdminAPIBase implements RenameCoreApi {
@Inject
public RenameCore(
CoreContainer coreContainer,
CoreAdminHandler.CoreAdminAsyncTracker coreAdminAsyncTracker,
SolrQueryRequest solrQueryRequest,
SolrQueryResponse solrQueryResponse) {
super(coreContainer, coreAdminAsyncTracker, solrQueryRequest, solrQueryResponse);
}

@PermissionName(CORE_EDIT_PERM)
@Override
public SolrJerseyResponse renameCore(String coreName, RenameCoreRequestBody requestBody)
throws Exception {
ensureRequiredParameterProvided("coreName", coreName);
ensureRequiredRequestBodyProvided(requestBody);
ensureRequiredParameterProvided("to", requestBody.to);
SolrJerseyResponse solrJerseyResponse = instantiateJerseyResponse(SolrJerseyResponse.class);
if (coreName.equals(requestBody.to)) return solrJerseyResponse;
return handlePotentiallyAsynchronousTask(
solrJerseyResponse,
coreName,
requestBody.async,
"rename",
() -> {
coreContainer.rename(coreName, requestBody.to);
return solrJerseyResponse;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ protected boolean checkCircuitBreakers(
rsp.add(STATUS, FAILURE);
rsp.setException(
new SolrException(
CircuitBreaker.getErrorCode(trippedCircuitBreakers),
CircuitBreaker.getExceptionErrorCode(),
"Circuit Breakers tripped " + errorMessage));
return true;
}
Expand Down
7 changes: 7 additions & 0 deletions solr/core/src/java/org/apache/solr/servlet/ServletUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,17 @@ private static void traceHttpRequestExecution2(
Context context = TraceUtils.extractContext(request);
Span span = TraceUtils.startHttpRequestSpan(request, context);

final Thread currentThread = Thread.currentThread();
final String oldThreadName = currentThread.getName();
try (var scope = context.with(span).makeCurrent()) {
assert scope != null; // prevent javac warning about scope being unused
TraceUtils.setSpan(request, span);
TraceUtils.ifValidTraceId(
span, s -> MDCLoggingContext.setTracerId(s.getSpanContext().getTraceId()));
String traceId = MDCLoggingContext.getTraceId();
if (traceId != null) {
currentThread.setName(oldThreadName + "-" + traceId);
}
tracedExecution.run();
} catch (ExceptionWhileTracing e) {
if (e.e instanceof SolrAuthenticationException) {
Expand All @@ -256,6 +262,7 @@ private static void traceHttpRequestExecution2(
throw new RuntimeException(e.e);
}
} finally {
currentThread.setName(oldThreadName);
TraceUtils.setHttpStatus(span, response.getStatus());
span.end();
}
Expand Down
Loading

0 comments on commit e369a6c

Please sign in to comment.