Skip to content
This repository has been archived by the owner on Aug 26, 2024. It is now read-only.

Commit

Permalink
Merge gocql/gocql into kiwicom/gocql
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-sucha committed Sep 4, 2023
2 parents 7fba239 + 34fdeeb commit 3b7e681
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 30 deletions.
57 changes: 35 additions & 22 deletions cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,28 @@ type ClusterConfig struct {
// versions the protocol selected is not defined (ie, it can be any of the supported in the cluster)
ProtoVersion int

// Connection timeout (default: 600ms)
// ConnectTimeout is used to set up the default dialer and is ignored if Dialer or HostDialer is provided.
// Timeout limits the time spent on the client side while executing a query.
// Specifically, query or batch execution will return an error if the client does not receive a response
// from the server within the Timeout period.
// Timeout is also used to configure the read timeout on the underlying network connection.
// Client Timeout should always be higher than the request timeouts configured on the server,
// so that retries don't overload the server.
// Timeout has a default value of 11 seconds, which is higher than default server timeout for most query types.
// Timeout is not applied to requests during initial connection setup, see ConnectTimeout.
Timeout time.Duration

// Initial connection timeout, used during initial dial to server (default: 600ms)
// ConnectTimeout is used to set up the default dialer and is ignored if Dialer or HostDialer is provided.
// ConnectTimeout limits the time spent during connection setup.
// During initial connection setup, internal queries, AUTH requests will return an error if the client
// does not receive a response within the ConnectTimeout period.
// ConnectTimeout is applied to the connection setup queries independently.
// ConnectTimeout also limits the duration of dialing a new TCP connection
// in case there is no Dialer nor HostDialer configured.
// ConnectTimeout has a default value of 11 seconds.
ConnectTimeout time.Duration

// Timeout for writing a query. Defaults to Timeout if not specified.
// WriteTimeout limits the time the driver waits to write a request to a network connection.
// WriteTimeout should be lower than or equal to Timeout.
// WriteTimeout defaults to the value of Timeout.
WriteTimeout time.Duration

// Port used when dialing.
Expand Down Expand Up @@ -282,24 +295,24 @@ type Dialer interface {
// the same host, and will not mark the node being down or up from events.
func NewCluster(hosts ...string) *ClusterConfig {
cfg := &ClusterConfig{
Hosts: hosts,
CQLVersion: "3.0.0",
Timeout: 600 * time.Millisecond,
ConnectTimeout: 600 * time.Millisecond,
Port: 9042,
NumConns: 2,
HeavyLoadedConnectionThreshold: 512,
Hosts: hosts,
CQLVersion: "3.0.0",
Timeout: 11 * time.Second,
ConnectTimeout: 11 * time.Second,
Port: 9042,
NumConns: 2,
HeavyLoadedConnectionThreshold: 512,
HeavyLoadedSwitchConnectionPercentage: 20,
Consistency: Quorum,
MaxPreparedStmts: defaultMaxPreparedStmts,
MaxRoutingKeyInfo: 1000,
PageSize: 5000,
DefaultTimestamp: true,
MaxWaitSchemaAgreement: 60 * time.Second,
ReconnectInterval: 60 * time.Second,
ConvictionPolicy: &SimpleConvictionPolicy{},
ReconnectionPolicy: &ConstantReconnectionPolicy{MaxRetries: 3, Interval: 1 * time.Second},
WriteCoalesceWaitTime: 200 * time.Microsecond,
Consistency: Quorum,
MaxPreparedStmts: defaultMaxPreparedStmts,
MaxRoutingKeyInfo: 1000,
PageSize: 5000,
DefaultTimestamp: true,
MaxWaitSchemaAgreement: 60 * time.Second,
ReconnectInterval: 60 * time.Second,
ConvictionPolicy: &SimpleConvictionPolicy{},
ReconnectionPolicy: &ConstantReconnectionPolicy{MaxRetries: 3, Interval: 1 * time.Second},
WriteCoalesceWaitTime: 200 * time.Microsecond,
}

return cfg
Expand Down
2 changes: 1 addition & 1 deletion cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
func TestNewCluster_Defaults(t *testing.T) {
cfg := NewCluster()
assertEqual(t, "cluster config cql version", "3.0.0", cfg.CQLVersion)
assertEqual(t, "cluster config timeout", 600*time.Millisecond, cfg.Timeout)
assertEqual(t, "cluster config timeout", 11*time.Second, cfg.Timeout)
assertEqual(t, "cluster config port", 9042, cfg.Port)
assertEqual(t, "cluster config num-conns", 2, cfg.NumConns)
assertEqual(t, "cluster config consistency", Quorum, cfg.Consistency)
Expand Down
1 change: 1 addition & 0 deletions conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ func TestStartupTimeout(t *testing.T) {
// Set very long query connection timeout
// so we know CreateSession() is using the ConnectTimeout
cluster.Timeout = time.Second * 5
cluster.ConnectTimeout = 600 * time.Millisecond

// Create session should timeout during connect attempt
_, err := cluster.CreateSession()
Expand Down
7 changes: 0 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,4 @@ require (
sigs.k8s.io/yaml v1.3.0
)

retract (
v1.8.0 // tag from kiwicom/gocql added by mistake to scylladb/gocql
v1.8.1 // tag from kiwicom/gocql added by mistake to scylladb/gocql
v1.9.0 // tag from kiwicom/gocql added by mistake to scylladb/gocql
v1.10.0 // tag from kiwicom/gocql added by mistake to scylladb/gocql
)

go 1.13

0 comments on commit 3b7e681

Please sign in to comment.