Skip to content

Commit

Permalink
Address comments on PR.
Browse files Browse the repository at this point in the history
Signed-off-by: Rishikesh1159 <[email protected]>
  • Loading branch information
Rishikesh1159 committed Jan 20, 2024
1 parent be471e9 commit f2391ab
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
import static org.opensearch.core.common.util.CollectionUtils.iterableAsArrayList;
import static org.opensearch.index.IndexModule.INDEX_STORE_TYPE_SETTING;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.is;
Expand Down Expand Up @@ -672,30 +671,6 @@ public void testCacheIndexFilesClearedOnDelete() throws Exception {
logger.info("--> validated that the cache file path doesn't exist");
}

public void testIndexCreationWithIndexStoreTypeRemoteStoreThrowsException() {
final int numReplicas = 1;
final String indexName = "test-idx";
internalCluster().ensureAtLeastNumSearchAndDataNodes(numReplicas + 1);
final IllegalArgumentException error = expectThrows(
IllegalArgumentException.class,
() -> createIndex(
indexName,
Settings.builder()
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, Integer.toString(numReplicas))
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, "1")
.put(INDEX_STORE_TYPE_SETTING.getKey(), IndexModule.Type.FS.getSettingsKey())
.put(INDEX_STORE_TYPE_SETTING.getKey(), RestoreSnapshotRequest.StorageType.REMOTE_SNAPSHOT)
.build()
)
);
assertThat(
error.getMessage(),
containsString(
"cannot create index with index setting \"index.store.type\" set to \"remote_snapshot\". Store type can be set to \"remote_snapshot\" only when restoring a remote snapshot by using \"storage_type\": \"remote_snapshot\""
)
);
}

/**
* Test scenario that validates that the default search preference for searchable snapshot
* is primary shards
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,6 @@ public void createIndex(
final CreateIndexClusterStateUpdateRequest request,
final ActionListener<CreateIndexClusterStateUpdateResponse> listener
) {
// INDEX_STORE_TYPE_SETTING is intended to be a system-managed index setting that is configured when restoring a snapshot and
// should not be set to value REMOTE_SNAPSHOT by user.
String storeTypeSetting = request.settings().get(INDEX_STORE_TYPE_SETTING.getKey());
if (storeTypeSetting != null && storeTypeSetting.equals(RestoreSnapshotRequest.StorageType.REMOTE_SNAPSHOT.toString())) {
throw new IllegalArgumentException(
"cannot create index with index setting \"index.store.type\" set to \"remote_snapshot\". Store type can be set to \"remote_snapshot\" only when restoring a remote snapshot by using \"storage_type\": \"remote_snapshot\""
);
}
onlyCreateIndex(request, ActionListener.wrap(response -> {
if (response.isAcknowledged()) {
activeShardsObserver.waitForActiveShards(
Expand Down Expand Up @@ -826,6 +818,16 @@ static Settings aggregateIndexSettings(
final Settings.Builder requestSettings = Settings.builder().put(request.settings());

final Settings.Builder indexSettingsBuilder = Settings.builder();

// Store type of `remote_snapshot` is intended to be system-managed for searchable snapshot indexes so a special case is needed here
// to prevent a user specifying this value when creating an index
String storeTypeSetting = request.settings().get(INDEX_STORE_TYPE_SETTING.getKey());
if (storeTypeSetting != null && storeTypeSetting.equals(RestoreSnapshotRequest.StorageType.REMOTE_SNAPSHOT.toString())) {
throw new IllegalArgumentException(
"cannot create index with index setting \"index.store.type\" set to \"remote_snapshot\". Store type can be set to \"remote_snapshot\" only when restoring a remote snapshot by using \"storage_type\": \"remote_snapshot\""
);
}

if (sourceMetadata == null) {
final Settings.Builder additionalIndexSettings = Settings.builder();
final Settings templateAndRequestSettings = Settings.builder().put(combinedTemplateSettings).put(request.settings()).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.opensearch.ExceptionsHelper;
import org.opensearch.ResourceAlreadyExistsException;
import org.opensearch.Version;
import org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest;
import org.opensearch.action.admin.indices.alias.Alias;
import org.opensearch.action.admin.indices.create.CreateIndexClusterStateUpdateRequest;
import org.opensearch.action.admin.indices.shrink.ResizeType;
Expand Down Expand Up @@ -133,6 +134,7 @@
import static org.opensearch.cluster.metadata.MetadataCreateIndexService.getIndexNumberOfRoutingShards;
import static org.opensearch.cluster.metadata.MetadataCreateIndexService.parseV1Mappings;
import static org.opensearch.cluster.metadata.MetadataCreateIndexService.resolveAndValidateAliases;
import static org.opensearch.index.IndexModule.INDEX_STORE_TYPE_SETTING;
import static org.opensearch.index.IndexSettings.INDEX_REFRESH_INTERVAL_SETTING;
import static org.opensearch.index.IndexSettings.INDEX_REMOTE_TRANSLOG_BUFFER_INTERVAL_SETTING;
import static org.opensearch.index.IndexSettings.INDEX_SOFT_DELETES_SETTING;
Expand All @@ -146,6 +148,7 @@
import static org.opensearch.node.Node.NODE_ATTRIBUTES;
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEY;
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_TRANSLOG_REPOSITORY_NAME_ATTRIBUTE_KEY;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasKey;
Expand Down Expand Up @@ -1936,6 +1939,35 @@ public void testRequestDurabilityWhenRestrictSettingTrue() {
assertEquals(Translog.Durability.REQUEST, INDEX_TRANSLOG_DURABILITY_SETTING.get(indexSettings));
}

public void testIndexCreationWithIndexStoreTypeRemoteStoreThrowsException() {
// This checks that aggregateIndexSettings throws exception for the case when the index setting
// index.store.type is set to remote_snapshot
request = new CreateIndexClusterStateUpdateRequest("create index", "test", "test");
final Settings.Builder requestSettings = Settings.builder();
requestSettings.put(INDEX_STORE_TYPE_SETTING.getKey(), RestoreSnapshotRequest.StorageType.REMOTE_SNAPSHOT);
request.settings(requestSettings.build());
final IllegalArgumentException error = expectThrows(
IllegalArgumentException.class,
() -> aggregateIndexSettings(
ClusterState.EMPTY_STATE,
request,
Settings.EMPTY,
null,
Settings.EMPTY,
IndexScopedSettings.DEFAULT_SCOPED_SETTINGS,
randomShardLimitService(),
Collections.emptySet(),
clusterSettings
)
);
assertThat(
error.getMessage(),
containsString(
"cannot create index with index setting \"index.store.type\" set to \"remote_snapshot\". Store type can be set to \"remote_snapshot\" only when restoring a remote snapshot by using \"storage_type\": \"remote_snapshot\""
)
);
}

private IndexTemplateMetadata addMatchingTemplate(Consumer<IndexTemplateMetadata.Builder> configurator) {
IndexTemplateMetadata.Builder builder = templateMetadataBuilder("template1", "te*");
configurator.accept(builder);
Expand Down

0 comments on commit f2391ab

Please sign in to comment.