Skip to content

Commit 2e1159f

Browse files
authored
Add config property for Cassandra connection timeout (#679)
* Add config property for Cassandra connection timeout * change connect timeout to duration * update comment
1 parent fec152d commit 2e1159f

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

common/cassandra/cassandraCluster.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ package cassandra
2626

2727
import (
2828
"crypto/tls"
29-
"strings"
30-
3129
"github.com/gocql/gocql"
30+
"strings"
3231

3332
"go.temporal.io/server/common/service/config"
3433
)
@@ -68,6 +67,9 @@ func NewCassandraCluster(cfg config.Cassandra) *gocql.ClusterConfig {
6867
if cfg.MaxConns > 0 {
6968
cluster.NumConns = cfg.MaxConns
7069
}
70+
if cfg.ConnectTimeout > 0 {
71+
cluster.ConnectTimeout = cfg.ConnectTimeout
72+
}
7173

7274
cluster.PoolConfig.HostSelectionPolicy = gocql.TokenAwareHostPolicy(gocql.RoundRobinHostPolicy())
7375

common/persistence/cassandra/cassandraPersistenceTest.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,13 @@ func NewTestCluster(keyspace, username, password, host string, port int, schemaD
7171
}
7272
result.schemaDir = schemaDir
7373
result.cfg = config.Cassandra{
74-
User: username,
75-
Password: password,
76-
Hosts: host,
77-
Port: port,
78-
MaxConns: 2,
79-
Keyspace: keyspace,
74+
User: username,
75+
Password: password,
76+
Hosts: host,
77+
Port: port,
78+
MaxConns: 2,
79+
ConnectTimeout: 600 * time.Millisecond,
80+
Keyspace: keyspace,
8081
}
8182
return &result
8283
}

common/service/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ type (
230230
Datacenter string `yaml:"datacenter"`
231231
// MaxConns is the max number of connections to this datastore for a single keyspace
232232
MaxConns int `yaml:"maxConns"`
233+
// ConnectTimeout is a timeout for initial dial to cassandra server (default: 600ms)
234+
ConnectTimeout time.Duration `yaml:"connectTimeout"`
233235
// TLS configuration
234236
TLS *auth.TLS `yaml:"tls"`
235237
// Consistency configuration (defaults to LOCAL_QUORUM / LOCAL_SERIAL for all stores if this field not set)

0 commit comments

Comments
 (0)