Skip to content

Commit d8e6faa

Browse files
committed
Make cassandra reconnect down hosts.
* Fix #767 by enabling gocql setting `ReconnectInterval` to reconnect to down Cassandra hosts at a regular interval. Signed-off-by: Brendan Shaklovitz <nyanshak@users.noreply.github.com>
1 parent a0dc40e commit d8e6faa

File tree

2 files changed

+30
-18
lines changed

2 files changed

+30
-18
lines changed

pkg/cassandra/config/config.go

+5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type Configuration struct {
3131
Keyspace string `validate:"nonzero"`
3232
ConnectionsPerHost int `validate:"min=1" yaml:"connections_per_host"`
3333
Timeout time.Duration `validate:"min=500"`
34+
ReconnectInterval time.Duration `validate:"min=500" yaml:"reconnect_interval"`
3435
SocketKeepAlive time.Duration `validate:"min=0" yaml:"socket_keep_alive"`
3536
MaxRetryAttempts int `validate:"min=0" yaml:"max_retry_attempt"`
3637
ProtoVersion int `yaml:"proto_version"`
@@ -74,6 +75,9 @@ func (c *Configuration) ApplyDefaults(source *Configuration) {
7475
if c.Timeout == 0 {
7576
c.Timeout = source.Timeout
7677
}
78+
if c.ReconnectInterval == 0 {
79+
c.ReconnectInterval = source.ReconnectInterval
80+
}
7781
if c.Port == 0 {
7882
c.Port = source.Port
7983
}
@@ -109,6 +113,7 @@ func (c *Configuration) NewCluster() *gocql.ClusterConfig {
109113
cluster.Keyspace = c.Keyspace
110114
cluster.NumConns = c.ConnectionsPerHost
111115
cluster.Timeout = c.Timeout
116+
cluster.ReconnectInterval = c.ReconnectInterval
112117
cluster.SocketKeepalive = c.SocketKeepAlive
113118
if c.ProtoVersion > 0 {
114119
cluster.ProtoVersion = c.ProtoVersion

plugin/storage/cassandra/options.go

+25-18
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,25 @@ import (
2626

2727
const (
2828
// session settings
29-
suffixEnabled = ".enabled"
30-
suffixConnPerHost = ".connections-per-host"
31-
suffixMaxRetryAttempts = ".max-retry-attempts"
32-
suffixTimeout = ".timeout"
33-
suffixServers = ".servers"
34-
suffixPort = ".port"
35-
suffixKeyspace = ".keyspace"
36-
suffixConsistency = ".consistency"
37-
suffixProtoVer = ".proto-version"
38-
suffixSocketKeepAlive = ".socket-keep-alive"
39-
suffixUsername = ".username"
40-
suffixPassword = ".password"
41-
suffixTLS = ".tls"
42-
suffixCert = ".tls.cert"
43-
suffixKey = ".tls.key"
44-
suffixCA = ".tls.ca"
45-
suffixServerName = ".tls.server-name"
46-
suffixVerifyHost = ".tls.verify-host"
29+
suffixEnabled = ".enabled"
30+
suffixConnPerHost = ".connections-per-host"
31+
suffixMaxRetryAttempts = ".max-retry-attempts"
32+
suffixTimeout = ".timeout"
33+
suffixReconnectInterval = ".reconnect-interval"
34+
suffixServers = ".servers"
35+
suffixPort = ".port"
36+
suffixKeyspace = ".keyspace"
37+
suffixConsistency = ".consistency"
38+
suffixProtoVer = ".proto-version"
39+
suffixSocketKeepAlive = ".socket-keep-alive"
40+
suffixUsername = ".username"
41+
suffixPassword = ".password"
42+
suffixTLS = ".tls"
43+
suffixCert = ".tls.cert"
44+
suffixKey = ".tls.key"
45+
suffixCA = ".tls.ca"
46+
suffixServerName = ".tls.server-name"
47+
suffixVerifyHost = ".tls.verify-host"
4748

4849
// common storage settings
4950
suffixSpanStoreWriteCacheTTL = ".span-store-write-cache-ttl"
@@ -83,6 +84,7 @@ func NewOptions(primaryNamespace string, otherNamespaces ...string) *Options {
8384
Keyspace: "jaeger_v1_test",
8485
ProtoVersion: 4,
8586
ConnectionsPerHost: 2,
87+
ReconnectInterval: 60 * time.Second,
8688
},
8789
servers: "127.0.0.1",
8890
namespace: primaryNamespace,
@@ -130,6 +132,10 @@ func addFlags(flagSet *flag.FlagSet, nsConfig *namespaceConfig) {
130132
nsConfig.namespace+suffixTimeout,
131133
nsConfig.Timeout,
132134
"Timeout used for queries")
135+
flagSet.Duration(
136+
nsConfig.namespace+suffixReconnectInterval,
137+
nsConfig.ReconnectInterval,
138+
"Reconnect interval to retry connecting to downed hosts")
133139
flagSet.String(
134140
nsConfig.namespace+suffixServers,
135141
nsConfig.servers,
@@ -204,6 +210,7 @@ func (cfg *namespaceConfig) initFromViper(v *viper.Viper) {
204210
cfg.ConnectionsPerHost = v.GetInt(cfg.namespace + suffixConnPerHost)
205211
cfg.MaxRetryAttempts = v.GetInt(cfg.namespace + suffixMaxRetryAttempts)
206212
cfg.Timeout = v.GetDuration(cfg.namespace + suffixTimeout)
213+
cfg.ReconnectInterval = v.GetDuration(cfg.namespace + suffixReconnectInterval)
207214
cfg.servers = v.GetString(cfg.namespace + suffixServers)
208215
cfg.Port = v.GetInt(cfg.namespace + suffixPort)
209216
cfg.Keyspace = v.GetString(cfg.namespace + suffixKeyspace)

0 commit comments

Comments
 (0)