-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Discontinue archiving broken cluster settings #28253
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -681,6 +681,44 @@ public Settings archiveUnknownOrInvalidSettings( | |
} | ||
} | ||
|
||
|
||
/** | ||
* Checks invalid or unknown settings. Any setting that is not recognized or fails validation | ||
* will be processed by consumers. | ||
* An exception will be thrown if any invalid or unknown setting is found. | ||
* | ||
* @param settings the {@link Settings} instance to scan for unknown or invalid settings | ||
* @param unknownConsumer callback on unknown settings (consumer receives unknown key and its | ||
* associated value) | ||
* @param invalidConsumer callback on invalid settings (consumer receives invalid key, its | ||
* associated value and an exception) | ||
*/ | ||
public void checkUnknownOrInvalidSettings( | ||
final Settings settings, | ||
final Consumer<Map.Entry<String, String>> unknownConsumer, | ||
final BiConsumer<Map.Entry<String, String>, IllegalArgumentException> invalidConsumer) { | ||
List<String> failedKeys = new ArrayList<>(); | ||
for (String key : settings.keySet()) { | ||
try { | ||
Setting<?> setting = get(key); | ||
if (setting != null) { | ||
setting.get(settings); | ||
} else { | ||
if (!isPrivateSetting(key)) { | ||
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. nit: We usually use the |
||
failedKeys.add(key); | ||
unknownConsumer.accept(new Entry(key, settings)); | ||
} | ||
} | ||
} catch (IllegalArgumentException ex) { | ||
failedKeys.add(key); | ||
invalidConsumer.accept(new Entry(key, settings), ex); | ||
} | ||
} | ||
if (failedKeys.size() > 0) { | ||
throw new IllegalStateException("Invalid or unknown settings: " + String.join(", ", failedKeys)); | ||
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. Given that this error will occur during an upgrade which is a high stress scenario anyway and the mitigation is not entirely straightforward, I think it would be good if we could provide specific guidance how to address this problem? Otherwise, people would need to turn to the migration guide for 7.0 and check the changes to find out how to handle this? |
||
} | ||
} | ||
|
||
private static final class Entry implements Map.Entry<String, String> { | ||
|
||
private final String key; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,8 @@ | |
import org.elasticsearch.test.ESIntegTestCase.ClusterScope; | ||
import org.elasticsearch.test.ESIntegTestCase.Scope; | ||
import org.elasticsearch.test.InternalTestCluster.RestartCallback; | ||
import org.junit.Rule; | ||
import org.junit.rules.ExpectedException; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
@@ -64,6 +66,8 @@ | |
@ClusterScope(scope = Scope.TEST, numDataNodes = 0) | ||
public class GatewayIndexStateIT extends ESIntegTestCase { | ||
|
||
@Rule | ||
public ExpectedException expectedException = ExpectedException.none(); | ||
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. I'm not saying that this is wrong but it seems we don't use it (so far?) in our code base. For consistency I'd probably check for expected exceptions as we did before but maybe we want to use |
||
private final Logger logger = Loggers.getLogger(GatewayIndexStateIT.class); | ||
|
||
public void testMappingMetaDataParsed() throws Exception { | ||
|
@@ -479,7 +483,7 @@ public void testRecoverMissingAnalyzer() throws Exception { | |
assertThat(ex.getCause().getMessage(), containsString("analyzer [test] not found for field [field1]")); | ||
} | ||
|
||
public void testArchiveBrokenClusterSettings() throws Exception { | ||
public void testFailBrokenClusterSettings() throws Exception { | ||
logger.info("--> starting one node"); | ||
internalCluster().startNode(); | ||
client().prepareIndex("test", "type1", "1").setSource("field1", "value1").setRefreshPolicy(IMMEDIATE).get(); | ||
|
@@ -502,20 +506,9 @@ public void testArchiveBrokenClusterSettings() throws Exception { | |
.put(ElectMasterService.DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING.getKey(), "broken").build()).build(); | ||
MetaData.FORMAT.write(brokenMeta, nodeEnv.nodeDataPaths()); | ||
} | ||
internalCluster().fullRestart(); | ||
ensureYellow("test"); // wait for state recovery | ||
state = client().admin().cluster().prepareState().get().getState(); | ||
assertEquals("true", state.metaData().persistentSettings().get("archived.this.is.unknown")); | ||
assertEquals("broken", state.metaData().persistentSettings().get("archived." | ||
+ ElectMasterService.DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING.getKey())); | ||
|
||
// delete these settings | ||
client().admin().cluster().prepareUpdateSettings().setPersistentSettings(Settings.builder().putNull("archived.*")).get(); | ||
|
||
state = client().admin().cluster().prepareState().get().getState(); | ||
assertNull(state.metaData().persistentSettings().get("archived.this.is.unknown")); | ||
assertNull(state.metaData().persistentSettings().get("archived." | ||
+ ElectMasterService.DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING.getKey())); | ||
assertHitCount(client().prepareSearch().setQuery(matchAllQuery()).get(), 1L); | ||
expectedException.expect(ElasticsearchException.class); | ||
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. I think we should do a deeper inspection of the underlying cause and maybe even the error message (at least whether it matches a certain pattern)? |
||
internalCluster().fullRestart(); | ||
} | ||
|
||
} |
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 please mention the exact type that is thrown (
IllegalStateException
)?