From 123fc61ce14a164ce45f3837ab69c01c184dc83a Mon Sep 17 00:00:00 2001 From: Yuji Ito Date: Wed, 20 Dec 2023 05:16:32 +0100 Subject: [PATCH] DB/Add exponential backoff before trying the table creation (#119) --- scalardb/src/scalardb/core.clj | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/scalardb/src/scalardb/core.clj b/scalardb/src/scalardb/core.clj index caa9c8d..92914fe 100644 --- a/scalardb/src/scalardb/core.clj +++ b/scalardb/src/scalardb/core.clj @@ -31,21 +31,17 @@ (loop [retries RETRIES] (when (zero? retries) (throw (ex-info "Failed to set up tables" {:schema schema}))) + (when (< retries RETRIES) + (try + (SchemaLoader/unload properties schema true) + (catch Exception e (warn (.getMessage e)))) + (exponential-backoff (- RETRIES retries))) (let [schema (cheshire/generate-string schema) result (try - (SchemaLoader/load properties - schema - options - true) + (SchemaLoader/load properties schema options true) :success (catch Exception e (warn (.getMessage e)) - (try - (SchemaLoader/unload properties - schema - true) - (catch Exception e - (warn (.getMessage e)))) :fail))] (when (= result :fail) (recur (dec retries))))))))