@@ -377,7 +377,8 @@ public void testJoinClusterWithNonRemoteStoreNodeJoining() {
377
377
}
378
378
379
379
public void testJoinClusterWithRemoteStoreNodeJoining () {
380
- DiscoveryNode joiningNode = newDiscoveryNode (remoteStoreNodeAttributes (SEGMENT_REPO , TRANSLOG_REPO ));
380
+ Map <String , String > map = remoteStoreNodeAttributes (SEGMENT_REPO , TRANSLOG_REPO );
381
+ DiscoveryNode joiningNode = newDiscoveryNode (map );
381
382
ClusterState currentState = ClusterState .builder (ClusterName .DEFAULT )
382
383
.nodes (DiscoveryNodes .builder ().add (joiningNode ).build ())
383
384
.build ();
@@ -582,12 +583,94 @@ public void testPreventJoinClusterWithRemoteStoreNodeWithPartialAttributesJoinin
582
583
);
583
584
assertTrue (
584
585
e .getMessage ().equals ("joining node [" + joiningNode + "] doesn't have the node attribute [" + nodeAttribute .getKey () + "]" )
586
+ || e .getMessage ()
587
+ .equals (
588
+ "a remote store node ["
589
+ + joiningNode
590
+ + "] is trying to join a remote store cluster with incompatible node attributes in comparison with existing node ["
591
+ + currentState .getNodes ().getNodes ().values ().stream ().findFirst ().get ()
592
+ + "]"
593
+ )
585
594
);
586
595
587
596
remoteStoreNodeAttributes .put (nodeAttribute .getKey (), nodeAttribute .getValue ());
588
597
}
589
598
}
590
599
600
+ public void testJoinClusterWithRemoteStateNodeJoiningRemoteStateCluster () {
601
+ Map <String , String > existingNodeAttributes = remoteStateNodeAttributes (CLUSTER_STATE_REPO );
602
+ final DiscoveryNode existingNode = new DiscoveryNode (
603
+ UUIDs .base64UUID (),
604
+ buildNewFakeTransportAddress (),
605
+ existingNodeAttributes ,
606
+ DiscoveryNodeRole .BUILT_IN_ROLES ,
607
+ Version .CURRENT
608
+ );
609
+ ClusterState currentState = ClusterState .builder (ClusterName .DEFAULT )
610
+ .nodes (DiscoveryNodes .builder ().add (existingNode ).localNodeId (existingNode .getId ()).build ())
611
+ .build ();
612
+ DiscoveryNode joiningNode = newDiscoveryNode (remoteStateNodeAttributes (CLUSTER_STATE_REPO ));
613
+ JoinTaskExecutor .ensureNodesCompatibility (joiningNode , currentState .getNodes (), currentState .metadata ());
614
+ }
615
+
616
+ public void testPreventJoinClusterWithRemoteStateNodeJoiningRemoteStoreCluster () {
617
+ Map <String , String > existingNodeAttributes = remoteStoreNodeAttributes (SEGMENT_REPO , TRANSLOG_REPO );
618
+ final DiscoveryNode existingNode = new DiscoveryNode (
619
+ UUIDs .base64UUID (),
620
+ buildNewFakeTransportAddress (),
621
+ existingNodeAttributes ,
622
+ DiscoveryNodeRole .BUILT_IN_ROLES ,
623
+ Version .CURRENT
624
+ );
625
+ ClusterState currentState = ClusterState .builder (ClusterName .DEFAULT )
626
+ .nodes (DiscoveryNodes .builder ().add (existingNode ).localNodeId (existingNode .getId ()).build ())
627
+ .build ();
628
+ DiscoveryNode joiningNode = newDiscoveryNode (remoteStateNodeAttributes (CLUSTER_STATE_REPO ));
629
+ Exception e = assertThrows (
630
+ IllegalStateException .class ,
631
+ () -> JoinTaskExecutor .ensureNodesCompatibility (joiningNode , currentState .getNodes (), currentState .metadata ())
632
+ );
633
+ assertTrue (
634
+ e .getMessage ()
635
+ .equals (
636
+ "a remote store node ["
637
+ + joiningNode
638
+ + "] is trying to join a remote store cluster with incompatible node attributes in comparison with existing node ["
639
+ + currentState .getNodes ().getNodes ().values ().stream ().findFirst ().get ()
640
+ + "]"
641
+ )
642
+ );
643
+ }
644
+
645
+ public void testPreventJoinClusterWithRemoteStoreNodeJoiningRemoteStateCluster () {
646
+ Map <String , String > existingNodeAttributes = remoteStateNodeAttributes (CLUSTER_STATE_REPO );
647
+ final DiscoveryNode existingNode = new DiscoveryNode (
648
+ UUIDs .base64UUID (),
649
+ buildNewFakeTransportAddress (),
650
+ existingNodeAttributes ,
651
+ DiscoveryNodeRole .BUILT_IN_ROLES ,
652
+ Version .CURRENT
653
+ );
654
+ ClusterState currentState = ClusterState .builder (ClusterName .DEFAULT )
655
+ .nodes (DiscoveryNodes .builder ().add (existingNode ).localNodeId (existingNode .getId ()).build ())
656
+ .build ();
657
+ DiscoveryNode joiningNode = newDiscoveryNode (remoteStoreNodeAttributes (SEGMENT_REPO , TRANSLOG_REPO ));
658
+ Exception e = assertThrows (
659
+ IllegalStateException .class ,
660
+ () -> JoinTaskExecutor .ensureNodesCompatibility (joiningNode , currentState .getNodes (), currentState .metadata ())
661
+ );
662
+ assertTrue (
663
+ e .getMessage ()
664
+ .equals (
665
+ "a remote store node ["
666
+ + joiningNode
667
+ + "] is trying to join a remote store cluster with incompatible node attributes in comparison with existing node ["
668
+ + currentState .getNodes ().getNodes ().values ().stream ().findFirst ().get ()
669
+ + "]"
670
+ )
671
+ );
672
+ }
673
+
591
674
public void testUpdatesClusterStateWithSingleNodeCluster () throws Exception {
592
675
Map <String , String > remoteStoreNodeAttributes = remoteStoreNodeAttributes (SEGMENT_REPO , TRANSLOG_REPO );
593
676
final AllocationService allocationService = mock (AllocationService .class );
@@ -869,6 +952,23 @@ private Map<String, String> remoteStoreNodeAttributes(String segmentRepoName, St
869
952
REMOTE_STORE_REPOSITORY_SETTINGS_ATTRIBUTE_KEY_PREFIX ,
870
953
translogRepoName
871
954
);
955
+
956
+ return new HashMap <>() {
957
+ {
958
+ put (REMOTE_STORE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEY , segmentRepoName );
959
+ put (segmentRepositoryTypeAttributeKey , "s3" );
960
+ put (segmentRepositorySettingsAttributeKeyPrefix + "bucket" , "segment_bucket" );
961
+ put (segmentRepositorySettingsAttributeKeyPrefix + "base_path" , "/segment/path" );
962
+ put (REMOTE_STORE_TRANSLOG_REPOSITORY_NAME_ATTRIBUTE_KEY , translogRepoName );
963
+ putIfAbsent (translogRepositoryTypeAttributeKey , "s3" );
964
+ putIfAbsent (translogRepositorySettingsAttributeKeyPrefix + "bucket" , "translog_bucket" );
965
+ putIfAbsent (translogRepositorySettingsAttributeKeyPrefix + "base_path" , "/translog/path" );
966
+ putAll (remoteStateNodeAttributes (clusterStateRepo ));
967
+ }
968
+ };
969
+ }
970
+
971
+ private Map <String , String > remoteStateNodeAttributes (String clusterStateRepo ) {
872
972
String clusterStateRepositoryTypeAttributeKey = String .format (
873
973
Locale .getDefault (),
874
974
REMOTE_STORE_REPOSITORY_TYPE_ATTRIBUTE_KEY_FORMAT ,
@@ -882,14 +982,6 @@ private Map<String, String> remoteStoreNodeAttributes(String segmentRepoName, St
882
982
883
983
return new HashMap <>() {
884
984
{
885
- put (REMOTE_STORE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEY , segmentRepoName );
886
- put (segmentRepositoryTypeAttributeKey , "s3" );
887
- put (segmentRepositorySettingsAttributeKeyPrefix + "bucket" , "segment_bucket" );
888
- put (segmentRepositorySettingsAttributeKeyPrefix + "base_path" , "/segment/path" );
889
- put (REMOTE_STORE_TRANSLOG_REPOSITORY_NAME_ATTRIBUTE_KEY , translogRepoName );
890
- putIfAbsent (translogRepositoryTypeAttributeKey , "s3" );
891
- putIfAbsent (translogRepositorySettingsAttributeKeyPrefix + "bucket" , "translog_bucket" );
892
- putIfAbsent (translogRepositorySettingsAttributeKeyPrefix + "base_path" , "/translog/path" );
893
985
put (REMOTE_STORE_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_KEY , clusterStateRepo );
894
986
putIfAbsent (clusterStateRepositoryTypeAttributeKey , "s3" );
895
987
putIfAbsent (clusterStateRepositorySettingsAttributeKeyPrefix + "bucket" , "state_bucket" );
0 commit comments