Skip to content

Commit 3f67648

Browse files
committed
Decouple remote state configuration
Signed-off-by: Sooraj Sinha <soosinha@amazon.com>
1 parent bbe790b commit 3f67648

File tree

4 files changed

+50
-14
lines changed

4 files changed

+50
-14
lines changed

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_REPLICATION_TYPE;
137137
import static org.opensearch.cluster.metadata.Metadata.DEFAULT_REPLICA_COUNT_SETTING;
138138
import static org.opensearch.indices.IndicesService.CLUSTER_REPLICATION_TYPE_SETTING;
139-
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.isRemoteStoreAttributePresent;
139+
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.isRemoteStoreSegmentOrTranslogAttributePresent;
140140

141141
/**
142142
* Service responsible for submitting create index requests
@@ -959,7 +959,7 @@ private static void updateReplicationStrategy(
959959
indexReplicationType = INDEX_REPLICATION_TYPE_SETTING.get(combinedTemplateSettings);
960960
} else if (CLUSTER_REPLICATION_TYPE_SETTING.exists(clusterSettings)) {
961961
indexReplicationType = CLUSTER_REPLICATION_TYPE_SETTING.get(clusterSettings);
962-
} else if (isRemoteStoreAttributePresent(clusterSettings)) {
962+
} else if (isRemoteStoreSegmentOrTranslogAttributePresent(clusterSettings)) {
963963
indexReplicationType = ReplicationType.SEGMENT;
964964
} else {
965965
indexReplicationType = CLUSTER_REPLICATION_TYPE_SETTING.getDefault(clusterSettings);
@@ -973,7 +973,7 @@ private static void updateReplicationStrategy(
973973
* @param clusterSettings cluster level settings
974974
*/
975975
private static void updateRemoteStoreSettings(Settings.Builder settingsBuilder, Settings clusterSettings) {
976-
if (isRemoteStoreAttributePresent(clusterSettings)) {
976+
if (isRemoteStoreSegmentOrTranslogAttributePresent(clusterSettings)) {
977977
settingsBuilder.put(SETTING_REMOTE_STORE_ENABLED, true)
978978
.put(
979979
SETTING_REMOTE_SEGMENT_STORE_REPOSITORY,
@@ -1565,7 +1565,7 @@ public static void validateRefreshIntervalSettings(Settings requestSettings, Clu
15651565
* @param clusterSettings cluster setting
15661566
*/
15671567
static void validateTranslogDurabilitySettings(Settings requestSettings, ClusterSettings clusterSettings, Settings settings) {
1568-
if (isRemoteStoreAttributePresent(settings) == false
1568+
if (isRemoteStoreSegmentOrTranslogAttributePresent(settings) == false
15691569
|| IndexSettings.INDEX_TRANSLOG_DURABILITY_SETTING.exists(requestSettings) == false
15701570
|| clusterSettings.get(IndicesService.CLUSTER_REMOTE_INDEX_RESTRICT_ASYNC_DURABILITY_SETTING) == false) {
15711571
return;

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

+37-9
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,20 @@
1313
import org.opensearch.cluster.metadata.RepositoryMetadata;
1414
import org.opensearch.cluster.node.DiscoveryNode;
1515
import org.opensearch.common.settings.Settings;
16+
import org.opensearch.core.common.Strings;
1617
import org.opensearch.gateway.remote.RemoteClusterStateService;
1718
import org.opensearch.node.Node;
1819
import org.opensearch.repositories.blobstore.BlobStoreRepository;
1920

2021
import java.util.ArrayList;
21-
import java.util.HashSet;
2222
import java.util.Iterator;
2323
import java.util.List;
2424
import java.util.Locale;
2525
import java.util.Map;
2626
import java.util.Objects;
2727
import java.util.Set;
2828
import java.util.stream.Collectors;
29+
import java.util.stream.Stream;
2930

3031
/**
3132
* This is an abstraction for validating and storing information specific to remote backed storage nodes.
@@ -131,12 +132,16 @@ private RepositoryMetadata buildRepositoryMetadata(DiscoveryNode node, String na
131132
}
132133

133134
private RepositoriesMetadata buildRepositoriesMetadata(DiscoveryNode node) {
135+
validateSegmentAttributes(node);
134136
List<RepositoryMetadata> repositoryMetadataList = new ArrayList<>();
135-
Set<String> repositoryNames = new HashSet<>();
136-
137-
repositoryNames.add(validateAttributeNonNull(node, REMOTE_STORE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEY));
138-
repositoryNames.add(validateAttributeNonNull(node, REMOTE_STORE_TRANSLOG_REPOSITORY_NAME_ATTRIBUTE_KEY));
139-
repositoryNames.add(validateAttributeNonNull(node, REMOTE_STORE_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_KEY));
137+
Set<String> repositoryNames = Stream.of(
138+
REMOTE_STORE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEY,
139+
REMOTE_STORE_TRANSLOG_REPOSITORY_NAME_ATTRIBUTE_KEY,
140+
REMOTE_STORE_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_KEY
141+
)
142+
.map(repoKey -> node.getAttributes().get(repoKey))
143+
.filter(repositoryName -> Strings.isNullOrEmpty(repositoryName) == false)
144+
.collect(Collectors.toSet());
140145

141146
for (String repositoryName : repositoryNames) {
142147
repositoryMetadataList.add(buildRepositoryMetadata(node, repositoryName));
@@ -145,12 +150,31 @@ private RepositoriesMetadata buildRepositoriesMetadata(DiscoveryNode node) {
145150
return new RepositoriesMetadata(repositoryMetadataList);
146151
}
147152

153+
private void validateSegmentAttributes(DiscoveryNode node) {
154+
if (node.getAttributes().containsKey(REMOTE_STORE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEY)
155+
|| node.getAttributes().containsKey(REMOTE_STORE_TRANSLOG_REPOSITORY_NAME_ATTRIBUTE_KEY)) {
156+
validateAttributeNonNull(node, REMOTE_STORE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEY);
157+
validateAttributeNonNull(node, REMOTE_STORE_TRANSLOG_REPOSITORY_NAME_ATTRIBUTE_KEY);
158+
}
159+
}
160+
148161
public static boolean isRemoteStoreAttributePresent(Settings settings) {
149162
return settings.getByPrefix(Node.NODE_ATTRIBUTES.getKey() + REMOTE_STORE_NODE_ATTRIBUTE_KEY_PREFIX).isEmpty() == false;
150163
}
151164

165+
public static boolean isRemoteStoreSegmentOrTranslogAttributePresent(Settings settings) {
166+
return settings.getByPrefix(Node.NODE_ATTRIBUTES.getKey() + REMOTE_STORE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEY).isEmpty() == false
167+
|| settings.getByPrefix(Node.NODE_ATTRIBUTES.getKey() + REMOTE_STORE_TRANSLOG_REPOSITORY_NAME_ATTRIBUTE_KEY).isEmpty() == false;
168+
}
169+
170+
public static boolean isRemoteClusterStateAttributePresent(Settings settings) {
171+
return settings.getByPrefix(Node.NODE_ATTRIBUTES.getKey() + REMOTE_STORE_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_KEY)
172+
.isEmpty() == false;
173+
}
174+
152175
public static boolean isRemoteStoreClusterStateEnabled(Settings settings) {
153-
return RemoteClusterStateService.REMOTE_CLUSTER_STATE_ENABLED_SETTING.get(settings) && isRemoteStoreAttributePresent(settings);
176+
return RemoteClusterStateService.REMOTE_CLUSTER_STATE_ENABLED_SETTING.get(settings)
177+
&& isRemoteClusterStateAttributePresent(settings);
154178
}
155179

156180
public RepositoriesMetadata getRepositoriesMetadata() {
@@ -175,8 +199,12 @@ public int hashCode() {
175199

176200
@Override
177201
public boolean equals(Object o) {
178-
if (this == o) return true;
179-
if (o == null || getClass() != o.getClass()) return false;
202+
if (this == o) {
203+
return true;
204+
}
205+
if (o == null || getClass() != o.getClass()) {
206+
return false;
207+
}
180208

181209
RemoteStoreNodeAttribute that = (RemoteStoreNodeAttribute) o;
182210

server/src/test/java/org/opensearch/cluster/coordination/JoinTaskExecutorTests.java

+8
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,14 @@ public void testPreventJoinClusterWithRemoteStoreNodeWithPartialAttributesJoinin
521521
);
522522
assertTrue(
523523
e.getMessage().equals("joining node [" + joiningNode + "] doesn't have the node attribute [" + nodeAttribute.getKey() + "]")
524+
|| e.getMessage()
525+
.equals(
526+
"a remote store node ["
527+
+ joiningNode
528+
+ "] is trying to join a remote store cluster with incompatible node attributes in comparison with existing node ["
529+
+ currentState.getNodes().getNodes().values().stream().findFirst().get()
530+
+ "]"
531+
)
524532
);
525533

526534
remoteStoreNodeAttributes.put(nodeAttribute.getKey(), nodeAttribute.getValue());

server/src/test/java/org/opensearch/cluster/metadata/MetadataCreateIndexServiceTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1898,7 +1898,7 @@ public void testAsyncDurabilityThrowsExceptionWhenRestrictSettingTrue() {
18981898
request,
18991899
Settings.EMPTY,
19001900
null,
1901-
Settings.builder().put("node.attr.remote_store.setting", "test").build(),
1901+
Settings.builder().put("node.attr.remote_store.segment.repository", "test").build(),
19021902
IndexScopedSettings.DEFAULT_SCOPED_SETTINGS,
19031903
randomShardLimitService(),
19041904
Collections.emptySet(),

0 commit comments

Comments
 (0)