Skip to content

Conversation

@martijnvg
Copy link
Member

When removing aliases allow that an alias action's index expression can match
both data streams and regular indices.

This allows api calls like DELETE /_all/_alias/my-alias, which can be common
in tear down / cleanup logic. In this case my-alias just points to regular
indices, but _all can be expanded to data streams too if exist. This can
then trigger validation logic that prevents adding aliases that refer to both
indices and data streams. However this api call never adds any alias, only
removes it. So failing with this validation error doesn't make much sense.

This change adjusts the validation logic so that: 'match with both data streams and
regular indices are disallowed' validation is only executed for alias actions
that add aliases.

Additionally with the change, a single alias remove action that spans across
indices and data stream aliases is allowed. For example DELETE /_all/_alias/*
will be allowed with this PR, which removes all aliases.

Relates to #66163

…dices.

When removing aliases allow that an alias action's index expression can match
both data streams and regular indices.

This allows api calls like `DELETE /_all/_alias/my-alias`, which can common
in tear down / cleanup logic. In this case `my-alias` just points to regular
indices, but `_all` can be expanded to data streams too if exist. This can
then trigger validation logic that prevents adding aliases that refer to both
indices and data streams. However this api call never adds any alias, only
removes it. So failing with this validation error doesn't make much sense.

This change adjusts the validation logic so that: 'match with both data streams and
regular indices are disallowed' validation is only executed for alias actions
that add aliases.

Relates to elastic#66163
@martijnvg martijnvg requested a review from danhermann June 22, 2021 08:57
@elasticmachine elasticmachine added the Team:Data Management Meta label for data/management team label Jun 22, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-features (Team:Core/Features)

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.

The main change here to allow deletion of both index and DS alias in the same call LGTM. I had two questions about the implementation that are not blocking.

}
}
break;
continue;
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the continue here do something different than the break would have done?

Copy link
Member Author

Choose a reason for hiding this comment

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

In this case data stream aliases are added, if break were to be used here, then this transport action could attempt adding indices aliases with the same name (which would then fail). A few lines below, at the end of the if statement a continue statement used to do what this continue statement is doing.

Comment on lines +144 to +150
if (nonBackingIndices.isEmpty() == false) {
// Regular aliases/indices match as well with the provided expression.
// (Only when adding new aliases, matching both data streams and indices is disallowed)
break;
} else {
continue;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't follow the logic here. Do the break and continue result in different outcomes depending on the value of nonBackingIndices.isEmpty()?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. The noneBackingIndices set contains the names of regular indices that match with this alias action. In that case, this transport action should attempt to remove indices aliases.

If the set is empty then the logic should stop here, because otherwise resolving to concrete indices that happens a bit later would fail. (since no regular indices would be resolved)

@danhermann
Copy link
Contributor

Thanks for the explanation. I see how it works now. I think it's a somewhat complicated interaction between the outer for loop, an inner switch statement for data stream aliases, and the code block after that for index aliases though it's not immediately clear to me that it could easily be simplified.

@martijnvg
Copy link
Member Author

and the code block after that for index aliases though it's not immediately clear to me that it could easily be simplified.

Yes, it is more complicated now. I think in a follow-up, I will start making this code unit testable and try to break this big method down in simpler units.

@martijnvg martijnvg merged commit 3f44a5b into elastic:master Jun 24, 2021
martijnvg added a commit to martijnvg/elasticsearch that referenced this pull request Jun 24, 2021
…dices. (elastic#74403)

When removing aliases allow that an alias action's index expression can match
both data streams and regular indices.

This allows api calls like `DELETE /_all/_alias/my-alias`, which can common
in tear down / cleanup logic. In this case `my-alias` just points to regular
indices, but `_all` can be expanded to data streams too if exist. This can
then trigger validation logic that prevents adding aliases that refer to both
indices and data streams. However this api call never adds any alias, only
removes it. So failing with this validation error doesn't make much sense.

This change adjusts the validation logic so that: 'match with both data streams and
regular indices are disallowed' validation is only executed for alias actions
that add aliases.

Relates to elastic#66163
martijnvg added a commit that referenced this pull request Jun 24, 2021
…dices. (#74543)

Backporting #74403 to 7.x branch.

When removing aliases allow that an alias action's index expression can match
both data streams and regular indices.

This allows api calls like `DELETE /_all/_alias/my-alias`, which can common
in tear down / cleanup logic. In this case `my-alias` just points to regular
indices, but `_all` can be expanded to data streams too if exist. This can
then trigger validation logic that prevents adding aliases that refer to both
indices and data streams. However this api call never adds any alias, only
removes it. So failing with this validation error doesn't make much sense.

This change adjusts the validation logic so that: 'match with both data streams and
regular indices are disallowed' validation is only executed for alias actions
that add aliases.

Relates to #66163
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Data Management/Data streams Data streams and their lifecycles >non-issue Team:Data Management Meta label for data/management team v7.14.0 v8.0.0-alpha1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants