-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Make the TransportRolloverAction execute in one cluster state update #50388
Merged
andreidan
merged 6 commits into
elastic:master
from
andreidan:ilm-retryable-rollover-step
Dec 20, 2019
+81
−99
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
682f0d7
ILM: Make the rollover step retryable.
andreidan 156b556
Rename innerExecute to applyAliasActions
andreidan aba5acd
Add the rollover index names in cluster update task name
andreidan d899a10
Guard active shards observer by newState != oldState
andreidan 78aca58
RolloverStep is not retryable
andreidan 71f8c43
Merge branch 'master' into ilm-retryable-rollover-step
elasticmachine 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 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 |
---|---|---|
|
@@ -20,7 +20,6 @@ | |
package org.elasticsearch.action.admin.indices.rollover; | ||
|
||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesClusterStateUpdateRequest; | ||
import org.elasticsearch.action.admin.indices.create.CreateIndexClusterStateUpdateRequest; | ||
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; | ||
import org.elasticsearch.action.admin.indices.stats.IndicesStatsAction; | ||
|
@@ -130,7 +129,7 @@ protected void masterOperation(Task task, final RolloverRequest rolloverRequest, | |
.docs(true); | ||
statsRequest.setParentTask(clusterService.localNode().getId(), task.getId()); | ||
client.execute(IndicesStatsAction.INSTANCE, statsRequest, | ||
new ActionListener<IndicesStatsResponse>() { | ||
new ActionListener<>() { | ||
@Override | ||
public void onResponse(IndicesStatsResponse statsResponse) { | ||
final Map<String, Boolean> conditionResults = evaluateConditions(rolloverRequest.getConditions().values(), | ||
|
@@ -141,56 +140,41 @@ public void onResponse(IndicesStatsResponse statsResponse) { | |
new RolloverResponse(sourceIndexName, rolloverIndexName, conditionResults, true, false, false, false)); | ||
return; | ||
} | ||
List<Condition<?>> metConditions = rolloverRequest.getConditions().values().stream() | ||
List<Condition<?>> metConditions = rolloverRequest.getConditions().values().stream() | ||
.filter(condition -> conditionResults.get(condition.toString())).collect(Collectors.toList()); | ||
if (conditionResults.size() == 0 || metConditions.size() > 0) { | ||
CreateIndexClusterStateUpdateRequest updateRequest = prepareCreateIndexRequest(unresolvedName, rolloverIndexName, | ||
rolloverRequest); | ||
createIndexService.createIndex(updateRequest, ActionListener.wrap(createIndexClusterStateUpdateResponse -> { | ||
final IndicesAliasesClusterStateUpdateRequest aliasesUpdateRequest; | ||
if (explicitWriteIndex) { | ||
aliasesUpdateRequest = prepareRolloverAliasesWriteIndexUpdateRequest(sourceIndexName, | ||
rolloverIndexName, rolloverRequest); | ||
} else { | ||
aliasesUpdateRequest = prepareRolloverAliasesUpdateRequest(sourceIndexName, | ||
rolloverIndexName, rolloverRequest); | ||
CreateIndexClusterStateUpdateRequest createIndexRequest = prepareCreateIndexRequest(unresolvedName, | ||
rolloverIndexName, rolloverRequest); | ||
clusterService.submitStateUpdateTask("rollover_index", new ClusterStateUpdateTask() { | ||
@Override | ||
public ClusterState execute(ClusterState currentState) throws Exception { | ||
ClusterState newState = createIndexService.applyCreateIndexRequest(currentState, createIndexRequest); | ||
newState = indexAliasesService.applyAliasActions(newState, | ||
rolloverAliasToNewIndex(sourceIndexName, rolloverIndexName, rolloverRequest, explicitWriteIndex)); | ||
RolloverInfo rolloverInfo = new RolloverInfo(rolloverRequest.getAlias(), metConditions, | ||
threadPool.absoluteTimeInMillis()); | ||
return ClusterState.builder(newState) | ||
.metaData(MetaData.builder(newState.metaData()) | ||
.put(IndexMetaData.builder(newState.metaData().index(sourceIndexName)) | ||
.putRolloverInfo(rolloverInfo))).build(); | ||
} | ||
indexAliasesService.indicesAliases(aliasesUpdateRequest, | ||
ActionListener.wrap(aliasClusterStateUpdateResponse -> { | ||
if (aliasClusterStateUpdateResponse.isAcknowledged()) { | ||
clusterService.submitStateUpdateTask("update_rollover_info", new ClusterStateUpdateTask() { | ||
@Override | ||
public ClusterState execute(ClusterState currentState) { | ||
RolloverInfo rolloverInfo = new RolloverInfo(rolloverRequest.getAlias(), metConditions, | ||
threadPool.absoluteTimeInMillis()); | ||
return ClusterState.builder(currentState) | ||
.metaData(MetaData.builder(currentState.metaData()) | ||
.put(IndexMetaData.builder(currentState.metaData().index(sourceIndexName)) | ||
.putRolloverInfo(rolloverInfo))).build(); | ||
} | ||
|
||
@Override | ||
public void onFailure(String source, Exception e) { | ||
listener.onFailure(e); | ||
} | ||
@Override | ||
public void onFailure(String source, Exception e) { | ||
listener.onFailure(e); | ||
} | ||
|
||
@Override | ||
public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) { | ||
activeShardsObserver.waitForActiveShards(new String[]{rolloverIndexName}, | ||
rolloverRequest.getCreateIndexRequest().waitForActiveShards(), | ||
rolloverRequest.masterNodeTimeout(), | ||
isShardsAcknowledged -> listener.onResponse(new RolloverResponse( | ||
sourceIndexName, rolloverIndexName, conditionResults, false, true, true, | ||
isShardsAcknowledged)), | ||
listener::onFailure); | ||
} | ||
}); | ||
} else { | ||
listener.onResponse(new RolloverResponse(sourceIndexName, rolloverIndexName, conditionResults, | ||
false, true, false, false)); | ||
} | ||
}, listener::onFailure)); | ||
}, listener::onFailure)); | ||
@Override | ||
public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) { | ||
activeShardsObserver.waitForActiveShards(new String[]{rolloverIndexName}, | ||
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. I don't expect it to happen (it would be a bad situation if it did), but it might be a good idea to wrap this in: if (newState.equals(oldState) == false) {
...
} |
||
rolloverRequest.getCreateIndexRequest().waitForActiveShards(), | ||
rolloverRequest.masterNodeTimeout(), | ||
isShardsAcknowledged -> listener.onResponse(new RolloverResponse( | ||
sourceIndexName, rolloverIndexName, conditionResults, false, true, true, | ||
isShardsAcknowledged)), | ||
listener::onFailure); | ||
} | ||
}); | ||
} else { | ||
// conditions not met | ||
listener.onResponse( | ||
|
@@ -207,27 +191,24 @@ public void onFailure(Exception e) { | |
); | ||
} | ||
|
||
static IndicesAliasesClusterStateUpdateRequest prepareRolloverAliasesUpdateRequest(String oldIndex, String newIndex, | ||
RolloverRequest request) { | ||
final List<AliasAction> actions = List.of( | ||
new AliasAction.Add(newIndex, request.getAlias(), null, null, null, null), | ||
new AliasAction.Remove(oldIndex, request.getAlias())); | ||
return new IndicesAliasesClusterStateUpdateRequest(actions) | ||
.ackTimeout(request.ackTimeout()) | ||
.masterNodeTimeout(request.masterNodeTimeout()); | ||
} | ||
|
||
static IndicesAliasesClusterStateUpdateRequest prepareRolloverAliasesWriteIndexUpdateRequest(String oldIndex, String newIndex, | ||
RolloverRequest request) { | ||
final List<AliasAction> actions = List.of( | ||
/** | ||
* Creates the alias actions to reflect the alias rollover from the old (source) index to the new (target/rolled over) index. An | ||
* alias pointing to multiple indices will have to be an explicit write index (ie. the old index alias has is_write_index set to true) | ||
* in which case, after the rollover, the new index will need to be the explicit write index. | ||
*/ | ||
static List<AliasAction> rolloverAliasToNewIndex(String oldIndex, String newIndex, RolloverRequest request, | ||
boolean explicitWriteIndex) { | ||
if (explicitWriteIndex) { | ||
return List.of( | ||
new AliasAction.Add(newIndex, request.getAlias(), null, null, null, true), | ||
new AliasAction.Add(oldIndex, request.getAlias(), null, null, null, false)); | ||
return new IndicesAliasesClusterStateUpdateRequest(actions) | ||
.ackTimeout(request.ackTimeout()) | ||
.masterNodeTimeout(request.masterNodeTimeout()); | ||
} else { | ||
return List.of( | ||
new AliasAction.Add(newIndex, request.getAlias(), null, null, null, null), | ||
new AliasAction.Remove(oldIndex, request.getAlias())); | ||
} | ||
} | ||
|
||
|
||
static String generateRolloverIndexName(String sourceIndexName, IndexNameExpressionResolver indexNameExpressionResolver) { | ||
String resolvedName = indexNameExpressionResolver.resolveDateMathExpression(sourceIndexName); | ||
final boolean isDateMath = sourceIndexName.equals(resolvedName) == false; | ||
|
This file contains 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 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 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.
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.
Can you add the index name into the task string?