12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
14
15
+ import re
15
16
import os
16
17
from cassandra .cluster import Cluster
17
18
@@ -561,18 +562,23 @@ def use_cluster(cluster_name, nodes, ipformat=None, start=True, workloads=None,
561
562
562
563
CCM_CLUSTER .set_dse_configuration_options (dse_options )
563
564
else :
564
- CCM_CLUSTER = CCMCluster (path , cluster_name , ** ccm_options )
565
+ ccm_cluster_clz = CCMCluster if Version (cassandra_version ) < Version ('4.1' ) else Cassandra41CCMCluster
566
+ CCM_CLUSTER = ccm_cluster_clz (path , cluster_name , ** ccm_options )
565
567
CCM_CLUSTER .set_configuration_options ({'start_native_transport' : True })
566
568
if Version (cassandra_version ) >= Version ('2.2' ):
567
569
CCM_CLUSTER .set_configuration_options ({'enable_user_defined_functions' : True })
568
570
if Version (cassandra_version ) >= Version ('3.0' ):
569
- CCM_CLUSTER .set_configuration_options ({'enable_scripted_user_defined_functions' : True })
570
- if Version (cassandra_version ) >= Version ('4.0-a' ):
571
+ # The config.yml option below is deprecated in C* 4.0 per CASSANDRA-17280
572
+ if Version (cassandra_version ) < Version ('4.0' ):
573
+ CCM_CLUSTER .set_configuration_options ({'enable_scripted_user_defined_functions' : True })
574
+ else :
575
+ # Cassandra version >= 4.0
571
576
CCM_CLUSTER .set_configuration_options ({
572
577
'enable_materialized_views' : True ,
573
578
'enable_sasi_indexes' : True ,
574
579
'enable_transient_replication' : True ,
575
580
})
581
+
576
582
common .switch_cluster (path , cluster_name )
577
583
CCM_CLUSTER .set_configuration_options (configuration_options )
578
584
CCM_CLUSTER .populate (nodes , ipformat = ipformat , use_single_interface = use_single_interface )
@@ -1011,3 +1017,38 @@ def __new__(cls, **kwargs):
1011
1017
kwargs ['allow_beta_protocol_version' ] = cls .DEFAULT_ALLOW_BETA
1012
1018
return Cluster (** kwargs )
1013
1019
1020
+ # Subclass of CCMCluster (i.e. ccmlib.cluster.Cluster) which transparently performs
1021
+ # conversion of cassandra.yml directives into something matching the new syntax
1022
+ # introduced by CASSANDRA-15234
1023
+ class Cassandra41CCMCluster (CCMCluster ):
1024
+ __test__ = False
1025
+ IN_MS_REGEX = re .compile ('^(\w+)_in_ms$' )
1026
+ IN_KB_REGEX = re .compile ('^(\w+)_in_kb$' )
1027
+ ENABLE_REGEX = re .compile ('^enable_(\w+)$' )
1028
+
1029
+ def _get_config_key (self , k , v ):
1030
+ if "." in k :
1031
+ return k
1032
+ m = self .IN_MS_REGEX .match (k )
1033
+ if m :
1034
+ return m .group (1 )
1035
+ m = self .ENABLE_REGEX .search (k )
1036
+ if m :
1037
+ return "%s_enabled" % (m .group (1 ))
1038
+ m = self .IN_KB_REGEX .match (k )
1039
+ if m :
1040
+ return m .group (1 )
1041
+ return k
1042
+
1043
+ def _get_config_val (self , k , v ):
1044
+ m = self .IN_MS_REGEX .match (k )
1045
+ if m :
1046
+ return "%sms" % (v )
1047
+ m = self .IN_KB_REGEX .match (k )
1048
+ if m :
1049
+ return "%sKiB" % (v )
1050
+ return v
1051
+
1052
+ def set_configuration_options (self , values = None , * args , ** kwargs ):
1053
+ new_values = {self ._get_config_key (k , str (v )):self ._get_config_val (k , str (v )) for (k ,v ) in values .items ()}
1054
+ super (Cassandra41CCMCluster , self ).set_configuration_options (values = new_values , * args , ** kwargs )
0 commit comments