-
Notifications
You must be signed in to change notification settings - Fork 24.2k
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
Remove expansion of empty index arguments in RoutingTable #10148
Conversation
RoutingTables activePrimaryShardsGrouped(), allActiveShardsGrouped() and allAssignedShardsGrouped() methods treated empty index array input parameters as meaning "all" indices and expanded to the routing maps keyset. However, the expansion of index names is now already done in MetaData#concreteIndices(). Returning an empty index name list here when a wildcard pattern didn't match any index name could lead to problems like elastic#9081 because the RoutingTable still expanded this list of names to "_all". In case of e.g. the recovery endpoint this could lead to problems. This fix removes the index name expansion in RoutingTable and introduces some more checks for preventing NPEs in MetaData#concreteIndices(). Closes elastic#9081
@@ -1,9 +1,6 @@ | |||
--- | |||
"Indices recovery test": | |||
|
|||
- skip: | |||
features: gtelte | |||
|
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.
if you rebase this change should go away right?
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, I deleted that on master already. Should also maybe delete the gtelte on 1.x branch?
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 I think so, should be done on 1.x too
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.
done
I like the change! Left a bunch of comments |
I adressed your comments, will revert the changes in IndicesRequestTests and create rest tests for that later. Let me know if my other replies make sense. |
@javanna pushed a couple of changes regarding your comments. For one, I reverted the changes to IndicesRequestTests and introduced rest tests for these cases. Other changes address your comments to code style mostly. Let me know what you think. |
* test resolving _all pattern (null, empty arry or "_all") for random IndicesOptions | ||
*/ | ||
@Test | ||
public void concreteIndicesAllpatternRandom() { |
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.
concreteIndicesAllpatternRandom=>concreteIndicesAllPatternRandom
Hi @cbuescher I did another review round. it's close. I am not sure if we should rely solely on REST tests to test the |
@javanna I adressed two of your comments and started adding a RoutingTable unit test, but it's still a very rudimentary test. One thing I'm currently not sure about is how to set up the RoutingTable for the test so that the shard routings that are created are in a different state than "unassigned". When I figured that out I will extend the test. Any suggestion on how to do that in a simple unit test way are. |
assertThat(concreteIndices, notNullValue()); | ||
int expectedNumberOfIndices = 0; | ||
if (indicesOptions.expandWildcardsOpen()) | ||
expectedNumberOfIndices += 2; |
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.
brackets please
*/ | ||
@Test | ||
public void concreteIndicesWildcardEmptyRandom() { | ||
for (int i = 0; i < 100; i++) { |
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 we really need to repeat this 100 times. Seems a little too high, wouldn't 10 be enough? Or even just rely on the fact that tests run continously. An alternative would be to use the @Repeat
annotation instead of the loop. What do you think?
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.
Sure, will decrease that
Thanks for the update @cbuescher I had another look, looks good. You are on the right track with the |
Added changes according to latest review comments and extended RoutingTableTest so it covers moving through different ShardRoutingStates now. |
} | ||
|
||
@Test | ||
public void testIsExplicitAllIndices_wildcard() throws Exception { | ||
MetaData metaData = MetaData.builder().build(); | ||
assertThat(metaData.isExplicitAllPattern(new String[]{"*"}), equalTo(false)); | ||
assertThat(MetaData.isExplicitAllPattern(new String[]{"*"}), equalTo(false)); |
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.
if you get merge conflicts on these MetaData calls that should have been static, don't worry, I think I recently merged a PR from a contributor that fixed just that.
Had another look, left a bunch of super minor comments, this is very close. |
I left the two exception types in MetaData.concreteIndices() but extended the test to check for throwing the correcty type. Can also make both IndexMissingExceptions, but that one wants the name of the missing index and it realy is more like a call to the function with mismatch in arguments. I hope its okay to give the IndicesOptions a simple toString() to see whats going on in case of an exception. |
|
||
if (aliasesOrIndices == null || aliasesOrIndices.length == 0) { | ||
if (!indicesOptions.allowNoIndices()) { | ||
throw new ElasticsearchIllegalArgumentException("Null or zero length argument for list of index or alias names " |
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.
we throw IndexMissingException
all the time when allowNoIndices
is set to true. I don't think we should act differently here.
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.
but now that I read your comment below, I see why it makes sense. Fine with illegal argument, I would only change the message to something like "no indices were specified but wildcard expansion is disabled" , shorter and more user oriented, what do you think?
We agreed on pulling the changes in MetaData and MetaDataTests out into a separate PR. Will open that soon. This PR now should only remove the expansion of empty or null index name lists in RoutingTable. |
…Data Prevents a current edge case resolving concrete aliases or index names in cluster MetaData that could potentialy lead to NullPointerException when the IndicesOptions don't allow wildcard expansion and the method is called with aliasesOrIndices argument null or emtpy list. This change adds a check for that and introduces randomized test that catches this. Closes #10342 Closes #10339
LGTM @cbuescher thanks |
RoutingTables activePrimaryShardsGrouped(), allActiveShardsGrouped() and allAssignedShardsGrouped() methods treated empty index array input parameters as meaning "all" indices and expanded to the routing maps keyset. However, the expansion of index names is now already done in MetaData#concreteIndices(). Returning an empty index name list here when a wildcard pattern didn't match any index name could lead to problems like #9081 because the RoutingTable still expanded this list of names to "_all". In case of e.g. the recovery endpoint this could lead to problems. Closes #9081 Closes #10148
RoutingTables activePrimaryShardsGrouped(), allActiveShardsGrouped() and
allAssignedShardsGrouped() methods treated empty index array input
parameters as meaning "all" indices and expanded to the routing maps
keyset. However, the expansion of index names is now already done in
MetaData#concreteIndices(). Returning an empty index name list here
when a wildcard pattern didn't match any index name could lead to
problems like #9081 because the RoutingTable still expanded this
list of names to "_all". In case of e.g. the recovery endpoint this
could lead to problems.
This fix removes the index name expansion in RoutingTable and introduces
some more checks for preventing NPEs in MetaData#concreteIndices().
Closes #9081