Skip to content

Commit ce84f82

Browse files
sachinpkaleSachin Kale
authored andcommitted
[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 <[email protected]>
1 parent 3d50a74 commit ce84f82

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
@@ -290,6 +290,32 @@ public Iterator<Setting<?>> settings() {
290290
public static final Setting<Boolean> INDEX_REMOTE_STORE_ENABLED_SETTING = Setting.boolSetting(
291291
SETTING_REMOTE_STORE_ENABLED,
292292
false,
293+
new Setting.Validator<>() {
294+
295+
@Override
296+
public void validate(final Boolean value) {}
297+
298+
@Override
299+
public void validate(final Boolean value, final Map<Setting<?>, Object> settings) {
300+
final Object replicationType = settings.get(INDEX_REPLICATION_TYPE_SETTING);
301+
if (replicationType != ReplicationType.SEGMENT && value == true) {
302+
throw new IllegalArgumentException(
303+
"Settings "
304+
+ INDEX_REMOTE_STORE_ENABLED_SETTING.getKey()
305+
+ " cannot be enabled when "
306+
+ INDEX_REPLICATION_TYPE_SETTING.getKey()
307+
+ " is set to "
308+
+ settings.get(INDEX_REPLICATION_TYPE_SETTING)
309+
);
310+
}
311+
}
312+
313+
@Override
314+
public Iterator<Setting<?>> settings() {
315+
final List<Setting<?>> settings = Collections.singletonList(INDEX_REPLICATION_TYPE_SETTING);
316+
return settings.iterator();
317+
}
318+
},
293319
Property.IndexScope,
294320
Property.Final
295321
);

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.opensearch.common.unit.TimeValue;
4545
import org.opensearch.common.util.FeatureFlags;
4646
import org.opensearch.index.translog.Translog;
47+
import org.opensearch.indices.replication.common.ReplicationType;
4748
import org.opensearch.test.OpenSearchTestCase;
4849
import org.opensearch.test.VersionUtils;
4950

@@ -796,4 +797,31 @@ public void testUpdateRemoteStoreFails() {
796797
);
797798
assertEquals(error.getMessage(), "final index setting [index.remote_store.enabled], not updateable");
798799
}
800+
801+
public void testEnablingRemoteStoreFailsWhenReplicationTypeIsDocument() {
802+
Settings indexSettings = Settings.builder()
803+
.put("index.replication.type", ReplicationType.DOCUMENT)
804+
.put("index.remote_store.enabled", true)
805+
.build();
806+
IllegalArgumentException iae = expectThrows(
807+
IllegalArgumentException.class,
808+
() -> IndexMetadata.INDEX_REMOTE_STORE_ENABLED_SETTING.get(indexSettings)
809+
);
810+
assertEquals(
811+
"Settings index.remote_store.enabled cannot be enabled when index.replication.type is set to DOCUMENT",
812+
iae.getMessage()
813+
);
814+
}
815+
816+
public void testEnablingRemoteStoreFailsWhenReplicationTypeIsDefault() {
817+
Settings indexSettings = Settings.builder().put("index.remote_store.enabled", true).build();
818+
IllegalArgumentException iae = expectThrows(
819+
IllegalArgumentException.class,
820+
() -> IndexMetadata.INDEX_REMOTE_STORE_ENABLED_SETTING.get(indexSettings)
821+
);
822+
assertEquals(
823+
"Settings index.remote_store.enabled cannot be enabled when index.replication.type is set to DOCUMENT",
824+
iae.getMessage()
825+
);
826+
}
799827
}

0 commit comments

Comments
 (0)