-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Do not open indices with broken settings #26995
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
Merged
jasontedor
merged 3 commits into
elastic:master
from
jasontedor:do-not-open-broken-indices
Dec 8, 2017
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
|
|
||
| package org.elasticsearch.action.admin.indices.create; | ||
|
|
||
| import org.elasticsearch.ElasticsearchException; | ||
| import org.elasticsearch.action.ActionListener; | ||
| import org.elasticsearch.action.UnavailableShardsException; | ||
| import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse; | ||
|
|
@@ -32,6 +33,7 @@ | |
| import org.elasticsearch.common.collect.ImmutableOpenMap; | ||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.common.unit.TimeValue; | ||
| import org.elasticsearch.env.NodeEnvironment; | ||
| import org.elasticsearch.index.IndexNotFoundException; | ||
| import org.elasticsearch.index.query.RangeQueryBuilder; | ||
| import org.elasticsearch.test.ESIntegTestCase; | ||
|
|
@@ -51,6 +53,8 @@ | |
| import static org.hamcrest.Matchers.containsString; | ||
| import static org.hamcrest.Matchers.equalTo; | ||
| import static org.hamcrest.Matchers.greaterThanOrEqualTo; | ||
| import static org.hamcrest.Matchers.hasToString; | ||
| import static org.hamcrest.Matchers.instanceOf; | ||
| import static org.hamcrest.Matchers.lessThanOrEqualTo; | ||
| import static org.hamcrest.core.IsNull.notNullValue; | ||
|
|
||
|
|
@@ -344,4 +348,37 @@ public void testIndexNameInResponse() { | |
|
|
||
| assertEquals("Should have index name in response", "foo", response.index()); | ||
| } | ||
|
|
||
| public void testIndexWithUnknownSetting() throws Exception { | ||
| final int replicas = internalCluster().numDataNodes() - 1; | ||
| final Settings settings = Settings.builder().put("index.number_of_shards", 1).put("index.number_of_replicas", replicas).build(); | ||
| client().admin().indices().prepareCreate("test").setSettings(settings).get(); | ||
| ensureGreen("test"); | ||
| final ClusterState state = client().admin().cluster().prepareState().get().getState(); | ||
| final IndexMetaData metaData = state.getMetaData().index("test"); | ||
| for (final NodeEnvironment services : internalCluster().getInstances(NodeEnvironment.class)) { | ||
| final IndexMetaData brokenMetaData = | ||
| IndexMetaData | ||
| .builder(metaData) | ||
| .settings(Settings.builder().put(metaData.getSettings()).put("index.foo", "true")) | ||
| .build(); | ||
| // so evil | ||
| IndexMetaData.FORMAT.write(brokenMetaData, services.indexPaths(brokenMetaData.getIndex())); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice test :) |
||
| } | ||
| internalCluster().fullRestart(); | ||
| ensureGreen(metaData.getIndex().getName()); // we have to wait for the index to show up in the metadata or we will fail in a race | ||
| final ClusterState stateAfterRestart = client().admin().cluster().prepareState().get().getState(); | ||
|
|
||
| // the index should not be open after we restart and recover the broken index metadata | ||
| assertThat(stateAfterRestart.getMetaData().index(metaData.getIndex()).getState(), equalTo(IndexMetaData.State.CLOSE)); | ||
|
|
||
| // try to open the index | ||
| final ElasticsearchException e = | ||
| expectThrows(ElasticsearchException.class, () -> client().admin().indices().prepareOpen("test").get()); | ||
| assertThat(e, hasToString(containsString("Failed to verify index " + metaData.getIndex()))); | ||
| assertNotNull(e.getCause()); | ||
| assertThat(e.getCause(), instanceOf(IllegalArgumentException.class)); | ||
| assertThat(e, hasToString(containsString("unknown setting [index.foo]"))); | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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 really do not like removing this but it is in the way of testing this change and I do see hacks to get around it but I would rather not. Let's discuss this?
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.
well I think it's not necessarily correct to have this assertion since if you have a plugin that you remove with a setting it will fail. so I think it's ok to remove it no?