-
Notifications
You must be signed in to change notification settings - Fork 25.2k
ILM: add searchable snapshot action #52585
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
andreidan
merged 85 commits into
elastic:feature/searchable-snapshots
from
andreidan:ilm-searchable-snapshot-action
Apr 1, 2020
Merged
Changes from 76 commits
Commits
Show all changes
85 commits
Select commit
Hold shift + click to select a range
25cea2b
ILM: add searchable snapshot action
andreidan 3c32490
Merge branch 'feature/searchable-snapshots' into ilm-searchable-snaps…
elasticmachine 7dbc46e
Add license header
andreidan 9881c44
Document why we don’t restore the lifecycle setting
andreidan a601dbf
Checkstyle
andreidan f0a9da1
Remove unused import
andreidan dfec7c9
Use WaitForIndexColorStep
andreidan a6bc720
Use requireNonNull
andreidan 271fb54
Refactorings and cleanups
andreidan f6f7d29
Make performAction final in AsyncRetryDuringSnapshotActionStep
andreidan 7075752
Add docs and redesign OnAsyncWaitBranchingStep
andreidan 501dbaf
Rename BranchingStepListener onStopWaitingForCondition
andreidan 1222902
Extract and reuse the alias swap request
andreidan faa2834
Rename restoredIndexPrefix to targetIndexPrefix
andreidan 21d67cb
Fix tests
andreidan 7e0d5f7
Unused imports
andreidan eafe3de
Handle null next step key
andreidan bc91ae3
Try with resources in test
andreidan 8520c7b
Rename originalIndex to sourceIndexName
andreidan 9735649
Merge branch 'feature/searchable-snapshots' into ilm-searchable-snaps…
elasticmachine d20cf52
More tests
andreidan 8a46d05
Add more steps tests
andreidan 12c1f5f
Make method static
andreidan 3870388
Don’t fail if the response isAck flag is false
andreidan d28557c
Searchable action tests and more step tests
andreidan 357987b
Merge branch 'feature/searchable-snapshots' into ilm-searchable-snaps…
elasticmachine 6960187
Merge branch 'feature/searchable-snapshots' into ilm-searchable-snaps…
elasticmachine 9af943f
Merge branch 'feature/searchable-snapshots' into ilm-searchable-snaps…
elasticmachine 858e6a1
Store the snapshot name in the ILM execution state
andreidan 6edfcd0
Remove import
andreidan e4791b0
Merge branch 'feature/searchable-snapshots' into ilm-searchable-snaps…
elasticmachine 63194ea
Copy the repository and snapshot name
andreidan a92463f
Expose repo and snapshot name in the ILM explain response
andreidan 0f65ed7
Explain lifecycle repo and snapshot in transport
andreidan 6e779b6
Delete action has an optional parameter delege_generated_snapshot
andreidan 841f6bc
Merge branch 'feature/searchable-snapshots' into ilm-searchable-snaps…
elasticmachine da361b5
Merge branch 'feature/searchable-snapshots' into ilm-searchable-snaps…
andreidan 5eb524e
Drop the searchable repository action param
andreidan 8e8ff99
Drop sys.out.println
andreidan 119c439
Fix docs tests
andreidan 064b4e7
BWC for DeleteAction delete generated snap flag
andreidan 1cb6480
Merge branch 'feature/searchable-snapshots' into ilm-searchable-snaps…
elasticmachine 3a750e0
Merge branch 'feature/searchable-snapshots' into ilm-searchable-snaps…
elasticmachine 0a79753
Update settings version when copying settings
andreidan 013d4df
Add test that deletes the snapshot
andreidan aa098d2
Document step
andreidan 520d6bb
Merge branch 'feature/searchable-snapshots' into ilm-searchable-snaps…
elasticmachine 5e4cf55
Merge branch 'feature/searchable-snapshots' into ilm-searchable-snaps…
andreidan 32e3371
Format code
andreidan ac9e9c3
Make CleanupSnapshotStep retryable
andreidan b68b61c
Fix typo
andreidan 374e50d
Format code
andreidan 4f25ce9
CreateSnapshotStep request specifies index name
andreidan 0f6f371
Rename delete action field to delete_searchable_snapshot
andreidan 15d39ed
Rename SSA repo field to snapshot_repository (underscore)
andreidan e76ff6c
Fix delete action test assertions
andreidan ff7623f
Merge branch 'feature/searchable-snapshots' into ilm-searchable-snaps…
elasticmachine 3c56f73
Fix doc tests
andreidan 06bf054
Change debug level to warn
andreidan c3d785e
Log when we stop waiting for the branch condition
andreidan 9d37f78
MountSnapshotStep is retries when response is not acked
andreidan 985477e
Doc null handling
andreidan 2e4bd2b
Update info message to be good english
andreidan cd73bd6
Use the correct Info class Luke
andreidan 0ca1db0
Cleanup if/else branches that check the snapshot state
andreidan 2b467cf
Log that the swap aliases response was not acked
andreidan 5f506ee
SnapshotInProgress null check
andreidan 80c9a45
Fix test
andreidan 8ed70c8
Merge branch 'feature/searchable-snapshots' into ilm-searchable-snaps…
elasticmachine c38e081
Delete phase min_age after 5 seconds
andreidan c032d3a
Checkstyle
andreidan 7107b1a
Use underscore in action name too
andreidan 5bc6df2
Get the generated snapshot name from the original index in test
andreidan 5b7f599
Merge branch 'feature/searchable-snapshots' into ilm-searchable-snaps…
elasticmachine 7f1940d
Merge branch 'feature/searchable-snapshots' into ilm-searchable-snaps…
elasticmachine 879e7d6
Merge branch 'feature/searchable-snapshots' into ilm-searchable-snaps…
elasticmachine 01222af
Merge branch 'feature/searchable-snapshots' into ilm-searchable-snaps…
elasticmachine 64a903d
Update exception message
andreidan 6e4ede4
Update javadoc
andreidan 864f4c3
Add example of generated snapshot name
andreidan 9bbb9df
Fail CleanupSnapshotStep if the request is not acked
andreidan 2c61f00
Move empty settings check before target index check
andreidan ac574b2
Delete WaitForSnapshotInProgressStepTests
andreidan 567d067
Merge branch 'feature/searchable-snapshots' into ilm-searchable-snaps…
elasticmachine b766806
Fix typo
andreidan 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
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
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
76 changes: 76 additions & 0 deletions
76
x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CleanupSnapshotStep.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,76 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
package org.elasticsearch.xpack.core.ilm; | ||
|
||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest; | ||
import org.elasticsearch.action.support.master.AcknowledgedResponse; | ||
import org.elasticsearch.client.Client; | ||
import org.elasticsearch.cluster.ClusterState; | ||
import org.elasticsearch.cluster.metadata.IndexMetaData; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.repositories.RepositoryMissingException; | ||
import org.elasticsearch.snapshots.SnapshotMissingException; | ||
|
||
import static org.elasticsearch.xpack.core.ilm.LifecycleExecutionState.fromIndexMetadata; | ||
|
||
/** | ||
* Deletes the snapshot designated by the repository and snapshot name present in the lifecycle execution state. | ||
*/ | ||
public class CleanupSnapshotStep extends AsyncRetryDuringSnapshotActionStep { | ||
public static final String NAME = "cleanup-snapshot"; | ||
|
||
public CleanupSnapshotStep(StepKey key, StepKey nextStepKey, Client client) { | ||
super(key, nextStepKey, client); | ||
} | ||
|
||
@Override | ||
public boolean isRetryable() { | ||
return true; | ||
} | ||
|
||
@Override | ||
void performDuringNoSnapshot(IndexMetaData indexMetaData, ClusterState currentClusterState, Listener listener) { | ||
final String indexName = indexMetaData.getIndex().getName(); | ||
|
||
LifecycleExecutionState lifecycleState = fromIndexMetadata(indexMetaData); | ||
final String repositoryName = lifecycleState.getSnapshotRepository(); | ||
// if the snapshot information is missing from the ILM execution state there is nothing to delete so we move on | ||
if (Strings.hasText(repositoryName) == false) { | ||
listener.onResponse(true); | ||
return; | ||
} | ||
final String snapshotName = lifecycleState.getSnapshotName(); | ||
if (Strings.hasText(snapshotName) == false) { | ||
listener.onResponse(true); | ||
return; | ||
} | ||
DeleteSnapshotRequest deleteSnapshotRequest = new DeleteSnapshotRequest(repositoryName, snapshotName); | ||
getClient().admin().cluster().deleteSnapshot(deleteSnapshotRequest, new ActionListener<>() { | ||
|
||
@Override | ||
public void onResponse(AcknowledgedResponse acknowledgedResponse) { | ||
listener.onResponse(true); | ||
dakrone marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
@Override | ||
public void onFailure(Exception e) { | ||
if (e instanceof SnapshotMissingException) { | ||
dakrone marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// during the happy flow we generate a snapshot name and that snapshot doesn't exist in the repository | ||
listener.onResponse(true); | ||
} else { | ||
if (e instanceof RepositoryMissingException) { | ||
String policyName = indexMetaData.getSettings().get(LifecycleSettings.LIFECYCLE_NAME); | ||
listener.onFailure(new IllegalStateException("repository [" + repositoryName + "] is missing. [" + policyName + | ||
"] policy for index [" + indexName + "] cannot continue until the repository is created", e)); | ||
} else { | ||
listener.onFailure(e); | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
} |
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
112 changes: 112 additions & 0 deletions
112
x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CopySettingsStep.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,112 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
package org.elasticsearch.xpack.core.ilm; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.elasticsearch.cluster.ClusterState; | ||
import org.elasticsearch.cluster.metadata.IndexMetaData; | ||
import org.elasticsearch.cluster.metadata.MetaData; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.index.Index; | ||
|
||
import java.util.Locale; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Copy the provided settings from the source to the target index. | ||
* <p> | ||
* The target index is derived from the source index using the provided prefix. | ||
* This is useful for actions like shrink or searchable snapshot that create a new index and migrate the ILM execution from the source | ||
* to the target index. | ||
*/ | ||
public class CopySettingsStep extends ClusterStateActionStep { | ||
public static final String NAME = "copy-settings"; | ||
|
||
private static final Logger logger = LogManager.getLogger(CopySettingsStep.class); | ||
|
||
private final String[] settingsKeys; | ||
private final String indexPrefix; | ||
|
||
public CopySettingsStep(StepKey key, StepKey nextStepKey, String indexPrefix, String... settingsKeys) { | ||
super(key, nextStepKey); | ||
Objects.requireNonNull(indexPrefix); | ||
Objects.requireNonNull(settingsKeys); | ||
this.indexPrefix = indexPrefix; | ||
this.settingsKeys = settingsKeys; | ||
} | ||
|
||
@Override | ||
public boolean isRetryable() { | ||
return true; | ||
} | ||
|
||
public String[] getSettingsKeys() { | ||
return settingsKeys; | ||
} | ||
|
||
public String getIndexPrefix() { | ||
return indexPrefix; | ||
} | ||
|
||
@Override | ||
public ClusterState performAction(Index index, ClusterState clusterState) { | ||
String sourceIndexName = index.getName(); | ||
IndexMetaData sourceIndexMetadata = clusterState.metaData().index(sourceIndexName); | ||
String targetIndexName = indexPrefix + sourceIndexName; | ||
IndexMetaData targetIndexMetadata = clusterState.metaData().index(targetIndexName); | ||
|
||
if (sourceIndexMetadata == null) { | ||
// Index must have been since deleted, ignore it | ||
logger.debug("[{}] lifecycle action for index [{}] executed but index no longer exists", getKey().getAction(), sourceIndexName); | ||
return clusterState; | ||
} | ||
|
||
if (targetIndexMetadata == null) { | ||
String errorMessage = String.format(Locale.ROOT, "index [%s] is being referenced by ILM action [%s] on step [%s] but " + | ||
"it doesn't exist", targetIndexName, getKey().getAction(), getKey().getName()); | ||
logger.debug(errorMessage); | ||
throw new IllegalStateException(errorMessage); | ||
} | ||
|
||
if (settingsKeys == null || settingsKeys.length == 0) { | ||
return clusterState; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Super minor, but we can probably stick this before the |
||
|
||
Settings.Builder settings = Settings.builder().put(targetIndexMetadata.getSettings()); | ||
for (String key : settingsKeys) { | ||
String value = sourceIndexMetadata.getSettings().get(key); | ||
settings.put(key, value); | ||
} | ||
|
||
MetaData.Builder newMetaData = MetaData.builder(clusterState.getMetaData()) | ||
.put(IndexMetaData.builder(targetIndexMetadata) | ||
.settingsVersion(targetIndexMetadata.getSettingsVersion() + 1) | ||
.settings(settings)); | ||
return ClusterState.builder(clusterState).metaData(newMetaData).build(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
if (!super.equals(o)) { | ||
return false; | ||
} | ||
CopySettingsStep that = (CopySettingsStep) o; | ||
return Objects.equals(settingsKeys, that.settingsKeys) && | ||
Objects.equals(indexPrefix, that.indexPrefix); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(super.hashCode(), settingsKeys, indexPrefix); | ||
} | ||
} |
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.