Skip to content

Fix corrupted Metadata from index and alias having the same name #91456

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

Conversation

original-brownbear
Copy link
Contributor

This fixes a bug introduced in #87863 which added a Metadata copy constructor with separate name collision checks that assumed index name and alias names were already validated in IndexMetada. => fixed corrupted states by actually adding the validation to IndexMetadata to make it impossible to instantiate a broken IndexMetadata in the first place.

This fixes a bug introduced in elastic#87863
which added a Metadata copy constructor with separate name collision checks that
assumed index name and alias names were already validated in `IndexMetada`.
=> fixed corrupted states by actually adding the validation to `IndexMetadata`
to make it impossible to instantiate a broken `IndexMetadata` in the first place.
@original-brownbear original-brownbear added >bug :Distributed Coordination/Cluster Coordination Cluster formation and cluster state publication, including cluster membership and fault detection. v8.5.1 v8.6.0 labels Nov 9, 2022
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-distributed (Team:Distributed)

@elasticsearchmachine
Copy link
Collaborator

Hi @original-brownbear, I've created a changelog YAML for you.

@elasticsearchmachine elasticsearchmachine added the Team:Distributed (Obsolete) Meta label for distributed team (obsolete). Replaced by Distributed Indexing/Coordination. label Nov 9, 2022
@arteam arteam self-requested a review November 9, 2022 13:25
Copy link
Contributor

@henningandersen henningandersen left a comment

Choose a reason for hiding this comment

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

LGTM.

var aliasesMap = aliases.build();
aliasesMap.forEach((key, value) -> {
if (value.alias().equals(index)) {
throw new IllegalArgumentException("alias name [" + index + "] and index name may not be the same");
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make this a strong message about "conflict":

Suggested change
throw new IllegalArgumentException("alias name [" + index + "] and index name may not be the same");
throw new IllegalArgumentException("alias name [" + index + "] self-conflicts with index name");

@@ -193,26 +193,6 @@ public void testFindAliasWithExclusionAndOverride() {
assertThat(aliases.get(1).alias(), equalTo("bb"));
}

public void testIndexAndAliasWithSameName() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I was trying to find a case where we'd build IndexMetadata instances that temporarily breaks this. The one case I could think of was the aliases action where we can add and remove aliases/indices. AFAICS, it does try to do things in order. I think this is OK, but wanted to mention in case you have a case yourself you also want to check.

Obviously we should have tests failling then, but this is pretty old so might not necessarily be covered well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea I checked for that and at least couldn't find any broken spots (all of the spots that may throw seem to have safe listeners). If anything this should at least cause a better exception here and there.

aliasToIndices.put(alias, new HashSet<>(randomSubsetOf(randomIntBetween(1, 3), indices)));
Set<String> indicesInAlias;
do {
indicesInAlias = new HashSet<>(randomSubsetOf(randomIntBetween(1, 3), indices));
Copy link
Contributor

Choose a reason for hiding this comment

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

WDYT about initializing indicesInAlias in one go?

indicesInAlias = randomSubsetOf(randomIntBetween(1, 3), indices).stream()
                    .filter(e -> e.equals(alias) == false)
                    .collect(Collectors.toSet())

Copy link
Contributor

@arteam arteam left a comment

Choose a reason for hiding this comment

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

LGTM! I've left a few small comments

@original-brownbear
Copy link
Contributor Author

Thanks both!

@original-brownbear original-brownbear merged commit a867ba1 into elastic:main Nov 9, 2022
@original-brownbear original-brownbear deleted the hunt-down-bug-alias-index-collision branch November 9, 2022 15:12
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
8.5 Commit could not be cherrypicked due to conflicts

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 91456

original-brownbear added a commit to original-brownbear/elasticsearch that referenced this pull request Nov 9, 2022
…stic#91456)

This fixes a bug introduced in elastic#87863
which added a Metadata copy constructor with separate name collision checks that
assumed index name and alias names were already validated in `IndexMetada`.
=> fixed corrupted states by actually adding the validation to `IndexMetadata`
to make it impossible to instantiate a broken `IndexMetadata` in the first place.
elasticsearchmachine pushed a commit that referenced this pull request Nov 9, 2022
) (#91469)

This fixes a bug introduced in #87863
which added a Metadata copy constructor with separate name collision checks that
assumed index name and alias names were already validated in `IndexMetada`.
=> fixed corrupted states by actually adding the validation to `IndexMetadata`
to make it impossible to instantiate a broken `IndexMetadata` in the first place.
original-brownbear added a commit to original-brownbear/elasticsearch that referenced this pull request Nov 24, 2022
Follow up to elastic#91456 implementing an automated fix for indices corrupted in 8.5.
original-brownbear added a commit that referenced this pull request Nov 29, 2022
…#91887)

Follow up to #91456 implementing an automated fix for indices corrupted in 8.5.
original-brownbear added a commit to original-brownbear/elasticsearch that referenced this pull request Nov 29, 2022
…elastic#91887)

Follow up to elastic#91456 implementing an automated fix for indices corrupted in 8.5.
elasticsearchmachine pushed a commit that referenced this pull request Nov 29, 2022
…#91887) (#91988)

Follow up to #91456 implementing an automated fix for indices corrupted in 8.5.
original-brownbear added a commit to original-brownbear/elasticsearch that referenced this pull request Nov 29, 2022
…stic#91456)

This fixes a bug introduced in elastic#87863
which added a Metadata copy constructor with separate name collision checks that
assumed index name and alias names were already validated in `IndexMetada`.
=> fixed corrupted states by actually adding the validation to `IndexMetadata`
to make it impossible to instantiate a broken `IndexMetadata` in the first place.
original-brownbear added a commit to original-brownbear/elasticsearch that referenced this pull request Nov 29, 2022
…elastic#91887)

Follow up to elastic#91456 implementing an automated fix for indices corrupted in 8.5.
original-brownbear added a commit that referenced this pull request Nov 29, 2022
…es bug (#91993)

* Fix corrupted Metadata from index and alias having the same name (#91456)

This fixes a bug introduced in #87863
which added a Metadata copy constructor with separate name collision checks that
assumed index name and alias names were already validated in `IndexMetada`.
=> fixed corrupted states by actually adding the validation to `IndexMetadata`
to make it impossible to instantiate a broken `IndexMetadata` in the first place.

* Implement repair functionality for aliases colliding with indices bug (#91887)

Follow up to #91456 implementing an automated fix for indices corrupted in 8.5.
DaveCTurner added a commit to DaveCTurner/elasticsearch that referenced this pull request Dec 12, 2022
DaveCTurner added a commit that referenced this pull request Dec 12, 2022
DaveCTurner added a commit that referenced this pull request Dec 12, 2022
DaveCTurner added a commit that referenced this pull request Dec 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Distributed Coordination/Cluster Coordination Cluster formation and cluster state publication, including cluster membership and fault detection. Team:Distributed (Obsolete) Meta label for distributed team (obsolete). Replaced by Distributed Indexing/Coordination. v8.5.1 v8.6.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants