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

Verify the index state of concrete indices after alias resolution #9057

Merged

Conversation

martijnvg
Copy link
Member

No description provided.

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

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

Copy link
Member

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 :)

@javanna
Copy link
Member

javanna commented Dec 24, 2014

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 ignore_unavailable option, meaning that if an alias expands to multiple indices, closed indices will be ignored or cause an exception depending on the value of ignore_unavailable. Want to double check this @clintongormley ? I wonder if it's ok to execute an operation on only a subset of indices that an alias points to...

@clintongormley
Copy link

I wonder if it's ok to execute an operation on only a subset of indices that an alias points to...

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 ignore_unavailable then they're expecting the operation to execute only on available indices, so it seems OK to me, no? Any ideas of when it might not be OK?

@javanna
Copy link
Member

javanna commented Dec 24, 2014

Any ideas of when it might not be OK?

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 ignore_unavailable option to control this, so we should be fine.

}
return indices;
default:
ObjectOpenHashSet<String> concreteIndices = ObjectOpenHashSet.from(indices);
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 the other way around would be better: create a new array instead of set and add open indices to it from within the loop.

Copy link
Member Author

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?

Copy link
Member

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

@javanna
Copy link
Member

javanna commented Dec 24, 2014

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:

{"error":"ClusterBlockException[blocked by: [FORBIDDEN/4/index closed];]","status":403}

After the fix, depending on ignore_unavailable we will either filter out the closed indices during aliases resolution, hence the operation will be executed against the resolved open indices only, or we'll return the following:

{"error":"IndexClosedException[[alias] closed]","status":403}

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

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.

Copy link
Member

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.

@martijnvg
Copy link
Member Author

Ok, lets also push it to 1.4 branch for the reasons you mentioned. I think that:

"IndexClosedException[[alias] closed]"

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

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?)

@javanna
Copy link
Member

javanna commented Jan 7, 2015

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 ;)

@martijnvg martijnvg force-pushed the check_state_after_alias_resolution branch from 4c7427b to 5a46b67 Compare January 7, 2015 14:30
@martijnvg
Copy link
Member Author

@javanna I've updated the PR.

if (indexMetaData != null) {
if (indexMetaData.getState() == IndexMetaData.State.CLOSE) {
if (failClosed) {
throw new IndexClosedException(new Index(aliasOrIndex));
Copy link
Member

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 ;)

Copy link
Member Author

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 :)

@javanna
Copy link
Member

javanna commented Jan 7, 2015

LGTM

@martijnvg martijnvg removed the review label Jan 8, 2015
@martijnvg martijnvg force-pushed the check_state_after_alias_resolution branch from 580b802 to dedaf93 Compare January 8, 2015 15:47
martijnvg added a commit that referenced this pull request Jan 8, 2015
…osed and deal with this according to IndicesOptions.

Closes #9057
@martijnvg martijnvg merged commit dedaf93 into elastic:master Jan 8, 2015
martijnvg added a commit that referenced this pull request Jan 8, 2015
…osed and deal with this according to IndicesOptions.

Closes #9057
@clintongormley clintongormley added the :Core/Infra/Core Core issues without another label label Mar 19, 2015
@martijnvg martijnvg deleted the check_state_after_alias_resolution branch May 18, 2015 23:27
@clintongormley clintongormley changed the title Core: Verify the index state of concrete indices after alias resolution Verify the index state of concrete indices after alias resolution Jun 7, 2015
mute pushed a commit to mute/elasticsearch that referenced this pull request Jul 29, 2015
…osed and deal with this according to IndicesOptions.

Closes elastic#9057
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants