Skip to content

Commit

Permalink
Add upper limit to exponential-backoff
Browse files Browse the repository at this point in the history
  • Loading branch information
komamitsu committed Oct 24, 2024
1 parent 9ff6675 commit 82acdb0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion scalardb/src/scalardb/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions scalardb/test/scalardb/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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))))

0 comments on commit 82acdb0

Please sign in to comment.