diff --git a/scalardb/src/scalardb/core.clj b/scalardb/src/scalardb/core.clj index 2ebd860..063a20b 100644 --- a/scalardb/src/scalardb/core.clj +++ b/scalardb/src/scalardb/core.clj @@ -15,15 +15,20 @@ (def ^:const RETRIES 8) (def ^:const RETRIES_FOR_RECONNECTION 3) (def ^:private ^:const NUM_FAILURES_FOR_RECONNECTION 1000) +(def ^:private ^:const MAX_WAIT_MILLIS 32000) (def ^:const INITIAL_TABLE_ID 1) (def ^:const DEFAULT_TABLE_COUNT 3) (def ^:const KEYSPACE "jepsen") (def ^:const VERSION "tx_version") +(defn compute-exponential-backoff + [r] + (min MAX_WAIT_MILLIS (reduce * 1000 (repeat r 2)))) + (defn exponential-backoff [r] - (Thread/sleep (reduce * 1000 (repeat r 2)))) + (Thread/sleep (compute-exponential-backoff r))) (defn- get-cassandra-schema "Only the current test schemata are covered diff --git a/scalardb/test/scalardb/core_test.clj b/scalardb/test/scalardb/core_test.clj index 00d00de..1545bac 100644 --- a/scalardb/test/scalardb/core_test.clj +++ b/scalardb/test/scalardb/core_test.clj @@ -152,3 +152,9 @@ (scalar/check-transaction-states test #{"tx"}))) (is (spy/called-n-times? scalar/exponential-backoff 8)) (is (spy/called-n-times? scalar/prepare-storage-service! 3))))) + +(deftest compute-exponential-backoff-test + (is (= 2000 (scalar/compute-exponential-backoff 1))) + (is (= 4000 (scalar/compute-exponential-backoff 2))) + (is (= 32000 (scalar/compute-exponential-backoff 5))) + (is (= 32000 (scalar/compute-exponential-backoff 10))))