-
Notifications
You must be signed in to change notification settings - Fork 25.4k
Add extension points to remediate index metadata in during snapshot restore #131706
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
Merged
jbaiera
merged 7 commits into
elastic:main
from
jbaiera:remediate-failure-store-allocation-settings
Jul 29, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8e85a12
Add extension points to remediate index settings
jbaiera 071625b
Update docs/changelog/131706.yaml
jbaiera a0e7a44
[CI] Auto commit changes from spotless
27152de
PR feedback
jbaiera e6c4787
Cleanup instance creation
jbaiera c6d0215
Merge branch 'main' into remediate-failure-store-allocation-settings
jbaiera 6dd86d2
[CI] Auto commit changes from spotless
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
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,5 @@ | ||
pr: 131706 | ||
summary: Add extension points to remediate index metadata in during snapshot restore | ||
area: Snapshot/Restore | ||
type: enhancement | ||
issues: [] |
109 changes: 109 additions & 0 deletions
109
server/src/internalClusterTest/java/org/elasticsearch/snapshots/RemediateSnapshotIT.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,109 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.snapshots; | ||
|
||
import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse; | ||
import org.elasticsearch.action.admin.indices.get.GetIndexResponse; | ||
import org.elasticsearch.client.internal.Client; | ||
import org.elasticsearch.cluster.metadata.IndexMetadata; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.core.TimeValue; | ||
import org.elasticsearch.plugins.Plugin; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.stream.Stream; | ||
|
||
import static org.elasticsearch.index.IndexSettings.INDEX_SEARCH_IDLE_AFTER; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.greaterThan; | ||
|
||
public class RemediateSnapshotIT extends AbstractSnapshotIntegTestCase { | ||
|
||
@Override | ||
protected Collection<Class<? extends Plugin>> nodePlugins() { | ||
return Stream.concat(Stream.of(RemediateSnapshotTestPlugin.class), super.nodePlugins().stream()).toList(); | ||
} | ||
|
||
public void testRemediationOnRestore() { | ||
Client client = client(); | ||
|
||
createRepository("test-repo", "fs"); | ||
|
||
createIndex("test-idx-1", "test-idx-2", "test-idx-3"); | ||
ensureGreen(); | ||
|
||
GetIndexResponse getIndexResponse = client.admin() | ||
.indices() | ||
.prepareGetIndex(TEST_REQUEST_TIMEOUT) | ||
.setIndices("test-idx-1", "test-idx-2", "test-idx-3") | ||
.get(); | ||
|
||
assertThat( | ||
INDEX_SEARCH_IDLE_AFTER.get(getIndexResponse.settings().get("test-idx-1")), | ||
equalTo(INDEX_SEARCH_IDLE_AFTER.getDefault(Settings.EMPTY)) | ||
); | ||
assertThat( | ||
INDEX_SEARCH_IDLE_AFTER.get(getIndexResponse.settings().get("test-idx-2")), | ||
equalTo(INDEX_SEARCH_IDLE_AFTER.getDefault(Settings.EMPTY)) | ||
); | ||
assertThat( | ||
INDEX_SEARCH_IDLE_AFTER.get(getIndexResponse.settings().get("test-idx-3")), | ||
equalTo(INDEX_SEARCH_IDLE_AFTER.getDefault(Settings.EMPTY)) | ||
); | ||
|
||
indexRandomDocs("test-idx-1", 100); | ||
indexRandomDocs("test-idx-2", 100); | ||
|
||
createSnapshot("test-repo", "test-snap", Arrays.asList("test-idx-1", "test-idx-2")); | ||
|
||
logger.info("--> close snapshot indices"); | ||
client.admin().indices().prepareClose("test-idx-1", "test-idx-2").get(); | ||
|
||
logger.info("--> restore indices"); | ||
RestoreSnapshotResponse restoreSnapshotResponse = client.admin() | ||
.cluster() | ||
.prepareRestoreSnapshot(TEST_REQUEST_TIMEOUT, "test-repo", "test-snap") | ||
.setWaitForCompletion(true) | ||
.get(); | ||
assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0)); | ||
|
||
GetIndexResponse getIndexResponseAfter = client.admin() | ||
.indices() | ||
.prepareGetIndex(TEST_REQUEST_TIMEOUT) | ||
.setIndices("test-idx-1", "test-idx-2", "test-idx-3") | ||
.get(); | ||
|
||
assertDocCount("test-idx-1", 100L); | ||
assertThat(INDEX_SEARCH_IDLE_AFTER.get(getIndexResponseAfter.settings().get("test-idx-1")), equalTo(TimeValue.timeValueMinutes(2))); | ||
assertDocCount("test-idx-2", 100L); | ||
assertThat(INDEX_SEARCH_IDLE_AFTER.get(getIndexResponseAfter.settings().get("test-idx-2")), equalTo(TimeValue.timeValueMinutes(2))); | ||
} | ||
|
||
/** | ||
* Dummy plugin to load SPI function off of | ||
*/ | ||
public static class RemediateSnapshotTestPlugin extends Plugin {} | ||
|
||
public static class RemediateSnapshotTestTransformer implements IndexMetadataRestoreTransformer { | ||
@Override | ||
public IndexMetadata updateIndexMetadata(IndexMetadata original) { | ||
// Set a property to something mild, outside its default | ||
return IndexMetadata.builder(original) | ||
.settings( | ||
Settings.builder() | ||
.put(original.getSettings()) | ||
.put(INDEX_SEARCH_IDLE_AFTER.getKey(), TimeValue.timeValueMinutes(2)) | ||
.build() | ||
) | ||
.build(); | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...t/resources/META-INF/services/org.elasticsearch.snapshots.IndexMetadataRestoreTransformer
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,10 @@ | ||
# | ||
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
# or more contributor license agreements. Licensed under the "Elastic License | ||
# 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
# Public License v 1"; you may not use this file except in compliance with, at | ||
# your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
# License v3.0 only", or the "Server Side Public License, v 1". | ||
# | ||
|
||
org.elasticsearch.snapshots.RemediateSnapshotIT$RemediateSnapshotTestTransformer |
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
38 changes: 38 additions & 0 deletions
38
server/src/main/java/org/elasticsearch/snapshots/IndexMetadataRestoreTransformer.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 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.snapshots; | ||
|
||
import org.elasticsearch.cluster.metadata.IndexMetadata; | ||
|
||
/** | ||
* A temporary interface meant to allow a plugin to provide remedial logic for index metadata being restored from a snapshot. This was | ||
* added to address an allocation issue and will eventually be removed once any affected snapshots age out. | ||
*/ | ||
public interface IndexMetadataRestoreTransformer { | ||
IndexMetadata updateIndexMetadata(IndexMetadata original); | ||
|
||
/** | ||
* A default implementation of {@link IndexMetadataRestoreTransformer} which does nothing | ||
*/ | ||
final class NoOpRestoreTransformer implements IndexMetadataRestoreTransformer { | ||
public static final NoOpRestoreTransformer INSTANCE = new NoOpRestoreTransformer(); | ||
|
||
public static NoOpRestoreTransformer getInstance() { | ||
return INSTANCE; | ||
} | ||
|
||
private NoOpRestoreTransformer() {} | ||
|
||
@Override | ||
public IndexMetadata updateIndexMetadata(IndexMetadata original) { | ||
return original; | ||
} | ||
} | ||
} |
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.