Skip to content
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

ILM: add support for rolling over data streams #57295

Merged
merged 10 commits into from
Jun 2, 2020

Conversation

andreidan
Copy link
Contributor

As the datastream information is stored in the ClusterState.Metadata we exposed
the Metadata to the AsyncWaitStep#evaluateCondition method in order for
the steps to be able to identify when a managed index is part of a DataStream.

If a managed index is part of a DataStream the rollover target is the DataStream
name and the highest generation index is the write index (ie. the rolled index).

Relates to #53488
Relates to #53100

andreidan added 3 commits May 28, 2020 14:53
As the datastream information is stored in the `ClusterState.Metadata` we exposed
the `Metadata` to the `AsyncWaitStep#evaluateCondition` method in order for
the steps to be able to identify when a managed index is part of a DataStream.

If a managed index is part of a DataStream the rollover target is the DataStream
name and the highest generation index is the write index (ie. the rolled index).
@andreidan andreidan added :Data Management/ILM+SLM Index and Snapshot lifecycle management v8.0.0 v7.9.0 labels May 28, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-features (:Core/Features/ILM+SLM)

@elasticmachine elasticmachine added the Team:Data Management Meta label for data/management team label May 28, 2020
Comment on lines 72 to 73
DataStream dataStream = indexAbstraction.getParentDataStream().getDataStream();
rolledIndexName = DataStream.getBackingIndexName(dataStream.getName(), dataStream.getGeneration());
Copy link
Contributor

@danhermann danhermann May 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: this correctly identifies the data stream's write index under the current implementation of data streams. The IndexAbstraction::getWriteIndex method will always return the correct write index in the event that we change the logic around backing index names, generations, etc., and would slightly simplify the code above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion, Dan. Pushed a fix to change this.

@andreidan andreidan requested a review from dakrone May 28, 2020 15:53
Copy link
Member

@dakrone dakrone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some comments on this, thanks Andrei!

@@ -29,7 +30,7 @@ protected Client getClient() {
return client;
}

public abstract void evaluateCondition(IndexMetadata indexMetadata, Listener listener, TimeValue masterTimeout);
public abstract void evaluateCondition(Metadata metadata, IndexMetadata indexMetadata, Listener listener, TimeValue masterTimeout);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does seem strange to pass both the Metadata and the IndexMetadata, should we instead pass Metadata and Index so it's easy to look up the index metadata?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, fair enough, it felt a bit odd to me too (it equally felt wasteful, in terms of CPU cycles, to re-do the lookup every time though, but given ILM is not so much about low latency I agree it makes sense to change it)

listener.onResponse(true);
return;
}
IndexAbstraction indexAbstraction = currentClusterState.metadata().getIndicesLookup().get(indexMetadata.getIndex().getName());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super minor, but can you add an

assert indexAbstraction != null : "expected the index " + indexName + " to exist in the lookup but it didn't";

after this line? I don't think it's going to happen, but we should check it regardless. Optionally, we could make it a real error also (throw an IllegalStateException)

IndexAbstraction indexAbstraction = currentClusterState.metadata().getIndicesLookup().get(indexMetadata.getIndex().getName());
final String rolloverTarget;
if (indexAbstraction.getParentDataStream() != null) {
rolloverTarget = indexAbstraction.getParentDataStream().getDataStream().getName();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be super paranoid, I think we should handle the case where getDataStream() returns null

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that can be changed to:

rolloverTarget = indexAbstraction.getParentDataStream().getName();

to eliminate the need for another null check.

Comment on lines 48 to 53
boolean indexingComplete = LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE_SETTING.get(indexMetadata.getSettings());
if (indexingComplete) {
logger.trace(indexMetadata.getIndex() + " has lifecycle complete set, skipping " + RolloverStep.NAME);
listener.onResponse(true);
return;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we allow this indexing complete setting regardless of whether the parent data stream exists or not? (in otherwords, moving it before the if (indexAbstraction.getParentDataStream() != null) { check)

}
if (Strings.isNullOrEmpty(rolloverAlias)) {
listener.onFailure(new IllegalArgumentException(String.format(Locale.ROOT,
"setting [%s] for index [%s] is empty or not defined", RolloverAction.LIFECYCLE_ROLLOVER_ALIAS,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a chance we can improve this error message (if you agree), maybe something like:

setting [index.lifecycle.rollover_alias] for index [foo-1] is not defined, it must be set to the name of the alias pointing to the group of indices being rolled over

I'm not stuck on the wording, maybe you have a better idea?

Copy link
Contributor Author

@andreidan andreidan May 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great point, I think the wording sounds good

IndexAbstraction indexAbstraction = currentState.metadata().getIndicesLookup().get(index.getName());
final String rolloverTarget;
if (indexAbstraction.getParentDataStream() != null) {
rolloverTarget = indexAbstraction.getParentDataStream().getDataStream().getName();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here about null check for the getDataStream(), I also wonder if maybe we should make this a nice static helper like IndexAbstraction.streamNameOrNull(indexAbstraction)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The underlying dataStream is non-nullable though. The getName method that Dan recommended emphasis this so replaced it here as well. Happy to discuss if there are any situations where this could be null though (in which case I believe more null checks are needed in IndexAbstraction.DataStream)

IndexMetadata aliasWriteIndex = aliasAbstraction.getWriteIndex();
if (aliasWriteIndex != null) {
rolledIndexName = aliasWriteIndex.getIndex().getName();
waitForActiveShardsSettingValue = aliasWriteIndex.getSettings().get("index.write.wait_for_active_shards");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super minor, but can we use IndexMetadata.SETTING_WAIT_FOR_ACTIVE_SHARDS instead of hardcoding here?

return getErrorResultOnNullMetadata(index);
}
rolledIndexName = rolledIndexMeta.getIndex().getName();
waitForActiveShardsSettingValue = rolledIndexMeta.getSettings().get("index.write.wait_for_active_shards");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here about using IndexMetadata.SETTING_WAIT_FOR_ACTIVE_SHARDS

@@ -114,6 +124,16 @@ public Result isConditionMet(Index index, ClusterState clusterState) {
return new Result(enoughShardsActive, new ActiveShardsInfo(currentActiveShards, activeShardCount.toString(), enoughShardsActive));
}

private Result getErrorResultOnNullMetadata(Index originalIndex) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be static I think

assert indexAbstraction != null : "invalid cluster metadata. index [" + indexMetadata.getIndex().getName() + "] was not found";
final String rolloverTarget;
if (indexAbstraction.getParentDataStream() != null) {
rolloverTarget = indexAbstraction.getParentDataStream().getDataStream().getName();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here about null check or a helper for retrieving the name :)

@andreidan andreidan requested review from dakrone and danhermann May 29, 2020 12:45
@andreidan
Copy link
Contributor Author

Dan, Lee, thanks for the review. I believe I've addressed all your suggestions

Copy link
Contributor

@danhermann danhermann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks, @andreidan!

@cjcenizal
Copy link
Contributor

Just wanted to note that the docs also need to be updated: https://www.elastic.co/guide/en/elasticsearch/reference/current/getting-started-index-lifecycle-management.html.

Copy link
Member

@dakrone dakrone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks Andrei!

@andreidan
Copy link
Contributor Author

@cjcenizal thanks for the heads up, we'll update the docs in an upcoming PR

@andreidan andreidan merged commit 6b410df into elastic:master Jun 2, 2020
andreidan added a commit to andreidan/elasticsearch that referenced this pull request Jun 2, 2020
As the datastream information is stored in the `ClusterState.Metadata` we exposed
the `Metadata` to the `AsyncWaitStep#evaluateCondition` method in order for
the steps to be able to identify when a managed index is part of a DataStream.

If a managed index is part of a DataStream the rollover target is the DataStream
name and the highest generation index is the write index (ie. the rolled index).

(cherry picked from commit 6b410df)
Signed-off-by: Andrei Dan <andrei.dan@elastic.co>
andreidan added a commit that referenced this pull request Jun 2, 2020
As the datastream information is stored in the `ClusterState.Metadata` we exposed
the `Metadata` to the `AsyncWaitStep#evaluateCondition` method in order for
the steps to be able to identify when a managed index is part of a DataStream.

If a managed index is part of a DataStream the rollover target is the DataStream
name and the highest generation index is the write index (ie. the rolled index).

(cherry picked from commit 6b410df)
Signed-off-by: Andrei Dan <andrei.dan@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Data Management/ILM+SLM Index and Snapshot lifecycle management >enhancement Team:Data Management Meta label for data/management team v7.9.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants