@@ -33,6 +33,7 @@ type Config struct {
33
33
DisableInitialHostLookup bool `yaml:"disable_initial_host_lookup"`
34
34
SSL bool `yaml:"SSL"`
35
35
HostVerification bool `yaml:"host_verification"`
36
+ HostSelectionPolicy string `yaml:"host_selection_policy"`
36
37
CAPath string `yaml:"CA_path"`
37
38
CertPath string `yaml:"tls_cert_path"`
38
39
KeyPath string `yaml:"tls_key_path"`
@@ -53,6 +54,11 @@ type Config struct {
53
54
TableOptions string `yaml:"table_options"`
54
55
}
55
56
57
+ const (
58
+ HostPolicyRoundRobin = "round-robin"
59
+ HostPolicyTokenAware = "token-aware"
60
+ )
61
+
56
62
// RegisterFlags adds the flags required to config this to the given FlagSet
57
63
func (cfg * Config ) RegisterFlags (f * flag.FlagSet ) {
58
64
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) {
63
69
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." )
64
70
f .BoolVar (& cfg .SSL , "cassandra.ssl" , false , "Use SSL when connecting to cassandra instances." )
65
71
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." )
66
73
f .StringVar (& cfg .CAPath , "cassandra.ca-path" , "" , "Path to certificate file to verify the peer." )
67
74
f .StringVar (& cfg .CertPath , "cassandra.tls-cert-path" , "" , "Path to certificate file used by TLS." )
68
75
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 {
180
187
}
181
188
}
182
189
}
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
+
183
199
if cfg .Auth {
184
200
password := cfg .Password .Value
185
201
if cfg .PasswordFile != "" {
0 commit comments