Skip to content

Commit f133d3c

Browse files
Add support for changing the gocql connect timeout (#4874)
* Add support for changing the gocql connect timout * Fix comment typo
1 parent e5ed7f7 commit f133d3c

File tree

7 files changed

+22
-3
lines changed

7 files changed

+22
-3
lines changed

common/persistence/nosql/nosqlplugin/cassandra/gocql/interface.go

+1
Original file line numberDiff line numberDiff line change
@@ -113,5 +113,6 @@ type (
113113
Consistency Consistency
114114
SerialConsistency SerialConsistency
115115
Timeout time.Duration
116+
ConnectTimeout time.Duration
116117
}
117118
)

common/persistence/nosql/nosqlplugin/cassandra/gocql/session.go

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ func initSession(
7171
cluster.Consistency = mustConvertConsistency(config.Consistency)
7272
cluster.SerialConsistency = mustConvertSerialConsistency(config.SerialConsistency)
7373
cluster.Timeout = config.Timeout
74+
cluster.ConnectTimeout = config.ConnectTimeout
75+
7476
return cluster.CreateSession()
7577
}
7678

common/persistence/nosql/nosqlplugin/cassandra/plugin.go

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const (
3535
// PluginName is the name of the plugin
3636
PluginName = "cassandra"
3737
defaultSessionTimeout = 10 * time.Second
38+
defaultConnectTimeout = 2 * time.Second
3839
)
3940

4041
type plugin struct{}
@@ -97,5 +98,6 @@ func toGoCqlConfig(cfg *config.NoSQL) gocql.ClusterConfig {
9798
Consistency: gocql.LocalQuorum,
9899
SerialConsistency: gocql.LocalSerial,
99100
Timeout: defaultSessionTimeout,
101+
ConnectTimeout: defaultConnectTimeout,
100102
}
101103
}

tools/cassandra/cqlclient.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type (
4747
AllowedAuthenticators []string
4848
Keyspace string
4949
Timeout int
50+
ConnectTimeout int
5051
NumReplicas int
5152
ProtoVersion int
5253
TLS *config.TLS
@@ -56,9 +57,10 @@ type (
5657
var errGetSchemaVersion = errors.New("failed to get current schema version from cassandra")
5758

5859
const (
59-
DefaultTimeout = 30 // Timeout in seconds
60-
DefaultCassandraPort = 9042
61-
SystemKeyspace = "system"
60+
DefaultTimeout = 30 // Timeout in seconds
61+
DefaultConnectTimeout = 2 // Connect timeout in seconds
62+
DefaultCassandraPort = 9042
63+
SystemKeyspace = "system"
6264
)
6365

6466
const (
@@ -105,6 +107,7 @@ func NewCQLClient(cfg *CQLClientConfig) (*CqlClient, error) {
105107
Keyspace: cfg.Keyspace,
106108
TLS: cfg.TLS,
107109
Timeout: time.Duration(cfg.Timeout) * time.Second,
110+
ConnectTimeout: time.Duration(cfg.ConnectTimeout) * time.Second,
108111
ProtoVersion: cfg.ProtoVersion,
109112
Consistency: gocql.All,
110113
})

tools/cassandra/handler.go

+2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ func CheckCompatibleVersion(
9595
Keyspace: cfg.Keyspace,
9696
AllowedAuthenticators: cfg.AllowedAuthenticators,
9797
Timeout: DefaultTimeout,
98+
ConnectTimeout: DefaultConnectTimeout,
9899
TLS: cfg.TLS,
99100
ProtoVersion: cfg.ProtoVersion,
100101
})
@@ -177,6 +178,7 @@ func newCQLClientConfig(cli *cli.Context) (*CQLClientConfig, error) {
177178
cqlConfig.User = cli.GlobalString(schema.CLIOptUser)
178179
cqlConfig.Password = cli.GlobalString(schema.CLIOptPassword)
179180
cqlConfig.Timeout = cli.GlobalInt(schema.CLIOptTimeout)
181+
cqlConfig.ConnectTimeout = cli.GlobalInt(schema.CLIOptConnectTimeout)
180182
cqlConfig.Keyspace = cli.GlobalString(schema.CLIOptKeyspace)
181183
cqlConfig.NumReplicas = cli.Int(schema.CLIOptReplicationFactor)
182184
cqlConfig.ProtoVersion = cli.Int(schema.CLIOptProtoVersion)

tools/cassandra/main.go

+5
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ func BuildCLIOptions() *cli.App {
9393
Usage: "request Timeout in seconds used for cql client",
9494
EnvVar: "CASSANDRA_TIMEOUT",
9595
},
96+
cli.IntFlag{
97+
Name: schema.CLIOptConnectTimeout,
98+
Value: DefaultConnectTimeout,
99+
Usage: "Connection Timeout in seconds used for cql client",
100+
},
96101
cli.StringFlag{
97102
Name: schema.CLIFlagKeyspace,
98103
Value: "cadence",

tools/common/schema/types.go

+4
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ const (
7878
CLIOptPassword = "password"
7979
// CLIOptTimeout is the cli option for timeout
8080
CLIOptTimeout = "timeout"
81+
// CLIOptConnectTimeout is the cli option for connection timeout
82+
CLIOptConnectTimeout = "connect-timeout"
8183
// CLIOptKeyspace is the cli option for keyspace
8284
CLIOptKeyspace = "keyspace"
8385
// CLIOptDatabase is the cli option for database
@@ -115,6 +117,8 @@ const (
115117
CLIFlagUser = CLIOptUser + ", u"
116118
// CLIFlagPassword is the cli flag for password
117119
CLIFlagPassword = CLIOptPassword + ", pw"
120+
// CLIFlagConnectTimeout is the cli flag for connection timeout
121+
CLIFlagConnectTimeout = CLIOptConnectTimeout + ", ct"
118122
// CLIFlagTimeout is the cli flag for timeout
119123
CLIFlagTimeout = CLIOptTimeout + ", t"
120124
// CLIFlagKeyspace is the cli flag for keyspace

0 commit comments

Comments
 (0)