-
Notifications
You must be signed in to change notification settings - Fork 809
SOLR-17725: CoreAdmin API to upgrade an index in-place to facilitate Solr upgrade across major versions #3903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rahulgoswami
wants to merge
43
commits into
apache:main
Choose a base branch
from
Commvault:index-upgrade
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,104
−2
Open
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
1ea5cce
Add merge policy to block older segments from participating in merges
rahulgoswami cdc9978
extend FilterMergePolicy for delegation and modularize logic
rahulgoswami 4be5ca1
First draft: Add UPGRADECOREINDEX as a CoreAdmin API
rahulgoswami 052cda6
fix incorrect early-exit while iterating over segments
rahulgoswami faff01f
merge with main
rahulgoswami c9e3f3e
restore original merge policy; injectable factory for test stubs; opt…
rahulgoswami daaaecb
cleanup and optimizations
rahulgoswami 1fa4f2a
more cleanup
rahulgoswami de455df
get default update chain if update.chain is not defined for /update
rahulgoswami c98418b
fix getUpdateProcessorChain()
rahulgoswami 57b5842
gradlew tidy
rahulgoswami abd584e
fix getUpdateProcessorChain()
rahulgoswami bdfa291
1) incorrect LeafReader closure.2) Fix validation
rahulgoswami feb70ac
cleanup
rahulgoswami 393c081
interrupt handling and validation cleanup
rahulgoswami b335e8e
async mode may cause merge policy to be reset immediately
rahulgoswami 6a354fd
Fix null response
rahulgoswami 088c599
changelog
rahulgoswami dfd7786
Merge branch 'main' into index-upgrade since LatestVersionMergePolicy…
rahulgoswami 3655ef4
LatestVersionMergePolicy renamed
rahulgoswami a50fc8d
Fix issue with running in async mode
rahulgoswami 3607110
Decorate response with bookkeeping info and upgrade state
rahulgoswami 0f10339
Wrap exceptions in CoreAdminAPIBaseException
rahulgoswami b8b5deb
Wrap exceptions in CoreAdminAPIBaseException
rahulgoswami 983f2d6
Handle exceptions in processSegment to preserve the main failure
rahulgoswami d005712
keeping validateLogCalls and forbidden apis check happy
rahulgoswami c8f2df2
Add UPGRADECOREINDEX to ref guide for CoreAdmin API
rahulgoswami ee5d1e2
do UpdateHandler.commit() instead of IndexWriter.commit() to clear se…
rahulgoswami b53dec1
add tests
rahulgoswami d7faaa4
Use VarHandle instead of reflection in UpgradeCoreIndexActionTest to …
rahulgoswami b68f587
Add license
rahulgoswami 58b25b3
Added javadoc for UpgradeCoreIndex; Removed redundant null checks and…
rahulgoswami 1e48deb
Modularize lambda; Fix typos
rahulgoswami 361b248
Push calculation of eligible segments into the main processing loop; …
rahulgoswami 68038ee
Use getRawReder() instead of getTopReaderContext(); better variable n…
rahulgoswami 99136e8
Refactor processSegment to handle close() through try-with-resources;…
rahulgoswami 39c91cc
Used directoryFactory from the core for validation in isIndexUpgraded…
rahulgoswami c464e40
Avoid unncessary unwrapping in processSegment()
rahulgoswami 83b2dd0
Switch to using searcher.getIndexReader() (instead of getRawReader) t…
rahulgoswami 023e6fa
Don't remove _version_ field
rahulgoswami bbb52d6
Readability changes: Use core.withSearcher() in tests; decompose Upgr…
rahulgoswami a8bbe76
Bail out if index contains nested docs; Add test
rahulgoswami b3edeb5
Include note about nested docs
rahulgoswami File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
changelog/unreleased/SOLR-17725-CoreAdmin-API-to-upgrade-an-index-in-place.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # See https://github.com/apache/solr/blob/main/dev-docs/changelog.adoc | ||
| title: CoreAdmin API (/admin/cores?action=UPGRADECOREINDEX) to upgrade an index in-place | ||
| type: added | ||
| authors: | ||
| - name: Rahul Goswami | ||
| links: | ||
| - name: SOLR-17725 | ||
| url: https://issues.apache.org/jira/browse/SOLR-17725 | ||
|
|
33 changes: 33 additions & 0 deletions
33
solr/api/src/java/org/apache/solr/client/api/model/UpgradeCoreIndexRequestBody.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /* | ||
| * 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 UpgradeCoreIndexRequestBody { | ||
|
|
||
| @Schema(description = "Request ID to track this action which will be processed asynchronously.") | ||
| @JsonProperty | ||
| public String async; | ||
|
|
||
| @Schema( | ||
| description = | ||
| "updateChain to be used for reindexing during index upgrade if you don't want to use the one used by /update by default") | ||
| @JsonProperty | ||
| public String updateChain; | ||
| } | ||
38 changes: 38 additions & 0 deletions
38
solr/api/src/java/org/apache/solr/client/api/model/UpgradeCoreIndexResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /* | ||
| * 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 UpgradeCoreIndexResponse extends SolrJerseyResponse { | ||
| @Schema(description = "The name of the core.") | ||
| @JsonProperty | ||
| public String core; | ||
|
|
||
| @Schema(description = "The total number of segments eligible for upgrade.") | ||
| @JsonProperty | ||
| public Integer numSegmentsEligibleForUpgrade; | ||
|
|
||
| @Schema(description = "The number of segments successfully upgraded.") | ||
| @JsonProperty | ||
| public Integer numSegmentsUpgraded; | ||
|
|
||
| @Schema(description = "Status of the core index upgrade operation.") | ||
| @JsonProperty | ||
| public String upgradeStatus; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
solr/core/src/java/org/apache/solr/handler/admin/UpgradeCoreIndexOp.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| /* | ||
| * 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.UpgradeCoreIndexRequestBody; | ||
| import org.apache.solr.client.api.model.UpgradeCoreIndexResponse; | ||
| import org.apache.solr.common.SolrException; | ||
| import org.apache.solr.common.params.CommonAdminParams; | ||
| import org.apache.solr.common.params.CoreAdminParams; | ||
| import org.apache.solr.common.params.SolrParams; | ||
| import org.apache.solr.common.params.UpdateParams; | ||
| import org.apache.solr.common.util.NamedList; | ||
| import org.apache.solr.core.CoreContainer; | ||
| import org.apache.solr.handler.admin.api.UpgradeCoreIndex; | ||
| import org.apache.solr.handler.api.V2ApiUtils; | ||
| import org.apache.solr.request.SolrQueryRequest; | ||
| import org.apache.solr.response.SolrQueryResponse; | ||
|
|
||
| class UpgradeCoreIndexOp implements CoreAdminHandler.CoreAdminOp { | ||
| @FunctionalInterface | ||
| public interface UpgradeCoreIndexFactory { | ||
| UpgradeCoreIndex create( | ||
| CoreContainer coreContainer, | ||
| CoreAdminHandler.CoreAdminAsyncTracker coreAdminAsyncTracker, | ||
| SolrQueryRequest req, | ||
| SolrQueryResponse rsp); | ||
| } | ||
|
|
||
| static UpgradeCoreIndexFactory UPGRADE_CORE_INDEX_FACTORY = UpgradeCoreIndex::new; | ||
|
|
||
| @Override | ||
| public boolean isExpensive() { | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public void execute(CoreAdminHandler.CallInfo it) throws Exception { | ||
|
|
||
| assert it.handler.coreContainer != null; | ||
| if (it.handler.coreContainer.isZooKeeperAware()) { | ||
| throw new SolrException( | ||
| SolrException.ErrorCode.BAD_REQUEST, | ||
| "action=UPGRADECOREINDEX is not supported in SolrCloud mode. As an alternative, in order to upgrade index, configure LatestVersionMergePolicyFactory in solrconfig.xml and reindex the data in your collection."); | ||
| } | ||
|
|
||
| SolrParams params = it.req.getParams(); | ||
| String cname = params.required().get(CoreAdminParams.CORE); | ||
| final boolean isAsync = params.get(CommonAdminParams.ASYNC) != null; | ||
| final var requestBody = new UpgradeCoreIndexRequestBody(); | ||
| requestBody.updateChain = params.get(UpdateParams.UPDATE_CHAIN); | ||
|
|
||
| UpgradeCoreIndex upgradeCoreIndexApi = | ||
| UPGRADE_CORE_INDEX_FACTORY.create( | ||
| it.handler.coreContainer, it.handler.coreAdminAsyncTracker, it.req, it.rsp); | ||
| final UpgradeCoreIndexResponse response = | ||
| upgradeCoreIndexApi.upgradeCoreIndex(cname, requestBody); | ||
| V2ApiUtils.squashIntoSolrResponseWithoutHeader(it.rsp, response); | ||
|
|
||
| if (isAsync) { | ||
| final var opResponse = new NamedList<>(); | ||
| V2ApiUtils.squashIntoNamedListWithoutHeader(opResponse, response); | ||
| // REQUESTSTATUS is returning the inner response NamedList as a positional array | ||
| // ([k1,v1,k2,v2...]). | ||
| // so converting to a map | ||
| it.rsp.addResponse(opResponse.asMap(1)); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe @gerlowskija might review the V2 API spect.
But what I notice here is this
async--- I'm suspicious as I figure it'd be handled in a more general way without each command needing to redundantly specify it, which is basically all commands.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tested this with only V1 api so far, but have tried to follow the pattern for V2 as well. There might be gaps which @gerlowskija could point out (?). In case of v1, the async is handled by the CoreAdminHandler.handleRequestBody() itself by adding to CoreAdminAsyncTracker https://github.com/apache/solr/blob/main/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java#L231
Right now unlike the SolrJerseyResponse, the *RequestBody classes don't inherit from a common parent so each one seems to introduce the "async" by itself. Perhaps a case for refactoring and pushing "async" into the parent class? An action item for another PR?