-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Remote Store] Add support to create index with remote store by default #6932
Changes from 9 commits
9f9d0d0
3f58cea
0c15ef8
4fef117
e02f7d3
a566cd7
7115af0
d611076
3151753
edb480b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.remotestore; | ||
|
||
import org.opensearch.action.admin.indices.get.GetIndexRequest; | ||
import org.opensearch.action.admin.indices.get.GetIndexResponse; | ||
import org.opensearch.cluster.metadata.IndexMetadata; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.indices.replication.common.ReplicationType; | ||
import org.opensearch.test.OpenSearchIntegTestCase; | ||
|
||
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_REMOTE_STORE_ENABLED; | ||
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_REMOTE_STORE_REPOSITORY; | ||
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_REPLICATION_TYPE; | ||
import static org.opensearch.indices.IndicesService.CLUSTER_REMOTE_STORE_ENABLED_SETTING; | ||
import static org.opensearch.indices.IndicesService.CLUSTER_REMOTE_STORE_REPOSITORY_SETTING; | ||
import static org.opensearch.indices.IndicesService.CLUSTER_REMOTE_TRANSLOG_REPOSITORY_SETTING; | ||
import static org.opensearch.indices.IndicesService.CLUSTER_REMOTE_TRANSLOG_STORE_ENABLED_SETTING; | ||
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked; | ||
|
||
@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST) | ||
public class CreateRemoteIndexTranslogDisabledIT extends CreateRemoteIndexIT { | ||
|
||
@Override | ||
protected Settings nodeSettings(int nodeOriginal) { | ||
Settings settings = super.nodeSettings(nodeOriginal); | ||
Settings.Builder builder = Settings.builder() | ||
.put(CLUSTER_REMOTE_STORE_ENABLED_SETTING.getKey(), true) | ||
.put(CLUSTER_REMOTE_STORE_REPOSITORY_SETTING.getKey(), "my-segment-repo-1") | ||
.put(settings); | ||
builder.remove(CLUSTER_REMOTE_TRANSLOG_STORE_ENABLED_SETTING.getKey()); | ||
builder.remove(CLUSTER_REMOTE_TRANSLOG_REPOSITORY_SETTING.getKey()); | ||
return builder.build(); | ||
} | ||
|
||
public void testRemoteStoreEnabledByUserWithRemoteRepo() throws Exception { | ||
final int numReplicas = internalCluster().numDataNodes(); | ||
Settings settings = Settings.builder() | ||
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 3) | ||
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, numReplicas) | ||
.put(SETTING_REPLICATION_TYPE, ReplicationType.SEGMENT) | ||
.put(SETTING_REMOTE_STORE_ENABLED, true) | ||
.put(SETTING_REMOTE_STORE_REPOSITORY, "my-custom-repo") | ||
.build(); | ||
|
||
assertAcked(client().admin().indices().prepareCreate("test-idx-1").setSettings(settings).get()); | ||
GetIndexResponse getIndexResponse = client().admin() | ||
.indices() | ||
.getIndex(new GetIndexRequest().indices("test-idx-1").includeDefaults(true)) | ||
.get(); | ||
Settings indexSettings = getIndexResponse.settings().get("test-idx-1"); | ||
verifyRemoteStoreIndexSettings(indexSettings, "true", "my-custom-repo", null, null, ReplicationType.SEGMENT.toString(), null); | ||
} | ||
|
||
public void testDefaultRemoteStoreNoUserOverride() throws Exception { | ||
final int numReplicas = internalCluster().numDataNodes(); | ||
Settings settings = Settings.builder() | ||
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 3) | ||
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, numReplicas) | ||
.build(); | ||
assertAcked(client().admin().indices().prepareCreate("test-idx-1").setSettings(settings).get()); | ||
GetIndexResponse getIndexResponse = client().admin() | ||
.indices() | ||
.getIndex(new GetIndexRequest().indices("test-idx-1").includeDefaults(true)) | ||
.get(); | ||
Settings indexSettings = getIndexResponse.settings().get("test-idx-1"); | ||
verifyRemoteStoreIndexSettings(indexSettings, "true", "my-segment-repo-1", null, null, ReplicationType.SEGMENT.toString(), null); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,6 +91,7 @@ | |
import org.opensearch.indices.InvalidIndexNameException; | ||
import org.opensearch.indices.ShardLimitValidator; | ||
import org.opensearch.indices.SystemIndices; | ||
import org.opensearch.indices.replication.common.ReplicationType; | ||
import org.opensearch.threadpool.ThreadPool; | ||
|
||
import java.io.IOException; | ||
|
@@ -104,6 +105,7 @@ | |
import java.util.List; | ||
import java.util.Locale; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
@@ -118,12 +120,26 @@ | |
import static java.util.stream.Collectors.toList; | ||
import static org.opensearch.cluster.metadata.IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING; | ||
import static org.opensearch.cluster.metadata.IndexMetadata.INDEX_NUMBER_OF_SHARDS_SETTING; | ||
import static org.opensearch.cluster.metadata.IndexMetadata.INDEX_REMOTE_STORE_ENABLED_SETTING; | ||
import static org.opensearch.cluster.metadata.IndexMetadata.INDEX_REMOTE_STORE_REPOSITORY_SETTING; | ||
import static org.opensearch.cluster.metadata.IndexMetadata.INDEX_REMOTE_TRANSLOG_REPOSITORY_SETTING; | ||
import static org.opensearch.cluster.metadata.IndexMetadata.INDEX_REMOTE_TRANSLOG_STORE_ENABLED_SETTING; | ||
import static org.opensearch.cluster.metadata.IndexMetadata.INDEX_REPLICATION_TYPE_SETTING; | ||
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS; | ||
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_CREATION_DATE; | ||
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_INDEX_UUID; | ||
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_REPLICAS; | ||
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_SHARDS; | ||
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_REMOTE_STORE_ENABLED; | ||
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_REMOTE_STORE_REPOSITORY; | ||
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_REMOTE_TRANSLOG_STORE_ENABLED; | ||
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_REMOTE_TRANSLOG_STORE_REPOSITORY; | ||
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_REPLICATION_TYPE; | ||
import static org.opensearch.cluster.metadata.Metadata.DEFAULT_REPLICA_COUNT_SETTING; | ||
import static org.opensearch.indices.IndicesService.CLUSTER_REMOTE_STORE_REPOSITORY_SETTING; | ||
import static org.opensearch.indices.IndicesService.CLUSTER_REMOTE_TRANSLOG_REPOSITORY_SETTING; | ||
import static org.opensearch.indices.IndicesService.CLUSTER_REMOTE_STORE_ENABLED_SETTING; | ||
import static org.opensearch.indices.IndicesService.CLUSTER_REMOTE_TRANSLOG_STORE_ENABLED_SETTING; | ||
|
||
/** | ||
* Service responsible for submitting create index requests | ||
|
@@ -874,6 +890,8 @@ static Settings aggregateIndexSettings( | |
indexSettingsBuilder.put(IndexMetadata.SETTING_INDEX_PROVIDED_NAME, request.getProvidedName()); | ||
indexSettingsBuilder.put(SETTING_INDEX_UUID, UUIDs.randomBase64UUID()); | ||
|
||
updateRemoteStoreSettings(indexSettingsBuilder, request.settings(), settings); | ||
|
||
if (sourceMetadata != null) { | ||
assert request.resizeType() != null; | ||
prepareResizeIndexSettings( | ||
|
@@ -906,6 +924,52 @@ static Settings aggregateIndexSettings( | |
return indexSettings; | ||
} | ||
|
||
/** | ||
* Updates index settings to enable remote store by default based on cluster level settings | ||
* @param settingsBuilder index settings builder to be updated with relevant settings | ||
* @param requestSettings settings passed in during index create request | ||
* @param clusterSettings cluster level settings | ||
*/ | ||
private static void updateRemoteStoreSettings(Settings.Builder settingsBuilder, Settings requestSettings, Settings clusterSettings) { | ||
if (CLUSTER_REMOTE_STORE_ENABLED_SETTING.get(clusterSettings)) { | ||
// Verify if we can create a remote store based index based on user provided settings | ||
if (!canCreateRemoteStoreIndex(requestSettings)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure |
||
return; | ||
} | ||
|
||
settingsBuilder.put(SETTING_REPLICATION_TYPE, ReplicationType.SEGMENT).put(SETTING_REMOTE_STORE_ENABLED, true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we adding Segment Replication setting explicitly here? Are we sure that replication type will always be segment at this point? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if there is an index level setting for segment replication then it would have been put by the user. We already have check for it. |
||
|
||
String remoteStoreRepo; | ||
if (Objects.equals(requestSettings.get(INDEX_REMOTE_STORE_ENABLED_SETTING.getKey()), "true")) { | ||
remoteStoreRepo = requestSettings.get(INDEX_REMOTE_STORE_REPOSITORY_SETTING.getKey()); | ||
} else { | ||
remoteStoreRepo = CLUSTER_REMOTE_STORE_REPOSITORY_SETTING.get(clusterSettings); | ||
} | ||
settingsBuilder.put(SETTING_REMOTE_STORE_REPOSITORY, remoteStoreRepo); | ||
|
||
boolean translogStoreEnabled = false; | ||
String translogStoreRepo = null; | ||
if (Objects.equals(requestSettings.get(INDEX_REMOTE_TRANSLOG_STORE_ENABLED_SETTING.getKey()), "true")) { | ||
translogStoreEnabled = true; | ||
translogStoreRepo = requestSettings.get(INDEX_REMOTE_TRANSLOG_REPOSITORY_SETTING.getKey()); | ||
} else if (!Objects.equals(requestSettings.get(INDEX_REMOTE_TRANSLOG_STORE_ENABLED_SETTING.getKey()), "false") | ||
&& CLUSTER_REMOTE_TRANSLOG_STORE_ENABLED_SETTING.get(clusterSettings)) { | ||
translogStoreEnabled = true; | ||
translogStoreRepo = CLUSTER_REMOTE_TRANSLOG_REPOSITORY_SETTING.get(clusterSettings); | ||
} | ||
if (translogStoreEnabled) { | ||
settingsBuilder.put(SETTING_REMOTE_TRANSLOG_STORE_ENABLED, translogStoreEnabled) | ||
.put(SETTING_REMOTE_TRANSLOG_STORE_REPOSITORY, translogStoreRepo); | ||
} | ||
} | ||
} | ||
|
||
private static boolean canCreateRemoteStoreIndex(Settings requestSettings) { | ||
return (!INDEX_REPLICATION_TYPE_SETTING.exists(requestSettings) | ||
|| INDEX_REPLICATION_TYPE_SETTING.get(requestSettings).equals(ReplicationType.SEGMENT)) | ||
&& (!INDEX_REMOTE_STORE_ENABLED_SETTING.exists(requestSettings) || INDEX_REMOTE_STORE_ENABLED_SETTING.get(requestSettings)); | ||
} | ||
|
||
public static void validateStoreTypeSettings(Settings settings) { | ||
// deprecate simplefs store type: | ||
if (IndexModule.Type.SIMPLEFS.match(IndexModule.INDEX_STORE_TYPE_SETTING.get(settings))) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will it throw exception if remote repo is not setup and prevent index creation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes. we have checks during index creation