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 (#4175)

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

Signed-off-by: Sachin Kale <kalsac@amazon.com>
  • Loading branch information
sachinpkale committed Aug 10, 2022
1 parent 4751f3b commit 1c3f034
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 @@ -292,6 +292,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 @@ -42,6 +42,7 @@
import org.opensearch.common.unit.ByteSizeValue;
import org.opensearch.common.unit.TimeValue;
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 @@ -854,4 +855,31 @@ public void testEnablingRemoteTranslogStoreFailsWhenRemoteSegmentDisabled() {
iae.getMessage()
);
}

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 1c3f034

Please sign in to comment.