Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions changelog/unreleased/SOLR-12239-index-sort-existing-collection.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
title: >
New RESORTINDEX core-admin action re-sorts an existing core's index into a configured sort order,
so index sorting can be enabled on a collection created without it, without deleting and reindexing
from source. Not supported in SolrCloud mode; indexes with child/nested documents are rejected.
type: added
authors:
- name: Serhiy Bzhezytskyy
links:
- name: SOLR-12239
url: https://issues.apache.org/jira/browse/SOLR-12239
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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.Parameter;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import org.apache.solr.client.api.model.ResortCoreIndexRequestBody;
import org.apache.solr.client.api.model.ResortCoreIndexResponse;

/** V2 API definition for re-sorting an existing core index (SOLR-12239). */
@Path("/cores/{coreName}/resort")
public interface ResortCoreIndexApi {

@POST
@Operation(
summary =
"Re-sort the existing index of the specified core into the target sort order, so index "
+ "sorting can be enabled without reindexing from source.",
tags = {"cores"})
ResortCoreIndexResponse resortCoreIndex(
@Parameter(description = "The name of the core whose index should be re-sorted")
@PathParam("coreName")
String coreName,
ResortCoreIndexRequestBody requestBody)
throws Exception;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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 ResortCoreIndexRequestBody {

@Schema(
description =
"The target index sort, in Solr sort syntax (e.g. 'timestamp desc'). If omitted, the "
+ "sort configured for the core (via a SortingMergePolicy) is used. Fields must have "
+ "docValues.")
@JsonProperty
public String sort;

@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
@@ -0,0 +1,31 @@
/*
* 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 ResortCoreIndexResponse extends SolrJerseyResponse {

@Schema(description = "The name of the core whose index was re-sorted.")
@JsonProperty
public String core;

@Schema(description = "The index sort that was applied.")
@JsonProperty
public String indexSort;
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import org.apache.solr.handler.admin.api.RequestBufferUpdatesAPI;
import org.apache.solr.handler.admin.api.RequestCoreRecoveryAPI;
import org.apache.solr.handler.admin.api.RequestSyncShardAPI;
import org.apache.solr.handler.admin.api.ResortCoreIndex;
import org.apache.solr.handler.admin.api.RestoreCore;
import org.apache.solr.handler.admin.api.SplitCoreAPI;
import org.apache.solr.handler.admin.api.SwapCores;
Expand Down Expand Up @@ -339,6 +340,7 @@ public Collection<Class<? extends JerseyResource>> getJerseyResources() {
SwapCores.class,
RenameCore.class,
MergeIndexes.class,
ResortCoreIndex.class,
GetNodeCommandStatus.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import static org.apache.solr.common.params.CoreAdminParams.CoreAdminAction.REQUESTRECOVERY;
import static org.apache.solr.common.params.CoreAdminParams.CoreAdminAction.REQUESTSTATUS;
import static org.apache.solr.common.params.CoreAdminParams.CoreAdminAction.REQUESTSYNCSHARD;
import static org.apache.solr.common.params.CoreAdminParams.CoreAdminAction.RESORTINDEX;
import static org.apache.solr.common.params.CoreAdminParams.CoreAdminAction.RESTORECORE;
import static org.apache.solr.common.params.CoreAdminParams.CoreAdminAction.SPLIT;
import static org.apache.solr.common.params.CoreAdminParams.CoreAdminAction.STATUS;
Expand Down Expand Up @@ -258,7 +259,8 @@ public enum CoreAdminOperation implements CoreAdminOp {

V2ApiUtils.squashIntoSolrResponseWithoutHeader(it.rsp, response);
}),
UPGRADEINDEX_OP(UPGRADEINDEX, new UpgradeCoreIndexOp());
UPGRADEINDEX_OP(UPGRADEINDEX, new UpgradeCoreIndexOp()),
RESORTINDEX_OP(RESORTINDEX, new ResortIndexOp());

final CoreAdminParams.CoreAdminAction action;
final CoreAdminOp fun;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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;

import org.apache.solr.client.api.model.ResortCoreIndexRequestBody;
import org.apache.solr.client.api.model.ResortCoreIndexResponse;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.CoreAdminParams;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.handler.admin.api.ResortCoreIndex;
import org.apache.solr.handler.api.V2ApiUtils;

/**
* v1 ({@code action=RESORTINDEX}) wrapper delegating to the {@link ResortCoreIndex} V2 API
* (SOLR-12239).
*/
class ResortIndexOp implements CoreAdminHandler.CoreAdminOp {

@Override
public boolean isExpensive() {
return true;
}

@Override
public void execute(CoreAdminHandler.CallInfo it) throws Exception {
final SolrParams params = it.req.getParams();
final String cname = params.required().get(CoreAdminParams.CORE);
final var requestBody = new ResortCoreIndexRequestBody();
// "async" is intentionally omitted because CoreAdminHandler has already processed it.
requestBody.sort = params.get(CommonParams.SORT);

final CoreContainer coreContainer = it.handler.getCoreContainer();
final ResortCoreIndex api =
new ResortCoreIndex(coreContainer, it.handler.getCoreAdminAsyncTracker(), it.req, it.rsp);
final ResortCoreIndexResponse response = api.resortCoreIndex(cname, requestBody);
V2ApiUtils.squashIntoSolrResponseWithoutHeader(it.rsp, response);
}
}
Loading