Skip to content

Commit 48a5373

Browse files
committed
relaxing the join validation for nodes which have only store disabled but only publication enabled
Signed-off-by: Rajiv Kumar Vaidyanathan <[email protected]>
1 parent 15ff668 commit 48a5373

File tree

9 files changed

+41
-65
lines changed

9 files changed

+41
-65
lines changed

server/src/main/java/org/opensearch/cluster/coordination/JoinTaskExecutor.java

+10-12
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ private static void ensureRemoteClusterStateNodesCompatibility(DiscoveryNode joi
514514
List<String> reposToValidate = new ArrayList<>(2);
515515
reposToValidate.add(RemoteStoreNodeAttribute.REMOTE_STORE_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_KEY);
516516
reposToValidate.add(RemoteStoreNodeAttribute.REMOTE_STORE_ROUTING_TABLE_REPOSITORY_NAME_ATTRIBUTE_KEY);
517-
ensureRemoteStoreNodesCompatibility(joiningNode, remotePublicationNode.get(), reposToValidate);
517+
ensureRepositoryCompatibility(joiningNode, remotePublicationNode.get(), reposToValidate);
518518
}
519519
}
520520

@@ -620,17 +620,15 @@ private static void ensureRepositoryCompatibility(DiscoveryNode joiningNode, Dis
620620
RemoteStoreNodeAttribute joiningRemoteStoreNodeAttribute = new RemoteStoreNodeAttribute(joiningNode);
621621
RemoteStoreNodeAttribute existingRemoteStoreNodeAttribute = new RemoteStoreNodeAttribute(existingNode);
622622

623-
for (String repoToValidate : reposToValidate) {
624-
if (existingRemoteStoreNodeAttribute.equalsForRepositories(joiningRemoteStoreNodeAttribute, reposToValidate) == false) {
625-
throw new IllegalStateException(
626-
"a remote store node ["
627-
+ joiningNode
628-
+ "] is trying to join a remote store cluster with incompatible node attributes in "
629-
+ "comparison with existing node ["
630-
+ existingNode
631-
+ "]"
632-
);
633-
}
623+
if (existingRemoteStoreNodeAttribute.equalsForRepositories(joiningRemoteStoreNodeAttribute, reposToValidate) == false) {
624+
throw new IllegalStateException(
625+
"a remote store node ["
626+
+ joiningNode
627+
+ "] is trying to join a remote store cluster with incompatible node attributes in "
628+
+ "comparison with existing node ["
629+
+ existingNode
630+
+ "]"
631+
);
634632
}
635633
}
636634

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

+18
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,24 @@ public boolean equalsIgnoreGenerationsWithRepoSkip(@Nullable RepositoriesMetadat
184184
.filter(repo -> !reposToSkip.contains(repo.name()))
185185
.collect(Collectors.toList());
186186

187+
return equalsRepository(currentRepositories, otherRepositories);
188+
}
189+
190+
public boolean equalsIgnoreGenerationsForRepo(@Nullable RepositoriesMetadata other, List<String> reposToValidate) {
191+
if (other == null) {
192+
return false;
193+
}
194+
List<RepositoryMetadata> currentRepositories = repositories.stream()
195+
.filter(repo -> reposToValidate.contains(repo.name()))
196+
.collect(Collectors.toList());
197+
List<RepositoryMetadata> otherRepositories = other.repositories.stream()
198+
.filter(repo -> reposToValidate.contains(repo.name()))
199+
.collect(Collectors.toList());
200+
201+
return equalsRepository(currentRepositories, otherRepositories);
202+
}
203+
204+
public static boolean equalsRepository(List<RepositoryMetadata> currentRepositories, List<RepositoryMetadata> otherRepositories) {
187205
if (otherRepositories.size() != currentRepositories.size()) {
188206
return false;
189207
}

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

+2-8
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_NODE_ATTRIBUTE_KEY_PREFIX;
6666
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_ROUTING_TABLE_REPOSITORY_NAME_ATTRIBUTE_KEY;
6767
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEY;
68-
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_TRANSLOG_REPOSITORY_NAME_ATTRIBUTE_KEY;
6968

7069
/**
7170
* A discovery node represents a node that is part of the cluster.
@@ -475,13 +474,8 @@ public boolean isSearchNode() {
475474
* @return true if the node contains remote store node attributes, false otherwise
476475
*/
477476
public boolean isRemoteStoreNode() {
478-
return this.getAttributes()
479-
.keySet()
480-
.stream()
481-
.anyMatch(
482-
key -> key.startsWith(REMOTE_STORE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEY)
483-
|| key.startsWith(REMOTE_STORE_TRANSLOG_REPOSITORY_NAME_ATTRIBUTE_KEY)
484-
);
477+
return this.getAttributes().keySet().stream().anyMatch(key -> key.equals(REMOTE_STORE_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_KEY))
478+
&& this.getAttributes().keySet().stream().anyMatch(key -> key.equals(REMOTE_STORE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEY));
485479
}
486480

487481
/**

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

+1-25
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import org.opensearch.repositories.blobstore.BlobStoreRepository;
2020

2121
import java.util.ArrayList;
22-
import java.util.Comparator;
2322
import java.util.HashMap;
2423
import java.util.HashSet;
2524
import java.util.Iterator;
@@ -270,30 +269,7 @@ public boolean equalsForRepositories(Object otherNode, List<String> repositoryTo
270269
if (otherNode == null || getClass() != otherNode.getClass()) return false;
271270

272271
RemoteStoreNodeAttribute other = (RemoteStoreNodeAttribute) otherNode;
273-
List<RepositoryMetadata> currentRepositories = this.repositoriesMetadata.repositories()
274-
.stream()
275-
.filter(repos -> repositoryToValidate.contains(repos.name()))
276-
.collect(Collectors.toList());
277-
278-
List<RepositoryMetadata> otherRepositories = other.repositoriesMetadata.repositories()
279-
.stream()
280-
.filter(repos -> repositoryToValidate.contains(repos.name()))
281-
.collect(Collectors.toList());
282-
283-
if (otherRepositories.size() != currentRepositories.size()) {
284-
return false;
285-
}
286-
// Sort repos by name for ordered comparison
287-
Comparator<RepositoryMetadata> compareByName = (o1, o2) -> o1.name().compareTo(o2.name());
288-
currentRepositories.sort(compareByName);
289-
otherRepositories.sort(compareByName);
290-
291-
for (int i = 0; i < currentRepositories.size(); i++) {
292-
if (currentRepositories.get(i).equalsIgnoreGenerations(otherRepositories.get(i)) == false) {
293-
return false;
294-
}
295-
}
296-
return true;
272+
return this.getRepositoriesMetadata().equalsIgnoreGenerationsForRepo(other.repositoriesMetadata, repositoryToValidate);
297273
}
298274

299275
@Override

server/src/test/java/org/opensearch/action/support/clustermanager/TransportClusterManagerNodeActionTests.java

+2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
import java.util.concurrent.atomic.AtomicBoolean;
8686

8787
import static org.opensearch.index.remote.RemoteMigrationIndexMetadataUpdaterTests.createIndexMetadataWithRemoteStoreSettings;
88+
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_KEY;
8889
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEY;
8990
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_TRANSLOG_REPOSITORY_NAME_ATTRIBUTE_KEY;
9091
import static org.opensearch.node.remotestore.RemoteStoreNodeService.REMOTE_STORE_COMPATIBILITY_MODE_SETTING;
@@ -901,6 +902,7 @@ public void testDontAllowSwitchingCompatibilityModeForClusterWithMultipleVersion
901902

902903
private Map<String, String> getRemoteStoreNodeAttributes() {
903904
Map<String, String> remoteStoreNodeAttributes = new HashMap<>();
905+
remoteStoreNodeAttributes.put(REMOTE_STORE_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_KEY, "my-cluster-repo-1");
904906
remoteStoreNodeAttributes.put(REMOTE_STORE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEY, "my-segment-repo-1");
905907
remoteStoreNodeAttributes.put(REMOTE_STORE_TRANSLOG_REPOSITORY_NAME_ATTRIBUTE_KEY, "my-translog-repo-1");
906908
return remoteStoreNodeAttributes;

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

+2-20
Original file line numberDiff line numberDiff line change
@@ -628,16 +628,7 @@ public void testPreventJoinClusterWithRemoteStateNodeJoiningRemoteStoreCluster()
628628
IllegalStateException.class,
629629
() -> JoinTaskExecutor.ensureNodesCompatibility(joiningNode, currentState.getNodes(), currentState.metadata())
630630
);
631-
assertTrue(
632-
e.getMessage()
633-
.equals(
634-
"a remote store node ["
635-
+ joiningNode
636-
+ "] is trying to join a remote store cluster with incompatible node attributes in comparison with existing node ["
637-
+ currentState.getNodes().getNodes().values().stream().findFirst().get()
638-
+ "]"
639-
)
640-
);
631+
assertTrue(e.getMessage().equals("a non remote store node [" + joiningNode + "] is trying to join a remote store cluster"));
641632
}
642633

643634
public void testPreventJoinClusterWithRemoteStoreNodeJoiningRemoteStateCluster() {
@@ -657,16 +648,7 @@ public void testPreventJoinClusterWithRemoteStoreNodeJoiningRemoteStateCluster()
657648
IllegalStateException.class,
658649
() -> JoinTaskExecutor.ensureNodesCompatibility(joiningNode, currentState.getNodes(), currentState.metadata())
659650
);
660-
assertTrue(
661-
e.getMessage()
662-
.equals(
663-
"a remote store node ["
664-
+ joiningNode
665-
+ "] is trying to join a remote store cluster with incompatible node attributes in comparison with existing node ["
666-
+ currentState.getNodes().getNodes().values().stream().findFirst().get()
667-
+ "]"
668-
)
669-
);
651+
assertTrue(e.getMessage().equals("a remote store node [" + joiningNode + "] is trying to join a non remote store cluster"));
670652
}
671653

672654
public void testUpdatesClusterStateWithSingleNodeCluster() throws Exception {

server/src/test/java/org/opensearch/cluster/routing/allocation/RemoteStoreMigrationAllocationDeciderTests.java

+2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_REMOTE_TRANSLOG_STORE_REPOSITORY;
6969
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_REPLICATION_TYPE;
7070
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_KEY;
71+
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEY;
7172
import static org.opensearch.node.remotestore.RemoteStoreNodeService.Direction.NONE;
7273
import static org.opensearch.node.remotestore.RemoteStoreNodeService.Direction.REMOTE_STORE;
7374
import static org.opensearch.node.remotestore.RemoteStoreNodeService.MIGRATION_DIRECTION_SETTING;
@@ -617,6 +618,7 @@ private DiscoveryNode getRemoteNode() {
617618
REMOTE_STORE_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_KEY,
618619
"REMOTE_STORE_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_VALUE"
619620
);
621+
attributes.put(REMOTE_STORE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEY, "REMOTE_STORE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_VALUE");
620622
return new DiscoveryNode(
621623
UUIDs.base64UUID(),
622624
buildNewFakeTransportAddress(),

server/src/test/java/org/opensearch/index/remote/RemoteStoreUtilsTests.java

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import static org.opensearch.index.store.RemoteSegmentStoreDirectory.MetadataFilenameUtils.METADATA_PREFIX;
6161
import static org.opensearch.index.store.RemoteSegmentStoreDirectory.MetadataFilenameUtils.SEPARATOR;
6262
import static org.opensearch.index.translog.transfer.TranslogTransferMetadata.METADATA_SEPARATOR;
63+
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_KEY;
6364
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEY;
6465
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_TRANSLOG_REPOSITORY_NAME_ATTRIBUTE_KEY;
6566
import static org.opensearch.node.remotestore.RemoteStoreNodeService.REMOTE_STORE_COMPATIBILITY_MODE_SETTING;
@@ -533,6 +534,7 @@ private RoutingTable createRoutingTableAllShardsStarted(
533534

534535
private Map<String, String> getRemoteStoreNodeAttributes() {
535536
Map<String, String> remoteStoreNodeAttributes = new HashMap<>();
537+
remoteStoreNodeAttributes.put(REMOTE_STORE_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_KEY, "my-cluster-repo-1");
536538
remoteStoreNodeAttributes.put(REMOTE_STORE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEY, "my-segment-repo-1");
537539
remoteStoreNodeAttributes.put(REMOTE_STORE_TRANSLOG_REPOSITORY_NAME_ATTRIBUTE_KEY, "my-translog-repo-1");
538540
return remoteStoreNodeAttributes;

test/framework/src/main/java/org/opensearch/index/shard/IndexShardTestUtils.java

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.Map;
2222

2323
public class IndexShardTestUtils {
24+
public static final String MOCK_STATE_REPO_NAME = "state-test-repo";
2425
public static final String MOCK_SEGMENT_REPO_NAME = "segment-test-repo";
2526
public static final String MOCK_TLOG_REPO_NAME = "tlog-test-repo";
2627

@@ -37,6 +38,7 @@ public static DiscoveryNode getFakeDiscoNode(String id) {
3738

3839
public static DiscoveryNode getFakeRemoteEnabledNode(String id) {
3940
Map<String, String> remoteNodeAttributes = new HashMap<String, String>();
41+
remoteNodeAttributes.put(RemoteStoreNodeAttribute.REMOTE_STORE_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_KEY, MOCK_STATE_REPO_NAME);
4042
remoteNodeAttributes.put(RemoteStoreNodeAttribute.REMOTE_STORE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEY, MOCK_SEGMENT_REPO_NAME);
4143
remoteNodeAttributes.put(RemoteStoreNodeAttribute.REMOTE_STORE_TRANSLOG_REPOSITORY_NAME_ATTRIBUTE_KEY, MOCK_TLOG_REPO_NAME);
4244
return new DiscoveryNode(

0 commit comments

Comments
 (0)