Skip to content

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

Merged
original-brownbear merged 5 commits intoelastic:mainfrom
original-brownbear:hunt-down-bug-alias-index-collision
Nov 9, 2022
Merged

Fix corrupted Metadata from index and alias having the same name#91456
original-brownbear merged 5 commits intoelastic:mainfrom
original-brownbear:hunt-down-bug-alias-index-collision

Conversation

@original-brownbear
Copy link
Copy Markdown
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 #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/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
Copy Markdown
Collaborator

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

@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

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

@elasticsearchmachine elasticsearchmachine added the Team:Distributed Meta label for distributed team. label Nov 9, 2022
@arteam arteam self-requested a review November 9, 2022 13:25
Copy link
Copy Markdown
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
Copy Markdown
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");

assertThat(aliases.get(1).alias(), equalTo("bb"));
}

public void testIndexAndAliasWithSameName() {
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

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 that referenced this pull request Nov 29, 2022
…#91887)

Follow up to #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 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>bug :Distributed/Cluster Coordination Cluster formation and cluster state publication, including cluster membership and fault detection. Team:Distributed Meta label for distributed team. v8.5.1 v8.6.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants