Skip to content

Commit 9cda00f

Browse files
committed
Incorporate feedback from @shwetathareja
Signed-off-by: Michael Froh <[email protected]>
1 parent 892b0a0 commit 9cda00f

File tree

5 files changed

+36
-7
lines changed

5 files changed

+36
-7
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public MetadataCreateIndexService(
227227
// Task is onboarded for throttling, it will get retried from associated TransportClusterManagerNodeAction.
228228
createIndexTaskKey = clusterService.registerClusterManagerTask(CREATE_INDEX, true);
229229
Supplier<Version> minNodeVersionSupplier = () -> clusterService.state().nodes().getMinNodeVersion();
230-
remoteStoreCustomMetadataResolver = RemoteStoreNodeAttribute.isRemoteClusterStateConfigured(settings)
230+
remoteStoreCustomMetadataResolver = RemoteStoreNodeAttribute.isSegmentRepoConfigured(settings)
231231
? new RemoteStoreCustomMetadataResolver(remoteStoreSettings, minNodeVersionSupplier, repositoriesServiceSupplier, settings)
232232
: null;
233233
}

server/src/main/java/org/opensearch/cluster/node/DiscoveryNode.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,14 @@ public boolean isSearchNode() {
503503
* @return true if the node contains remote store node attributes, false otherwise
504504
*/
505505
public boolean isRemoteStoreNode() {
506+
return isClusterStateRepoConfigured(this.getAttributes()) && RemoteStoreNodeAttribute.isSegmentRepoConfigured(this.getAttributes());
507+
}
508+
509+
/**
510+
* Returns whether the node is a remote segment store node.
511+
* @return true if the node contains remote segment store node attributes, false otherwise
512+
*/
513+
public boolean isRemoteSegmentStoreNode() {
506514
return RemoteStoreNodeAttribute.isSegmentRepoConfigured(this.getAttributes());
507515
}
508516

server/src/main/java/org/opensearch/index/IndexService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ public synchronized IndexShard createShard(
673673
Store remoteStore = null;
674674
Directory remoteDirectory = null;
675675
boolean seedRemote = false;
676-
if (targetNode.isRemoteStoreNode()) {
676+
if (targetNode.isRemoteSegmentStoreNode()) {
677677
if (this.indexSettings.isRemoteStoreEnabled()) {
678678
remoteDirectory = remoteDirectoryFactory.newDirectory(this.indexSettings, path);
679679
} else {

server/src/main/java/org/opensearch/index/shard/IndexShard.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ public boolean shouldSeedRemoteStore() {
587587
public Function<String, Boolean> isShardOnRemoteEnabledNode = nodeId -> {
588588
DiscoveryNode node = discoveryNodes.get(nodeId);
589589
if (node != null) {
590-
return node.isRemoteStoreNode();
590+
return node.isRemoteSegmentStoreNode();
591591
}
592592
return false;
593593
};

server/src/main/java/org/opensearch/node/remotestore/RemoteStoreNodeAttribute.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public class RemoteStoreNodeAttribute {
8181
REMOTE_TRANSLOG_REPOSITORY_NAME_ATTRIBUTE_KEYS
8282
);
8383

84-
public static final String REMOTE_STORE_SEGMENTS_ONLY_ATTRIBUTE_KEY = "remote_store.segments_only";
84+
public static final String REMOTE_STORE_MODE_KEY = "remote_store.mode";
8585

8686
/**
8787
* Creates a new {@link RemoteStoreNodeAttribute}
@@ -192,11 +192,23 @@ private static Tuple<String, String> getValue(Map<String, String> attributes, Li
192192
return null;
193193
}
194194

195+
private enum RemoteStoreMode {
196+
SEGMENTS_ONLY,
197+
DEFAULT
198+
}
199+
195200
private Map<String, String> getValidatedRepositoryNames(DiscoveryNode node) {
196201
Set<Tuple<String, String>> repositoryNames = new HashSet<>();
197-
if (containsKey(node.getAttributes(), REMOTE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEYS)
198-
&& containsKey(node.getAttributes(), List.of(REMOTE_STORE_SEGMENTS_ONLY_ATTRIBUTE_KEY))
199-
&& "true".equals(node.getAttributes().get(REMOTE_STORE_SEGMENTS_ONLY_ATTRIBUTE_KEY).toLowerCase(Locale.ROOT))) {
202+
RemoteStoreMode remoteStoreMode = RemoteStoreMode.DEFAULT;
203+
if (containsKey(node.getAttributes(), List.of(REMOTE_STORE_MODE_KEY))) {
204+
String mode = node.getAttributes().get(REMOTE_STORE_MODE_KEY);
205+
if (mode != null && mode.equalsIgnoreCase(RemoteStoreMode.SEGMENTS_ONLY.name())) {
206+
remoteStoreMode = RemoteStoreMode.SEGMENTS_ONLY;
207+
} else if (mode != null && mode.equalsIgnoreCase(RemoteStoreMode.DEFAULT.name()) == false) {
208+
throw new IllegalStateException("Unknown remote store mode [" + mode + "] for node [" + node + "]");
209+
}
210+
}
211+
if (remoteStoreMode == RemoteStoreMode.SEGMENTS_ONLY) {
200212
repositoryNames.add(validateAttributeNonNull(node, REMOTE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEYS));
201213
} else if (containsKey(node.getAttributes(), REMOTE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEYS)
202214
|| containsKey(node.getAttributes(), REMOTE_TRANSLOG_REPOSITORY_NAME_ATTRIBUTE_KEYS)) {
@@ -207,6 +219,15 @@ && containsKey(node.getAttributes(), List.of(REMOTE_STORE_SEGMENTS_ONLY_ATTRIBUT
207219
repositoryNames.add(validateAttributeNonNull(node, REMOTE_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_KEYS));
208220
}
209221
if (containsKey(node.getAttributes(), REMOTE_ROUTING_TABLE_REPOSITORY_NAME_ATTRIBUTE_KEYS)) {
222+
if (remoteStoreMode == RemoteStoreMode.SEGMENTS_ONLY) {
223+
throw new IllegalStateException(
224+
"Cannot set "
225+
+ REMOTE_ROUTING_TABLE_REPOSITORY_NAME_ATTRIBUTE_KEYS
226+
+ " attributes when remote store mode is set to segments only for node ["
227+
+ node
228+
+ "]"
229+
);
230+
}
210231
repositoryNames.add(validateAttributeNonNull(node, REMOTE_ROUTING_TABLE_REPOSITORY_NAME_ATTRIBUTE_KEYS));
211232
}
212233

0 commit comments

Comments
 (0)