Skip to content

Commit 1c3f034

Browse files
authored
[Remote Store] Add validator that forces segment replication type before 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>
1 parent 4751f3b commit 1c3f034

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

server/src/main/java/org/opensearch/cluster/metadata/IndexMetadata.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,32 @@ public Iterator<Setting<?>> settings() {
292292
public static final Setting<Boolean> INDEX_REMOTE_STORE_ENABLED_SETTING = Setting.boolSetting(
293293
SETTING_REMOTE_STORE_ENABLED,
294294
false,
295+
new Setting.Validator<>() {
296+
297+
@Override
298+
public void validate(final Boolean value) {}
299+
300+
@Override
301+
public void validate(final Boolean value, final Map<Setting<?>, Object> settings) {
302+
final Object replicationType = settings.get(INDEX_REPLICATION_TYPE_SETTING);
303+
if (replicationType != ReplicationType.SEGMENT && value == true) {
304+
throw new IllegalArgumentException(
305+
"Settings "
306+
+ INDEX_REMOTE_STORE_ENABLED_SETTING.getKey()
307+
+ " cannot be enabled when "
308+
+ INDEX_REPLICATION_TYPE_SETTING.getKey()
309+
+ " is set to "
310+
+ settings.get(INDEX_REPLICATION_TYPE_SETTING)
311+
);
312+
}
313+
}
314+
315+
@Override
316+
public Iterator<Setting<?>> settings() {
317+
final List<Setting<?>> settings = Collections.singletonList(INDEX_REPLICATION_TYPE_SETTING);
318+
return settings.iterator();
319+
}
320+
},
295321
Property.IndexScope,
296322
Property.Final
297323
);

server/src/test/java/org/opensearch/index/IndexSettingsTests.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.opensearch.common.unit.ByteSizeValue;
4343
import org.opensearch.common.unit.TimeValue;
4444
import org.opensearch.index.translog.Translog;
45+
import org.opensearch.indices.replication.common.ReplicationType;
4546
import org.opensearch.test.OpenSearchTestCase;
4647
import org.opensearch.test.VersionUtils;
4748

@@ -854,4 +855,31 @@ public void testEnablingRemoteTranslogStoreFailsWhenRemoteSegmentDisabled() {
854855
iae.getMessage()
855856
);
856857
}
858+
859+
public void testEnablingRemoteStoreFailsWhenReplicationTypeIsDocument() {
860+
Settings indexSettings = Settings.builder()
861+
.put("index.replication.type", ReplicationType.DOCUMENT)
862+
.put("index.remote_store.enabled", true)
863+
.build();
864+
IllegalArgumentException iae = expectThrows(
865+
IllegalArgumentException.class,
866+
() -> IndexMetadata.INDEX_REMOTE_STORE_ENABLED_SETTING.get(indexSettings)
867+
);
868+
assertEquals(
869+
"Settings index.remote_store.enabled cannot be enabled when index.replication.type is set to DOCUMENT",
870+
iae.getMessage()
871+
);
872+
}
873+
874+
public void testEnablingRemoteStoreFailsWhenReplicationTypeIsDefault() {
875+
Settings indexSettings = Settings.builder().put("index.remote_store.enabled", true).build();
876+
IllegalArgumentException iae = expectThrows(
877+
IllegalArgumentException.class,
878+
() -> IndexMetadata.INDEX_REMOTE_STORE_ENABLED_SETTING.get(indexSettings)
879+
);
880+
assertEquals(
881+
"Settings index.remote_store.enabled cannot be enabled when index.replication.type is set to DOCUMENT",
882+
iae.getMessage()
883+
);
884+
}
857885
}

0 commit comments

Comments
 (0)