Fix corrupted Metadata from index and alias having the same name#91456
Fix corrupted Metadata from index and alias having the same name#91456original-brownbear merged 5 commits intoelastic:mainfrom original-brownbear:hunt-down-bug-alias-index-collision
Conversation
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.
|
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
| 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.
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"); |
| assertThat(aliases.get(1).alias(), equalTo("bb")); | ||
| } | ||
|
|
||
| public void testIndexAndAliasWithSameName() { |
There was a problem hiding this comment.
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.
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.
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
arteam
left a comment
There was a problem hiding this comment.
LGTM! I've left a few small comments
|
Thanks both! |
💔 Backport failed
You can use sqren/backport to manually backport by running |
) (#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.
…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 toIndexMetadatato make it impossible to instantiate a brokenIndexMetadatain the first place.