Skip to content

Commit 5e915e1

Browse files
committed
Introduce remote store path type in customData in IndexMetadata
Signed-off-by: Ashish Singh <ssashish@amazon.com>
1 parent e6eec36 commit 5e915e1

File tree

5 files changed

+69
-2
lines changed

5 files changed

+69
-2
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@ public static APIBlock readFrom(StreamInput input) throws IOException {
635635
static final String KEY_ROLLOVER_INFOS = "rollover_info";
636636
static final String KEY_SYSTEM = "system";
637637
public static final String KEY_PRIMARY_TERMS = "primary_terms";
638+
public static final String REMOTE_STORE_CUSTOM_KEY = "remote_store";
638639

639640
public static final String INDEX_STATE_FILE_PREFIX = "state-";
640641

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

+19-2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
import org.opensearch.index.mapper.MapperService;
8989
import org.opensearch.index.mapper.MapperService.MergeReason;
9090
import org.opensearch.index.query.QueryShardContext;
91+
import org.opensearch.index.remote.RemoteStorePathType;
9192
import org.opensearch.index.shard.IndexSettingProvider;
9293
import org.opensearch.index.translog.Translog;
9394
import org.opensearch.indices.IndexCreationException;
@@ -498,7 +499,8 @@ private ClusterState applyCreateIndexWithTemporaryService(
498499
temporaryIndexMeta.getSettings(),
499500
temporaryIndexMeta.getRoutingNumShards(),
500501
sourceMetadata,
501-
temporaryIndexMeta.isSystem()
502+
temporaryIndexMeta.isSystem(),
503+
temporaryIndexMeta.getCustomData()
502504
);
503505
} catch (Exception e) {
504506
logger.info("failed to build index metadata [{}]", request.index());
@@ -544,6 +546,16 @@ private IndexMetadata buildAndValidateTemporaryIndexMetadata(
544546
tmpImdBuilder.settings(indexSettings);
545547
tmpImdBuilder.system(isSystem);
546548

549+
if (isRemoteStoreAttributePresent(settings)) {
550+
String pathType;
551+
if (clusterService.getClusterSettings().get(IndicesService.CLUSTER_REMOTE_STORE_PATH_PREFIX_OPTIMISED_SETTING)) {
552+
pathType = RemoteStorePathType.HASHED_PREFIX.toString();
553+
} else {
554+
pathType = RemoteStorePathType.FIXED.toString();
555+
}
556+
tmpImdBuilder.putCustom(IndexMetadata.REMOTE_STORE_CUSTOM_KEY, Map.of(RemoteStorePathType.NAME, pathType));
557+
}
558+
547559
// Set up everything, now locally create the index to see that things are ok, and apply
548560
IndexMetadata tempMetadata = tmpImdBuilder.build();
549561
validateActiveShardCount(request.waitForActiveShards(), tempMetadata);
@@ -1147,7 +1159,8 @@ static IndexMetadata buildIndexMetadata(
11471159
Settings indexSettings,
11481160
int routingNumShards,
11491161
@Nullable IndexMetadata sourceMetadata,
1150-
boolean isSystem
1162+
boolean isSystem,
1163+
Map<String, DiffableStringMap> customData
11511164
) {
11521165
IndexMetadata.Builder indexMetadataBuilder = createIndexMetadataBuilder(indexName, sourceMetadata, indexSettings, routingNumShards);
11531166
indexMetadataBuilder.system(isSystem);
@@ -1168,6 +1181,10 @@ static IndexMetadata buildIndexMetadata(
11681181
indexMetadataBuilder.putAlias(aliases.get(i));
11691182
}
11701183

1184+
for (Map.Entry<String, DiffableStringMap> entry : customData.entrySet()) {
1185+
indexMetadataBuilder.putCustom(entry.getKey(), entry.getValue());
1186+
}
1187+
11711188
indexMetadataBuilder.state(IndexMetadata.State.OPEN);
11721189
return indexMetadataBuilder.build();
11731190
}

server/src/main/java/org/opensearch/common/settings/ClusterSettings.java

+1
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,7 @@ public void apply(Settings value, Settings current, Settings previous) {
709709
CpuBasedAdmissionControllerSettings.INDEXING_CPU_USAGE_LIMIT,
710710
CpuBasedAdmissionControllerSettings.SEARCH_CPU_USAGE_LIMIT,
711711
IndicesService.CLUSTER_INDEX_RESTRICT_REPLICATION_TYPE_SETTING,
712+
IndicesService.CLUSTER_REMOTE_STORE_PATH_PREFIX_OPTIMISED_SETTING,
712713

713714
// Concurrent segment search settings
714715
SearchService.CLUSTER_CONCURRENT_SEGMENT_SEARCH_SETTING,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.index.remote;
10+
11+
/**
12+
* Enumerates the types of remote store paths resolution techniques supported by OpenSearch.
13+
* For more information, see <a href="https://github.com/opensearch-project/OpenSearch/issues/12567">Github issue #12567</a>.
14+
*
15+
* @opensearch.internal
16+
*/
17+
public enum RemoteStorePathType {
18+
19+
FIXED,
20+
HASHED_PREFIX;
21+
22+
public static RemoteStorePathType parseString(String remoteStorePathType) {
23+
try {
24+
return RemoteStorePathType.valueOf(remoteStorePathType);
25+
} catch (IllegalArgumentException e) {
26+
throw new IllegalArgumentException("Could not parse RemoteStorePathType for [" + remoteStorePathType + "]");
27+
} catch (NullPointerException npe) {
28+
// return a default value for null input
29+
return FIXED;
30+
}
31+
}
32+
33+
/**
34+
* This string is used as key for storing information in the custom data in index settings.
35+
*/
36+
public static final String NAME = "path_type";
37+
}

server/src/main/java/org/opensearch/indices/IndicesService.java

+11
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,17 @@ public class IndicesService extends AbstractLifecycleComponent
314314
Property.Final
315315
);
316316

317+
/**
318+
* This setting is used to enable the optimisation in prefix path which helps in achieving higher throughput and lesser
319+
* rate limiting by remote store providers. This setting is effective only for remote store enabled cluster.
320+
*/
321+
public static final Setting<Boolean> CLUSTER_REMOTE_STORE_PATH_PREFIX_OPTIMISED_SETTING = Setting.boolSetting(
322+
"cluster.remote_store.index.path.prefix.optimised",
323+
true,
324+
Property.NodeScope,
325+
Property.Dynamic
326+
);
327+
317328
/**
318329
* The node's settings.
319330
*/

0 commit comments

Comments
 (0)