Skip to content

Commit d04b521

Browse files
Allow configuration of Cassandra's host selection policy (#4069) (#4069)
Signed-off-by: ChinYing-Li <[email protected]> Co-authored-by: Peter Štibraný <[email protected]>
1 parent 588e47a commit d04b521

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
* [ENHANCEMENT] Distributor: added per-distributor limits: max number of inflight requests (`-distributor.instance-limits.max-inflight-push-requests`) and max ingestion rate in samples/sec (`-distributor.instance-limits.max-ingestion-rate`). If not set, these two are unlimited. Also added metrics to expose current values (`cortex_distributor_inflight_push_requests`, `cortex_distributor_ingestion_rate_samples_per_second`) as well as limits (`cortex_distributor_instance_limits` with various `limit` label values). #4071
4242
* [ENHANCEMENT] Ruler: Added `-ruler.enabled-tenants` and `-ruler.disabled-tenants` to explicitly enable or disable rules processing for specific tenants. #4074
4343
* [ENHANCEMENT] Block Storage Ingester: `/flush` now accepts two new parameters: `tenant` to specify tenant to flush and `wait=true` to make call synchronous. Multiple tenants can be specified by repeating `tenant` parameter. If no `tenant` is specified, all tenants are flushed, as before. #4073
44+
* [ENHANCEMENT] Allow configuration of Cassandra's host selection policy. #4069
4445
* [BUGFIX] Ruler-API: fix bug where `/api/v1/rules/<namespace>/<group_name>` endpoint return `400` instead of `404`. #4013
4546
* [BUGFIX] Distributor: reverted changes done to rate limiting in #3825. #3948
4647
* [BUGFIX] Ingester: Fix race condition when opening and closing tsdb concurrently. #3959

docs/configuration/config-file-reference.md

+5
Original file line numberDiff line numberDiff line change
@@ -3020,6 +3020,11 @@ cassandra:
30203020
# CLI flag: -cassandra.host-verification
30213021
[host_verification: <boolean> | default = true]
30223022

3023+
# Policy for selecting Cassandra host. Supported values are: round-robin,
3024+
# token-aware.
3025+
# CLI flag: -cassandra.host-selection-policy
3026+
[host_selection_policy: <string> | default = "round-robin"]
3027+
30233028
# Path to certificate file to verify the peer.
30243029
# CLI flag: -cassandra.ca-path
30253030
[CA_path: <string> | default = ""]

pkg/chunk/cassandra/storage_client.go

+16
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type Config struct {
3333
DisableInitialHostLookup bool `yaml:"disable_initial_host_lookup"`
3434
SSL bool `yaml:"SSL"`
3535
HostVerification bool `yaml:"host_verification"`
36+
HostSelectionPolicy string `yaml:"host_selection_policy"`
3637
CAPath string `yaml:"CA_path"`
3738
CertPath string `yaml:"tls_cert_path"`
3839
KeyPath string `yaml:"tls_key_path"`
@@ -53,6 +54,11 @@ type Config struct {
5354
TableOptions string `yaml:"table_options"`
5455
}
5556

57+
const (
58+
HostPolicyRoundRobin = "round-robin"
59+
HostPolicyTokenAware = "token-aware"
60+
)
61+
5662
// RegisterFlags adds the flags required to config this to the given FlagSet
5763
func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
5864
f.StringVar(&cfg.Addresses, "cassandra.addresses", "", "Comma-separated hostnames or IPs of Cassandra instances.")
@@ -63,6 +69,7 @@ func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
6369
f.BoolVar(&cfg.DisableInitialHostLookup, "cassandra.disable-initial-host-lookup", false, "Instruct the cassandra driver to not attempt to get host info from the system.peers table.")
6470
f.BoolVar(&cfg.SSL, "cassandra.ssl", false, "Use SSL when connecting to cassandra instances.")
6571
f.BoolVar(&cfg.HostVerification, "cassandra.host-verification", true, "Require SSL certificate validation.")
72+
f.StringVar(&cfg.HostSelectionPolicy, "cassandra.host-selection-policy", HostPolicyRoundRobin, "Policy for selecting Cassandra host. Supported values are: round-robin, token-aware.")
6673
f.StringVar(&cfg.CAPath, "cassandra.ca-path", "", "Path to certificate file to verify the peer.")
6774
f.StringVar(&cfg.CertPath, "cassandra.tls-cert-path", "", "Path to certificate file used by TLS.")
6875
f.StringVar(&cfg.KeyPath, "cassandra.tls-key-path", "", "Path to private key file used by TLS.")
@@ -180,6 +187,15 @@ func (cfg *Config) setClusterConfig(cluster *gocql.ClusterConfig) error {
180187
}
181188
}
182189
}
190+
191+
if cfg.HostSelectionPolicy == HostPolicyRoundRobin {
192+
cluster.PoolConfig.HostSelectionPolicy = gocql.RoundRobinHostPolicy()
193+
} else if cfg.HostSelectionPolicy == HostPolicyTokenAware {
194+
cluster.PoolConfig.HostSelectionPolicy = gocql.TokenAwareHostPolicy(gocql.RoundRobinHostPolicy())
195+
} else {
196+
return errors.New("Unknown host selection policy")
197+
}
198+
183199
if cfg.Auth {
184200
password := cfg.Password.Value
185201
if cfg.PasswordFile != "" {

0 commit comments

Comments
 (0)