forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUG] Add support to clear archived index settings (opensearch-projec…
…t#9019) * Add support to clear archived index setting Signed-off-by: Ankit Kala <ankikala@amazon.com>
- Loading branch information
Showing
7 changed files
with
161 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
129 changes: 129 additions & 0 deletions
129
...src/internalClusterTest/java/org/opensearch/indices/settings/ArchivedIndexSettingsIT.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.indices.settings; | ||
|
||
import org.opensearch.common.settings.Setting; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.plugins.Plugin; | ||
import org.opensearch.test.InternalTestCluster; | ||
import org.opensearch.test.OpenSearchIntegTestCase; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import static org.hamcrest.Matchers.startsWith; | ||
|
||
@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, numDataNodes = 0, supportsDedicatedMasters = false) | ||
public class ArchivedIndexSettingsIT extends OpenSearchIntegTestCase { | ||
private volatile boolean installPlugin; | ||
|
||
public void testArchiveSettings() throws Exception { | ||
installPlugin = true; | ||
// Set up the cluster with an index containing dummy setting(owned by dummy plugin) | ||
String oldClusterManagerNode = internalCluster().startClusterManagerOnlyNode(); | ||
String oldDataNode = internalCluster().startDataOnlyNode(); | ||
assertEquals(2, internalCluster().numDataAndClusterManagerNodes()); | ||
createIndex("test"); | ||
ensureYellow(); | ||
// Add a dummy setting | ||
client().admin() | ||
.indices() | ||
.prepareUpdateSettings("test") | ||
.setSettings(Settings.builder().put("index.dummy", "foobar").put("index.dummy2", "foobar")) | ||
.execute() | ||
.actionGet(); | ||
|
||
// Remove dummy plugin and replace the cluster manager node so that the stale plugin setting moves to "archived". | ||
installPlugin = false; | ||
String newClusterManagerNode = internalCluster().startClusterManagerOnlyNode(); | ||
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(oldClusterManagerNode)); | ||
internalCluster().restartNode(newClusterManagerNode); | ||
|
||
// Verify that archived settings exists. | ||
assertTrue( | ||
client().admin().indices().prepareGetSettings("test").get().getIndexToSettings().get("test").hasValue("archived.index.dummy") | ||
); | ||
assertTrue( | ||
client().admin().indices().prepareGetSettings("test").get().getIndexToSettings().get("test").hasValue("archived.index.dummy2") | ||
); | ||
|
||
// Archived setting update should fail on open index. | ||
IllegalArgumentException exception = expectThrows( | ||
IllegalArgumentException.class, | ||
() -> client().admin() | ||
.indices() | ||
.prepareUpdateSettings("test") | ||
.setSettings(Settings.builder().putNull("archived.index.dummy")) | ||
.execute() | ||
.actionGet() | ||
); | ||
assertThat( | ||
exception.getMessage(), | ||
startsWith("Can't update non dynamic settings [[archived.index.dummy]] for open indices [[test") | ||
); | ||
|
||
// close the index. | ||
client().admin().indices().prepareClose("test").get(); | ||
|
||
// Remove archived.index.dummy explicitly. | ||
assertTrue( | ||
client().admin() | ||
.indices() | ||
.prepareUpdateSettings("test") | ||
.setSettings(Settings.builder().putNull("archived.index.dummy")) | ||
.execute() | ||
.actionGet() | ||
.isAcknowledged() | ||
); | ||
|
||
// Remove archived.index.dummy2 using wildcard. | ||
assertTrue( | ||
client().admin() | ||
.indices() | ||
.prepareUpdateSettings("test") | ||
.setSettings(Settings.builder().putNull("archived.*")) | ||
.execute() | ||
.actionGet() | ||
.isAcknowledged() | ||
); | ||
|
||
// Verify that archived settings are cleaned up successfully. | ||
assertFalse( | ||
client().admin().indices().prepareGetSettings("test").get().getIndexToSettings().get("test").hasValue("archived.index.dummy") | ||
); | ||
assertFalse( | ||
client().admin().indices().prepareGetSettings("test").get().getIndexToSettings().get("test").hasValue("archived.index.dummy2") | ||
); | ||
} | ||
|
||
@Override | ||
protected Collection<Class<? extends Plugin>> nodePlugins() { | ||
return installPlugin ? Arrays.asList(DummySettingPlugin.class) : Collections.emptyList(); | ||
} | ||
|
||
public static class DummySettingPlugin extends Plugin { | ||
public static final Setting<String> DUMMY_SETTING = Setting.simpleString( | ||
"index.dummy", | ||
Setting.Property.IndexScope, | ||
Setting.Property.Dynamic | ||
); | ||
public static final Setting<String> DUMMY_SETTING2 = Setting.simpleString( | ||
"index.dummy2", | ||
Setting.Property.IndexScope, | ||
Setting.Property.Dynamic | ||
); | ||
|
||
@Override | ||
public List<Setting<?>> getSettings() { | ||
return Arrays.asList(DUMMY_SETTING, DUMMY_SETTING2); | ||
} | ||
} | ||
} |
This file contains 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 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 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 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 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