-
Notifications
You must be signed in to change notification settings - Fork 25k
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
Verify the index state of concrete indices after alias resolution #9057
Verify the index state of concrete indices after alias resolution #9057
Conversation
@@ -760,24 +760,44 @@ public String concreteSingleIndex(String indexOrAlias, IndicesOptions indicesOpt | |||
} | |||
// not an actual index, fetch from an alias | |||
String[] indices = aliasAndIndexToIndexMap.getOrDefault(aliasOrIndex, Strings.EMPTY_ARRAY); | |||
if (indices.length == 0 && !allowNoIndices) { | |||
if (indices.length == 0 && !failNoIndices) { |
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 think you should remove the !
here, throw exception if failNoIndices
is true
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.
Are we sure we wanna rename allowNoIndices
to failNoIndices
? Wondering if t becomes more error-prone than before :)
Left a couple of comments. I think the important bit here is to highlight that we didn't check indices state at all after expanding aliases. With this PR we are introducing an additional check that honours the |
So the process is: resolve aliases to indices, then do the closed/open check, then execute the operation. I think that, if the user has specified |
I tend to agree that this is the expected behaviour, wondering because aliases are different from wildcard expressions, meaning that users might not know they are using an alias, and depending on the state of the underlying indices we end up executing an action against different indices, although the same alias is provided. That said we have the |
} | ||
return indices; | ||
default: | ||
ObjectOpenHashSet<String> concreteIndices = ObjectOpenHashSet.from(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.
wondering if the other way around would be better: create a new array instead of set and add open indices to it from within the loop.
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.
ok, so a new array and only open indices are added to that from the loop?
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.
yes, that's what I was thinking, I'd maybe check state != CLOSE rather than checking for OPEN, but that's a super minor concern that doesn't change the result at this time
One more thing, let's discuss if this should be treated as a bug and pushed to 1.4. Before this fix, operations against aliases didn't check the indices state. Thus operations that can't be executed against closed indices (e.g. search) will return a cluster block all the time:
After the fix, depending on
Looking back this completes what we did in #6475 and #6990 and makes the behaviour consistent when using aliases as well. As for backwards compatibility, we would just return a better error (http response code stays the same) for operations that don't ignore unavailable indices, and we honour the ignore_unavailable option. I'm leaning towards treating it as a bugfix and push it to 1.4 too, the previous behaviour is a bug. |
@@ -760,24 +760,49 @@ public String concreteSingleIndex(String indexOrAlias, IndicesOptions indicesOpt | |||
} | |||
// not an actual index, fetch from an alias | |||
String[] indices = aliasAndIndexToIndexMap.getOrDefault(aliasOrIndex, Strings.EMPTY_ARRAY); | |||
if (indices.length == 0 && !allowNoIndices) { | |||
if (indices.length == 0 && failNoIndices) { |
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.
thinking... in javadocs and probably es docs as well, we always refer to allowNoIndices
and ignore_unavailable
as options that affect how wildcard expansion works. But those options also affects how aliases expansion to concrete indices work. I think we should double check docs and update it.
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 you double check the javadocs and es docs around indices options? Those options affect now not only how wildcards get expanded, but also how aliases get resolved to concrete indices.
Ok, lets also push it to 1.4 branch for the reasons you mentioned. I think that:
message is good enough and consistent to when a concrete index is closed. We just need to mention the alias name. |
} | ||
} else if (indexMetaData.getState() == IndexMetaData.State.OPEN) { | ||
concreteIndices.add(index); | ||
} |
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.
nitpicking: maybe add an else that throws exception (index state not supported?)
Hey @martijnvg I left a couple of comments around docs and the returned error message, if you can address those then this is ready to be merged ;) |
4c7427b
to
5a46b67
Compare
@javanna I've updated the PR. |
if (indexMetaData != null) { | ||
if (indexMetaData.getState() == IndexMetaData.State.CLOSE) { | ||
if (failClosed) { | ||
throw new IndexClosedException(new Index(aliasOrIndex)); |
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.
name needs to be replaced here...that is why I don't like these optimizations :) they make the code error-prone ;)
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.
argg... i'll change it :)
LGTM |
…osed and deal with this according to IndicesOptions. Closes elastic#9057
580b802
to
dedaf93
Compare
…osed and deal with this according to IndicesOptions. Closes #9057
…osed and deal with this according to IndicesOptions. Closes #9057
…osed and deal with this according to IndicesOptions. Closes elastic#9057
No description provided.