Skip to content
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

Closed
wants to merge 10 commits into from

Conversation

cbuescher
Copy link
Member

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

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
@cbuescher cbuescher added >bug v2.0.0-beta1 :Data Management/Indices APIs APIs to create and manage indices and templates v1.6.0 review labels Mar 18, 2015
@@ -1,9 +1,6 @@
---
"Indices recovery test":

- skip:
features: gtelte

Copy link
Member

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?

Copy link
Member Author

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?

Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@javanna
Copy link
Member

javanna commented Mar 19, 2015

I like the change! Left a bunch of comments

@cbuescher
Copy link
Member Author

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.

@cbuescher
Copy link
Member Author

@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() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

concreteIndicesAllpatternRandom=>concreteIndicesAllPatternRandom

@javanna
Copy link
Member

javanna commented Mar 20, 2015

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 RoutingTable changes. REST tests are great but I would love to have java unit tests around them. The tests that you previously added to IndicesRequestTests were not bad, just in the wrong place. Also, I wondered if we could move them to a more isolated unit tests instead of having to send requests and read responses to find out how many shards were touched. Replacing with REST tests makes tests even less isolated, makes sense?

@javanna javanna self-assigned this Mar 20, 2015
@cbuescher
Copy link
Member Author

@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;
Copy link
Member

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++) {
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will decrease that

@javanna
Copy link
Member

javanna commented Mar 23, 2015

Thanks for the update @cbuescher I had another look, looks good. You are on the right track with the RoutingTable test, looks great.

@cbuescher
Copy link
Member Author

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));
Copy link
Member

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.

@javanna
Copy link
Member

javanna commented Mar 30, 2015

Had another look, left a bunch of super minor comments, this is very close.

@cbuescher
Copy link
Member Author

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 "
Copy link
Member

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.

Copy link
Member

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?

@cbuescher
Copy link
Member Author

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.

cbuescher referenced this pull request Apr 1, 2015
…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
@cbuescher
Copy link
Member Author

@javanna With the removal of the changes in MetaData to #10339, anything else to change here?

@javanna
Copy link
Member

javanna commented Apr 1, 2015

LGTM @cbuescher thanks

@cbuescher cbuescher closed this in 2beda39 Apr 2, 2015
cbuescher pushed a commit that referenced this pull request Apr 2, 2015
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
@cbuescher cbuescher deleted the fix/9081 branch March 31, 2016 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Data Management/Indices APIs APIs to create and manage indices and templates v1.6.0 v2.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[REST API] «/<index_name>-*/_status» + «curator» ≈ massive data loss
3 participants