Skip to content

Commit

Permalink
[Remote Store] Add validator that forces segment replication type bef…
Browse files Browse the repository at this point in the history
…ore enabling remote store (opensearch-project#4175)

* Add validator that forces segment replication type before enabling remote store

Signed-off-by: Sachin Kale <kalsac@amazon.com>
  • Loading branch information
sachinpkale authored and Sachin Kale committed Sep 1, 2022
1 parent d5c4878 commit c0a3f67
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,32 @@ public Iterator<Setting<?>> settings() {
public static final Setting<Boolean> INDEX_REMOTE_STORE_ENABLED_SETTING = Setting.boolSetting(
SETTING_REMOTE_STORE_ENABLED,
false,
new Setting.Validator<>() {

@Override
public void validate(final Boolean value) {}

@Override
public void validate(final Boolean value, final Map<Setting<?>, Object> settings) {
final Object replicationType = settings.get(INDEX_REPLICATION_TYPE_SETTING);
if (replicationType != ReplicationType.SEGMENT && value == true) {
throw new IllegalArgumentException(
"Settings "
+ INDEX_REMOTE_STORE_ENABLED_SETTING.getKey()
+ " cannot be enabled when "
+ INDEX_REPLICATION_TYPE_SETTING.getKey()
+ " is set to "
+ settings.get(INDEX_REPLICATION_TYPE_SETTING)
);
}
}

@Override
public Iterator<Setting<?>> settings() {
final List<Setting<?>> settings = Collections.singletonList(INDEX_REPLICATION_TYPE_SETTING);
return settings.iterator();
}
},
Property.IndexScope,
Property.Final
);
Expand Down
28 changes: 28 additions & 0 deletions server/src/test/java/org/opensearch/index/IndexSettingsTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.opensearch.common.unit.TimeValue;
import org.opensearch.common.util.FeatureFlags;
import org.opensearch.index.translog.Translog;
import org.opensearch.indices.replication.common.ReplicationType;
import org.opensearch.test.OpenSearchTestCase;
import org.opensearch.test.VersionUtils;

Expand Down Expand Up @@ -796,4 +797,31 @@ public void testUpdateRemoteStoreFails() {
);
assertEquals(error.getMessage(), "final index setting [index.remote_store.enabled], not updateable");
}

public void testEnablingRemoteStoreFailsWhenReplicationTypeIsDocument() {
Settings indexSettings = Settings.builder()
.put("index.replication.type", ReplicationType.DOCUMENT)
.put("index.remote_store.enabled", true)
.build();
IllegalArgumentException iae = expectThrows(
IllegalArgumentException.class,
() -> IndexMetadata.INDEX_REMOTE_STORE_ENABLED_SETTING.get(indexSettings)
);
assertEquals(
"Settings index.remote_store.enabled cannot be enabled when index.replication.type is set to DOCUMENT",
iae.getMessage()
);
}

public void testEnablingRemoteStoreFailsWhenReplicationTypeIsDefault() {
Settings indexSettings = Settings.builder().put("index.remote_store.enabled", true).build();
IllegalArgumentException iae = expectThrows(
IllegalArgumentException.class,
() -> IndexMetadata.INDEX_REMOTE_STORE_ENABLED_SETTING.get(indexSettings)
);
assertEquals(
"Settings index.remote_store.enabled cannot be enabled when index.replication.type is set to DOCUMENT",
iae.getMessage()
);
}
}

0 comments on commit c0a3f67

Please sign in to comment.