Skip to content

Commit

Permalink
Add Message to DB Sync Timeout Error
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderkiel committed Dec 15, 2021
1 parent b3f4c79 commit e5cf492
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
1 change: 0 additions & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ comment:
layout: "reach, diff, flags, files"
behavior: default
require_changes: false
after_n_builds: 19
10 changes: 7 additions & 3 deletions modules/rest-api/src/blaze/rest_api/middleware/log.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
[taoensso.timbre :as log]))


(defn- format-request-method [{:keys [request-method]}]
(str/upper-case (name request-method)))


(defn wrap-log
[handler]
(fn [{:keys [request-method uri query-string] :as request}]
(fn [{:keys [uri query-string] :as request}]
(log/debug
(if query-string
(format "%s [base]%s?%s" (str/upper-case (name request-method)) uri query-string)
(format "%s [base]%s" (str/upper-case (name request-method)) uri)))
(format "%s [base]%s?%s" (format-request-method request) uri query-string)
(format "%s [base]%s" (format-request-method request) uri)))
(handler request)))
11 changes: 9 additions & 2 deletions modules/rest-util/src/blaze/middleware/fhir/db.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
(:require
[blaze.async.comp :as ac :refer [do-sync]]
[blaze.db.api :as d]
[blaze.handler.fhir.util :as fhir-util])
[blaze.handler.fhir.util :as fhir-util]
[cognitect.anomalies :as anom])
(:import
[java.util.concurrent TimeUnit]))

Expand All @@ -15,13 +16,19 @@
(and vid (re-matches #"\d+" vid) (Long/parseLong vid)))


(defn- timeout-msg [timeout]
(format "Timeout while trying to acquire the latest known database state. At least one known transaction hasen't been completed yet. Please try to lower the transaction load or increase the timeout of %d ms by setting DB_SYNC_TIMEOUT to a higher value if you see this often.", timeout))


(defn- db [node timeout {:keys [query-params] :as request}]
(if-let [t (vid request)]
(do-sync [db (d/sync node t)]
(d/as-of db t))
(if-let [t (fhir-util/t query-params)]
(d/sync node t)
(ac/or-timeout! (d/sync node) timeout TimeUnit/MILLISECONDS))))
(-> (d/sync node)
(ac/or-timeout! timeout TimeUnit/MILLISECONDS)
(ac/exceptionally #(assoc % ::anom/message (timeout-msg timeout)))))))


(defn wrap-db
Expand Down
6 changes: 4 additions & 2 deletions modules/rest-util/test/blaze/middleware/fhir/db_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@
(ac/supply-async (constantly ::db) (ac/delayed-executor 3 TimeUnit/SECONDS)))]

(given-failed-future ((db/wrap-db handler ::node 2000) {})
::anom/category := ::anom/busy)))
::anom/category := ::anom/busy
::anom/message := "Timeout while trying to acquire the latest known database state. At least one known transaction hasen't been completed yet. Please try to lower the transaction load or increase the timeout of 2000 ms by setting DB_SYNC_TIMEOUT to a higher value if you see this often.")))

(testing "default timeout are 10 seconds"
(with-redefs
Expand All @@ -96,4 +97,5 @@
(ac/supply-async (constantly ::db) (ac/delayed-executor 11 TimeUnit/SECONDS)))]

(given-failed-future ((db/wrap-db handler ::node) {})
::anom/category := ::anom/busy)))))
::anom/category := ::anom/busy
::anom/message := "Timeout while trying to acquire the latest known database state. At least one known transaction hasen't been completed yet. Please try to lower the transaction load or increase the timeout of 10000 ms by setting DB_SYNC_TIMEOUT to a higher value if you see this often.")))))

0 comments on commit e5cf492

Please sign in to comment.