From 6e499cb007801262c6f0d33070ac0ee2f9887bb2 Mon Sep 17 00:00:00 2001 From: Taylor Wrobel Date: Fri, 18 Feb 2022 16:33:06 -0800 Subject: [PATCH] Expose configuring cassandra connect timeout through query string Exposes the cassandra client's ConnectTimeout parameter through the cassandra database query string. The Cassandra client has a fairly aggressive connect timeout of 600ms, which can cause flakiness in certain network environments or in Cassandra-compatible clusters with a more complex process for establishing connections (i.e. ScyllaDB). The query timeout is already configurable and exposed, but does not impact the connect timeout in the gocql driver. This change allows for configurtion of both. --- database/cassandra/README.md | 1 + database/cassandra/cassandra.go | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/database/cassandra/README.md b/database/cassandra/README.md index c3d4387ad..65ab0e62c 100644 --- a/database/cassandra/README.md +++ b/database/cassandra/README.md @@ -20,6 +20,7 @@ system_schema table which comes with 3.X | `consistency` | ALL | Migration consistency | `protocol` | | Cassandra protocol version (3 or 4) | `timeout` | 1 minute | Migration timeout +| `connect-timeout` | 600ms | Initial connection timeout to the cluster | | `username` | nil | Username to use when authenticating. | | `password` | nil | Password to use when authenticating. | | `sslcert` | | Cert file location. The file must contain PEM encoded data. | diff --git a/database/cassandra/cassandra.go b/database/cassandra/cassandra.go index a639426d1..85b2eb19c 100644 --- a/database/cassandra/cassandra.go +++ b/database/cassandra/cassandra.go @@ -133,6 +133,14 @@ func (c *Cassandra) Open(url string) (database.Driver, error) { } cluster.Timeout = timeout } + if len(u.Query().Get("connect-timeout")) > 0 { + var connectTimeout time.Duration + connectTimeout, err = time.ParseDuration(u.Query().Get("connect-timeout")) + if err != nil { + return nil, err + } + cluster.ConnectTimeout = connectTimeout + } if len(u.Query().Get("sslmode")) > 0 { if u.Query().Get("sslmode") != "disable" {