Skip to content

Commit

Permalink
Add support to clear archived index setting
Browse files Browse the repository at this point in the history
Signed-off-by: Ankit Kala <ankikala@amazon.com>
  • Loading branch information
ankitkala committed Aug 1, 2023
1 parent b2a7348 commit 959bcc4
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Fixed
- Fix 'org.apache.hc.core5.http.ParseException: Invalid protocol version' under JDK 16+ ([#4827](https://github.com/opensearch-project/OpenSearch/pull/4827))
- Fix compression support for h2c protocol ([#4944](https://github.com/opensearch-project/OpenSearch/pull/4944))
- Add support to clear archived index setting ([#9019](https://github.com/opensearch-project/OpenSearch/pull/9019))

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import java.util.Set;

import static org.opensearch.action.support.ContextPreservingActionListener.wrapPreservingContext;
import static org.opensearch.common.settings.AbstractScopedSettings.ARCHIVED_SETTINGS_PREFIX;
import static org.opensearch.index.IndexSettings.same;

/**
Expand Down Expand Up @@ -137,15 +138,17 @@ public void updateSettings(
for (String key : normalizedSettings.keySet()) {
Setting setting = indexScopedSettings.get(key);
boolean isWildcard = setting == null && Regex.isSimpleMatchPattern(key);
boolean isArchived = key.startsWith(ARCHIVED_SETTINGS_PREFIX);
assert setting != null // we already validated the normalized settings
|| isArchived
|| (isWildcard && normalizedSettings.hasValue(key) == false) : "unknown setting: "
+ key
+ " isWildcard: "
+ isWildcard
+ " hasValue: "
+ normalizedSettings.hasValue(key);
settingsForClosedIndices.copy(key, normalizedSettings);
if (isWildcard || setting.isDynamic()) {
if (isWildcard || isArchived || setting.isDynamic()) {
settingsForOpenIndices.copy(key, normalizedSettings);
} else {
skippedSettings.add(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ public final void validate(final Settings settings, final boolean validateDepend
* @see Setting#getSettingsDependencies(String)
*/
public final void validate(final Settings settings, final boolean validateDependencies, final boolean validateInternalOrPrivateIndex) {
validate(settings, validateDependencies, false, false, validateInternalOrPrivateIndex);
validate(settings, validateDependencies, false, true, validateInternalOrPrivateIndex);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public final class IndexScopedSettings extends AbstractScopedSettings {

public static final Predicate<String> INDEX_SETTINGS_KEY_PREDICATE = (s) -> s.startsWith(IndexMetadata.INDEX_SETTING_PREFIX);

public static final Predicate<String> ARCHIVED_SETTINGS_KEY_PREDICATE = (s) -> s.startsWith(ARCHIVED_SETTINGS_PREFIX);

public static final Set<Setting<?>> BUILT_IN_INDEX_SETTINGS = Collections.unmodifiableSet(
new HashSet<>(
Arrays.asList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
import java.util.stream.Stream;

import static org.opensearch.core.common.unit.ByteSizeValue.parseBytesSizeValue;
import static org.opensearch.common.settings.AbstractScopedSettings.ARCHIVED_SETTINGS_PREFIX;
import static org.opensearch.common.unit.TimeValue.parseTimeValue;

/**
Expand Down Expand Up @@ -1217,7 +1218,7 @@ public boolean shouldRemoveMissingPlaceholder(String placeholderName) {
}

/**
* Checks that all settings in the builder start with the specified prefix.
* Checks that all settings(except archived settings and wildcards) in the builder start with the specified prefix.
*
* If a setting doesn't start with the prefix, the builder appends the prefix to such setting.
*/
Expand All @@ -1227,7 +1228,7 @@ public Builder normalizePrefix(String prefix) {
while (iterator.hasNext()) {
Map.Entry<String, Object> entry = iterator.next();
String key = entry.getKey();
if (key.startsWith(prefix) == false && key.endsWith("*") == false) {
if (key.startsWith(prefix) == false && key.endsWith("*") == false && key.startsWith(ARCHIVED_SETTINGS_PREFIX) == false) {
replacements.put(prefix + key, entry.getValue());
iterator.remove();
}
Expand Down
4 changes: 3 additions & 1 deletion server/src/main/java/org/opensearch/index/IndexSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,9 @@ public synchronized boolean updateIndexMetadata(IndexMetadata indexMetadata) {
*/
public static boolean same(final Settings left, final Settings right) {
return left.filter(IndexScopedSettings.INDEX_SETTINGS_KEY_PREDICATE)
.equals(right.filter(IndexScopedSettings.INDEX_SETTINGS_KEY_PREDICATE));
.equals(right.filter(IndexScopedSettings.INDEX_SETTINGS_KEY_PREDICATE))
&& left.filter(IndexScopedSettings.ARCHIVED_SETTINGS_KEY_PREDICATE)
.equals(right.filter(IndexScopedSettings.ARCHIVED_SETTINGS_KEY_PREDICATE));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,20 @@ public void testPrefixNormalization() {
assertThat(settings.get("foo.test"), equalTo("test"));
}

public void testPrefixNormalizationArchived() {
Settings settings = Settings.builder().put("archived.foo.bar", "baz").normalizePrefix("foo.").build();

assertThat(settings.size(), equalTo(1));
assertThat(settings.get("foo.archived.foo.bar"), nullValue());
assertThat(settings.get("archived.foo.bar"), equalTo("baz"));

settings = Settings.builder().put("archived.foo.*", "baz").normalizePrefix("foo.").build();

assertThat(settings.size(), equalTo(1));
assertThat(settings.get("foo.archived.foo.*"), nullValue());
assertThat(settings.get("archived.foo.*"), equalTo("baz"));
}

public void testFilteredMap() {
Settings.Builder builder = Settings.builder();
builder.put("a", "a1");
Expand Down

0 comments on commit 959bcc4

Please sign in to comment.