Skip to content

Commit

Permalink
Add initial support for HCD
Browse files Browse the repository at this point in the history
  • Loading branch information
adejanovski committed May 22, 2024
1 parent d7f059e commit e835c51
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 9 deletions.
18 changes: 15 additions & 3 deletions apis/k8ssandra/v1alpha1/k8ssandracluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ type CassandraClusterTemplate struct {
ClusterName string `json:"clusterName,omitempty"`

// Server type: "cassandra" or "dse".
// +kubebuilder:validation:Enum=cassandra;dse
// +kubebuilder:validation:Enum=cassandra;dse;hcd
// +kubebuilder:default=cassandra
ServerType ServerDistribution `json:"serverType,omitempty"`
}
Expand Down Expand Up @@ -318,7 +318,7 @@ type DatacenterOptions struct {
// ServerVersion is the Cassandra or DSE version. The following versions are supported:
// - Cassandra: 3.11.X, 4.X.X and 5.X.X
// - DSE: 6.8.X, 7.x.x
// +kubebuilder:validation:Pattern=(6\.8\.\d+)|(3\.11\.\d+)|(4\.\d+\.\d+)|(5\.\d+\.\d+)|(7\.\d+\.\d+)
// - HCD: 1.0.x
ServerVersion string `json:"serverVersion,omitempty"`

// ServerImage is the image for the cassandra container. Note that this should be a
Expand Down Expand Up @@ -530,12 +530,24 @@ type ServerDistribution string
const (
ServerDistributionCassandra = ServerDistribution("cassandra")
ServerDistributionDse = ServerDistribution("dse")
ServerDistributionHcd = ServerDistribution("hcd")
)

func (sd *ServerDistribution) IsCassandra() bool {
return *sd == ServerDistributionCassandra || *sd == ServerDistributionHcd
}

func (sd *ServerDistribution) IsDse() bool {
return *sd == ServerDistributionDse
}

func (kc *K8ssandraCluster) DefaultNumTokens(serverVersion *semver.Version) float64 {
if kc.Spec.Cassandra.ServerType == ServerDistributionCassandra && serverVersion.Major() == 3 {
if kc.Spec.Cassandra.ServerType.IsCassandra() && serverVersion.Major() == 3 {
return float64(256)
}
if kc.Spec.Cassandra.ServerType.IsCassandra() {
return float64(8)
}
return float64(16)
}

Expand Down
5 changes: 3 additions & 2 deletions charts/k8ssandra-operator/crds/k8ssandra-operator-crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10258,7 +10258,7 @@ spec:
ServerVersion is the Cassandra or DSE version. The following versions are supported:
- Cassandra: 3.11.X, 4.X.X and 5.X.X
- DSE: 6.8.X, 7.x.x
pattern: (6\.8\.\d+)|(3\.11\.\d+)|(4\.\d+\.\d+)|(5\.\d+\.\d+)|(7\.\d+\.\d+)
- HCD: 1.0.x
type: string
serviceAccount:
description: The k8s service account to use for the Cassandra
Expand Down Expand Up @@ -22129,13 +22129,14 @@ spec:
enum:
- cassandra
- dse
- hcd
type: string
serverVersion:
description: |-
ServerVersion is the Cassandra or DSE version. The following versions are supported:
- Cassandra: 3.11.X, 4.X.X and 5.X.X
- DSE: 6.8.X, 7.x.x
pattern: (6\.8\.\d+)|(3\.11\.\d+)|(4\.\d+\.\d+)|(5\.\d+\.\d+)|(7\.\d+\.\d+)
- HCD: 1.0.x
type: string
serviceAccount:
description: The k8s service account to use for the Cassandra
Expand Down
5 changes: 3 additions & 2 deletions config/crd/bases/k8ssandra.io_k8ssandraclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10196,7 +10196,7 @@ spec:
ServerVersion is the Cassandra or DSE version. The following versions are supported:
- Cassandra: 3.11.X, 4.X.X and 5.X.X
- DSE: 6.8.X, 7.x.x
pattern: (6\.8\.\d+)|(3\.11\.\d+)|(4\.\d+\.\d+)|(5\.\d+\.\d+)|(7\.\d+\.\d+)
- HCD: 1.0.x
type: string
serviceAccount:
description: The k8s service account to use for the Cassandra
Expand Down Expand Up @@ -22067,13 +22067,14 @@ spec:
enum:
- cassandra
- dse
- hcd
type: string
serverVersion:
description: |-
ServerVersion is the Cassandra or DSE version. The following versions are supported:
- Cassandra: 3.11.X, 4.X.X and 5.X.X
- DSE: 6.8.X, 7.x.x
pattern: (6\.8\.\d+)|(3\.11\.\d+)|(4\.\d+\.\d+)|(5\.\d+\.\d+)|(7\.\d+\.\d+)
- HCD: 1.0.x
type: string
serviceAccount:
description: The k8s service account to use for the Cassandra
Expand Down
4 changes: 2 additions & 2 deletions controllers/k8ssandra/dcconfigs.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ func (r *K8ssandraClusterReconciler) createDatacenterConfigs(
// which is why we're doing this for Cassandra only.
// We only set this for the first DC. For subsequent DCs, the replication will be altered and a rebuild
// triggered.
if kc.Spec.Cassandra.ServerType == api.ServerDistributionCassandra && len(dcConfigs) == 0 {
if kc.Spec.Cassandra.ServerType.IsCassandra() && len(dcConfigs) == 0 {
cassandra.ApplySystemReplication(dcConfig, systemReplication)
}

// Stargate has a bug when backed by Cassandra 4, unless `cassandra.allow_alter_rf_during_range_movement` is
// set (see https://github.com/stargate/stargate/issues/1274).
// Set the option preemptively (we don't check `kc.HasStargates()` explicitly, because that causes the operator
// to restart the whole DC whenever Stargate is added or removed).
if kc.Spec.Cassandra.ServerType == api.ServerDistributionCassandra && dcConfig.ServerVersion.Major() != 3 {
if kc.Spec.Cassandra.ServerType.IsCassandra() && dcConfig.ServerVersion.Major() != 3 {
cassandra.AllowAlterRfDuringRangeMovement(dcConfig)
}

Expand Down
50 changes: 50 additions & 0 deletions pkg/cassandra/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,27 @@ func TestCreateJsonConfig(t *testing.T) {
"concurrent_writes": 16,
"concurrent_counter_writes": 4
}
}`,
},
{
name: "HCD [1.0.0] simple",
serverVersion: semver.MustParse("1.0.0"),
serverType: api.ServerDistributionHcd,
cassandraConfig: api.CassandraConfig{
CassandraYaml: unstructured.Unstructured{
"num_tokens": 16,
"concurrent_reads": 8,
"concurrent_writes": 16,
"concurrent_counter_writes": 4,
},
},
want: `{
"cassandra-yaml": {
"num_tokens": 16,
"concurrent_reads": 8,
"concurrent_writes": 16,
"concurrent_counter_writes": 4
}
}`,
},
{
Expand All @@ -161,6 +182,25 @@ func TestCreateJsonConfig(t *testing.T) {
"-Dcassandra.system_distributed_replication=dc1:3,dc2:3,dc3:3"
]
}
}`,
},
{
name: "HCD [1.0.0] system replication",
serverVersion: semver.MustParse("1.0.0"),
serverType: api.ServerDistributionHcd,
cassandraConfig: api.CassandraConfig{
JvmOptions: api.JvmOptions{
AdditionalOptions: []string{
SystemReplicationFactorStrategy + "=dc1:3,dc2:3,dc3:3",
},
},
},
want: `{
"cassandra-env-sh": {
"additional-jvm-opts": [
"-Dcassandra.system_distributed_replication=dc1:3,dc2:3,dc3:3"
]
}
}`,
},
{
Expand Down Expand Up @@ -305,3 +345,13 @@ func TestSmartTokenAllocCassandra(t *testing.T) {
_, exists := dcConfig.CassandraConfig.CassandraYaml["allocate_tokens_for_local_replication_factor"]
assert.False(t, exists, "allocate_tokens_for_local_replication_factor should not be set for Cassandra")
}

func TestSmartTokenAllocHcd(t *testing.T) {
dcConfig := &DatacenterConfig{
ServerType: api.ServerDistributionHcd,
}

EnableSmartTokenAllocation(dcConfig)
_, exists := dcConfig.CassandraConfig.CassandraYaml["allocate_tokens_for_local_replication_factor"]
assert.False(t, exists, "allocate_tokens_for_local_replication_factor should not be set for HCD")
}

0 comments on commit e835c51

Please sign in to comment.