-
Notifications
You must be signed in to change notification settings - Fork 25.2k
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
Fix corrupted Metadata from index and alias having the same name #91456
Conversation
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.
Pinging @elastic/es-distributed (Team:Distributed) |
Hi @original-brownbear, I've created a changelog YAML for you. |
…ion' into hunt-down-bug-alias-index-collision
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.
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"); |
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 we make this a strong message about "conflict":
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() { |
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.
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.
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.
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)); |
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.
WDYT about initializing indicesInAlias
in one go?
indicesInAlias = randomSubsetOf(randomIntBetween(1, 3), indices).stream()
.filter(e -> e.equals(alias) == false)
.collect(Collectors.toSet())
server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java
Outdated
Show resolved
Hide resolved
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.
LGTM! I've left a few small comments
Thanks both! |
💔 Backport failed
You can use sqren/backport to manually backport by running |
…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.
) (#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.
Follow up to elastic#91456 implementing an automated fix for indices corrupted in 8.5.
…elastic#91887) Follow up to elastic#91456 implementing an automated fix for indices corrupted in 8.5.
…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.
…elastic#91887) Follow up to elastic#91456 implementing an automated fix for indices corrupted in 8.5.
…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.
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 toIndexMetadata
to make it impossible to instantiate a brokenIndexMetadata
in the first place.