37
37
import org .opensearch .cluster .node .DiscoveryNodes ;
38
38
import org .opensearch .cluster .service .ClusterManagerThrottlingException ;
39
39
import org .opensearch .cluster .service .ClusterService ;
40
+ import org .opensearch .common .UUIDs ;
40
41
import org .opensearch .common .action .ActionFuture ;
41
42
import org .opensearch .common .settings .Settings ;
42
43
import org .opensearch .common .settings .SettingsException ;
84
85
import static org .opensearch .node .remotestore .RemoteStoreNodeService .REMOTE_STORE_COMPATIBILITY_MODE_SETTING ;
85
86
import static org .opensearch .test .ClusterServiceUtils .createClusterService ;
86
87
import static org .opensearch .test .ClusterServiceUtils .setState ;
88
+ import static org .opensearch .test .VersionUtils .randomCompatibleVersion ;
89
+ import static org .opensearch .test .VersionUtils .randomOpenSearchVersion ;
90
+ import static org .hamcrest .Matchers .containsString ;
87
91
import static org .hamcrest .Matchers .equalTo ;
88
92
import static org .hamcrest .Matchers .instanceOf ;
89
93
@@ -711,26 +715,28 @@ public void testDontAllowSwitchingToStrictCompatibilityModeForMixedCluster() {
711
715
Settings nodeSettings = Settings .builder ().put (REMOTE_STORE_MIGRATION_EXPERIMENTAL , "true" ).build ();
712
716
FeatureFlags .initializeFeatureFlags (nodeSettings );
713
717
718
+ // request to change cluster compatibility mode to STRICT
719
+ Settings currentCompatibilityModeSettings = Settings .builder ()
720
+ .put (REMOTE_STORE_COMPATIBILITY_MODE_SETTING .getKey (), CompatibilityMode .MIXED )
721
+ .build ();
722
+ Settings intendedCompatibilityModeSettings = Settings .builder ()
723
+ .put (REMOTE_STORE_COMPATIBILITY_MODE_SETTING .getKey (), CompatibilityMode .STRICT )
724
+ .build ();
714
725
ClusterUpdateSettingsRequest request = new ClusterUpdateSettingsRequest ();
715
- request .persistentSettings (
716
- Settings .builder ().put (REMOTE_STORE_COMPATIBILITY_MODE_SETTING .getKey (), CompatibilityMode .STRICT ).build ()
717
- );
726
+ request .persistentSettings (intendedCompatibilityModeSettings );
718
727
719
- DiscoveryNode nonRemoteNode = getNonRemoteNode ();
720
- DiscoveryNode remoteNode = getRemoteNode ();
728
+ // mixed cluster (containing both remote and non-remote nodes)
729
+ DiscoveryNode nonRemoteNode1 = getNonRemoteNode ();
730
+ DiscoveryNode remoteNode1 = getRemoteNode ();
721
731
722
732
DiscoveryNodes discoveryNodes = DiscoveryNodes .builder ()
723
- .add (nonRemoteNode )
724
- .localNodeId (nonRemoteNode .getId ())
725
- .add (remoteNode )
726
- .localNodeId (remoteNode .getId ())
733
+ .add (nonRemoteNode1 )
734
+ .localNodeId (nonRemoteNode1 .getId ())
735
+ .add (remoteNode1 )
736
+ .localNodeId (remoteNode1 .getId ())
727
737
.build ();
728
738
729
- Settings mixedModeCompatibilitySettings = Settings .builder ()
730
- .put (REMOTE_STORE_COMPATIBILITY_MODE_SETTING .getKey (), CompatibilityMode .MIXED )
731
- .build ();
732
-
733
- Metadata metadata = Metadata .builder ().persistentSettings (mixedModeCompatibilitySettings ).build ();
739
+ Metadata metadata = Metadata .builder ().persistentSettings (currentCompatibilityModeSettings ).build ();
734
740
735
741
ClusterState clusterState = ClusterState .builder (ClusterName .DEFAULT ).metadata (metadata ).nodes (discoveryNodes ).build ();
736
742
@@ -742,5 +748,110 @@ public void testDontAllowSwitchingToStrictCompatibilityModeForMixedCluster() {
742
748
"can not switch to STRICT compatibility mode when the cluster contains both remote and non-remote nodes" ,
743
749
exception .getMessage ()
744
750
);
751
+
752
+ DiscoveryNode nonRemoteNode2 = getNonRemoteNode ();
753
+ DiscoveryNode remoteNode2 = getRemoteNode ();
754
+
755
+ // cluster with only non-remote nodes
756
+ discoveryNodes = DiscoveryNodes .builder ()
757
+ .add (nonRemoteNode1 )
758
+ .localNodeId (nonRemoteNode1 .getId ())
759
+ .add (nonRemoteNode2 )
760
+ .localNodeId (nonRemoteNode2 .getId ())
761
+ .build ();
762
+ ClusterState sameTypeClusterState = ClusterState .builder (clusterState ).nodes (discoveryNodes ).build ();
763
+ TransportClusterUpdateSettingsAction .validateCompatibilityModeSettingRequest (request , sameTypeClusterState );
764
+
765
+ // cluster with only non-remote nodes
766
+ discoveryNodes = DiscoveryNodes .builder ()
767
+ .add (remoteNode1 )
768
+ .localNodeId (remoteNode1 .getId ())
769
+ .add (remoteNode2 )
770
+ .localNodeId (remoteNode2 .getId ())
771
+ .build ();
772
+ sameTypeClusterState = ClusterState .builder (sameTypeClusterState ).nodes (discoveryNodes ).build ();
773
+ TransportClusterUpdateSettingsAction .validateCompatibilityModeSettingRequest (request , sameTypeClusterState );
774
+ }
775
+
776
+ public void testDontAllowSwitchingCompatibilityModeForClusterWithMultipleVersions () {
777
+ Settings nodeSettings = Settings .builder ().put (REMOTE_STORE_MIGRATION_EXPERIMENTAL , "true" ).build ();
778
+ FeatureFlags .initializeFeatureFlags (nodeSettings );
779
+
780
+ // request to change cluster compatibility mode
781
+ boolean toStrictMode = randomBoolean ();
782
+ Settings currentCompatibilityModeSettings = Settings .builder ()
783
+ .put (REMOTE_STORE_COMPATIBILITY_MODE_SETTING .getKey (), CompatibilityMode .MIXED )
784
+ .build ();
785
+ Settings intendedCompatibilityModeSettings = Settings .builder ()
786
+ .put (REMOTE_STORE_COMPATIBILITY_MODE_SETTING .getKey (), toStrictMode ? CompatibilityMode .STRICT : CompatibilityMode .MIXED )
787
+ .build ();
788
+ ClusterUpdateSettingsRequest request = new ClusterUpdateSettingsRequest ();
789
+ request .persistentSettings (intendedCompatibilityModeSettings );
790
+
791
+ // two different but compatible open search versions for the discovery nodes
792
+ final Version version1 = randomOpenSearchVersion (random ());
793
+ final Version version2 = randomCompatibleVersion (random (), version1 );
794
+
795
+ assert version1 .equals (version2 ) == false : "current nodes in the cluster must be of different versions" ;
796
+
797
+ DiscoveryNode discoveryNode1 = new DiscoveryNode (
798
+ UUIDs .base64UUID (),
799
+ buildNewFakeTransportAddress (),
800
+ toStrictMode ? remoteStoreNodeAttributes (SEGMENT_REPO , TRANSLOG_REPO ) : Collections .emptyMap (),
801
+ DiscoveryNodeRole .BUILT_IN_ROLES ,
802
+ version1
803
+ );
804
+ DiscoveryNode discoveryNode2 = new DiscoveryNode (
805
+ UUIDs .base64UUID (),
806
+ buildNewFakeTransportAddress (),
807
+ toStrictMode ? remoteStoreNodeAttributes (SEGMENT_REPO , TRANSLOG_REPO ) : Collections .emptyMap (),
808
+ DiscoveryNodeRole .BUILT_IN_ROLES ,
809
+ version2 // not same as discoveryNode1
810
+ );
811
+
812
+ DiscoveryNodes discoveryNodes = DiscoveryNodes .builder ()
813
+ .add (discoveryNode1 )
814
+ .localNodeId (discoveryNode1 .getId ())
815
+ .add (discoveryNode2 )
816
+ .localNodeId (discoveryNode2 .getId ())
817
+ .build ();
818
+
819
+ Metadata metadata = Metadata .builder ().persistentSettings (currentCompatibilityModeSettings ).build ();
820
+
821
+ ClusterState differentVersionClusterState = ClusterState .builder (ClusterName .DEFAULT )
822
+ .metadata (metadata )
823
+ .nodes (discoveryNodes )
824
+ .build ();
825
+
826
+ // changing compatibility mode when all nodes are not of the same version
827
+ final SettingsException exception = expectThrows (
828
+ SettingsException .class ,
829
+ () -> TransportClusterUpdateSettingsAction .validateCompatibilityModeSettingRequest (request , differentVersionClusterState )
830
+ );
831
+ assertThat (
832
+ exception .getMessage (),
833
+ containsString (
834
+ "can not change the compatibility mode when all the nodes in cluster are not of the same version. Present versions: ["
835
+ )
836
+ );
837
+
838
+ // changing compatibility mode when all nodes are of the same version
839
+ discoveryNode2 = new DiscoveryNode (
840
+ UUIDs .base64UUID (),
841
+ buildNewFakeTransportAddress (),
842
+ toStrictMode ? remoteStoreNodeAttributes (SEGMENT_REPO , TRANSLOG_REPO ) : Collections .emptyMap (),
843
+ DiscoveryNodeRole .BUILT_IN_ROLES ,
844
+ version1 // same as discoveryNode1
845
+ );
846
+ discoveryNodes = DiscoveryNodes .builder ()
847
+ .add (discoveryNode1 )
848
+ .localNodeId (discoveryNode1 .getId ())
849
+ .add (discoveryNode2 )
850
+ .localNodeId (discoveryNode2 .getId ())
851
+ .build ();
852
+
853
+ ClusterState sameVersionClusterState = ClusterState .builder (differentVersionClusterState ).nodes (discoveryNodes ).build ();
854
+ TransportClusterUpdateSettingsAction .validateCompatibilityModeSettingRequest (request , sameVersionClusterState );
745
855
}
856
+
746
857
}
0 commit comments