From 052ac1b8b356e47b2052ca6e585621d5fff1f887 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jane=C4=8Dek?= Date: Tue, 20 Oct 2020 20:41:26 +0200 Subject: [PATCH] refactor: Add connectTimeout (#357) fix: Default value of initQueryTimeout --- .../com/avast/sst/datastax/CassandraDatastaxDriverModule.scala | 1 + .../main/scala/com/avast/sst/datastax/config/advanced.scala | 3 ++- .../src/main/scala/com/avast/sst/datastax/config/package.scala | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cassandra-datastax-driver/src/main/scala/com/avast/sst/datastax/CassandraDatastaxDriverModule.scala b/cassandra-datastax-driver/src/main/scala/com/avast/sst/datastax/CassandraDatastaxDriverModule.scala index 140006bc9..285da3d65 100644 --- a/cassandra-datastax-driver/src/main/scala/com/avast/sst/datastax/CassandraDatastaxDriverModule.scala +++ b/cassandra-datastax-driver/src/main/scala/com/avast/sst/datastax/CassandraDatastaxDriverModule.scala @@ -28,6 +28,7 @@ object CassandraDatastaxDriverModule { stringProperty(LOAD_BALANCING_POLICY_CLASS)(cfg.basic.loadBalancingPolicy.`class`), optional(stringProperty(LOAD_BALANCING_LOCAL_DATACENTER), cfg.basic.loadBalancingPolicy.localDatacenter), optional(stringProperty(LOAD_BALANCING_FILTER_CLASS), cfg.basic.loadBalancingPolicy.filter.map(_.`class`)), + durationProperty(CONNECTION_CONNECT_TIMEOUT)(cfg.advanced.connection.connectTimeout), durationProperty(CONNECTION_INIT_QUERY_TIMEOUT)(cfg.advanced.connection.initQueryTimeout), intProperty(CONNECTION_POOL_LOCAL_SIZE)(cfg.advanced.connection.localPool.size), intProperty(CONNECTION_POOL_REMOTE_SIZE)(cfg.advanced.connection.remotePool.size), diff --git a/cassandra-datastax-driver/src/main/scala/com/avast/sst/datastax/config/advanced.scala b/cassandra-datastax-driver/src/main/scala/com/avast/sst/datastax/config/advanced.scala index 6fc5fa869..87f1a97a5 100644 --- a/cassandra-datastax-driver/src/main/scala/com/avast/sst/datastax/config/advanced.scala +++ b/cassandra-datastax-driver/src/main/scala/com/avast/sst/datastax/config/advanced.scala @@ -134,6 +134,7 @@ object AdvancedRequestConfig { * @param warnOnInitError Whether to log non-fatal errors when the driver tries to open a new connection. */ final case class ConnectionConfig( + connectTimeout: Duration = ConnectionConfig.Default.connectTimeout, initQueryTimeout: Duration = ConnectionConfig.Default.initQueryTimeout, setKeyspaceTimeout: Duration = ConnectionConfig.Default.setKeyspaceTimeout, localPool: PoolConfig = ConnectionConfig.Default.localPool, @@ -145,7 +146,7 @@ final case class ConnectionConfig( object ConnectionConfig { val Default: ConnectionConfig = - ConnectionConfig(InitQueryTimeout, InitQueryTimeout, PoolConfig.Default, PoolConfig.Default, 1024, 256, true) + ConnectionConfig(ConnectTimeout, InitQueryTimeout, InitQueryTimeout, PoolConfig.Default, PoolConfig.Default, 1024, 256, true) } /** The driver maintains a connection pool to each node, according to the distance assigned to it diff --git a/cassandra-datastax-driver/src/main/scala/com/avast/sst/datastax/config/package.scala b/cassandra-datastax-driver/src/main/scala/com/avast/sst/datastax/config/package.scala index b2c80ecd4..396a7ceb4 100644 --- a/cassandra-datastax-driver/src/main/scala/com/avast/sst/datastax/config/package.scala +++ b/cassandra-datastax-driver/src/main/scala/com/avast/sst/datastax/config/package.scala @@ -3,7 +3,8 @@ package com.avast.sst.datastax import scala.concurrent.duration._ package object config { - val InitQueryTimeout: Duration = 500.milliseconds + val ConnectTimeout: Duration = 5.seconds + val InitQueryTimeout: Duration = 5.seconds val RequestTimeout: Duration = 2.seconds val RequestPageSize: Int = 5000 }