Skip to content

Commit

Permalink
Fix Issues with Rebuilding the PatientLastChange Index
Browse files Browse the repository at this point in the history
Closes: #2372
  • Loading branch information
alexanderkiel committed Feb 3, 2025
1 parent e0f832c commit 1cfc66a
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 102 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2077,6 +2077,9 @@ jobs:
- name: Wait for Blaze
run: .github/scripts/wait-for-url.sh http://localhost:8080/health

- name: Docker Logs
run: docker logs blaze

- name: Ensure that the State of PatientLastChange Index is Current
run: .github/scripts/check-patient-last-change-index-state.sh current

Expand Down
2 changes: 1 addition & 1 deletion modules/db/src/blaze/db/impl/index/patient_last_change.clj
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
(bb/put-long! t)
bb/array)))

(defn decode-state [bytes]
(defn- decode-state [bytes]
(let [buf (bb/wrap bytes)]
(if (zero? (bb/get-byte! buf))
{:type :current}
Expand Down
42 changes: 10 additions & 32 deletions modules/db/src/blaze/db/node.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
[blaze.db.impl.index.tx-success :as tx-success]
[blaze.db.impl.protocols :as p]
[blaze.db.kv :as kv]
[blaze.db.node.patient-last-change-index :as node-plc]
[blaze.db.node.protocols :as np]
[blaze.db.node.resource-indexer :as resource-indexer]
[blaze.db.node.resource-indexer.spec]
Expand Down Expand Up @@ -494,40 +493,19 @@
(fn sync-standalone [^Node node]
(ac/completed-future (db/db node (:t @(.-state node)))))))

(defn- index-patient-last-change-index!
[{:keys [kv-store] :as node} current-t {:keys [t] :as tx-data}]
(log/trace "Build PatientLastChange index with t =" t)
(when-ok [entries (node-plc/index-entries node tx-data)]
(store-tx-entries! kv-store entries))
(vreset! current-t t))

(defn- poll-and-index-patient-last-change-index!
[node queue current-t poll-timeout]
(run! (partial index-patient-last-change-index! node current-t)
(poll-tx-queue! queue poll-timeout)))
(defn- initial-plc-index-entries [{:keys [state] :as node}]
(into
[(plc/state-index-entry {:type :current})]
(map (fn [{:keys [id]}] (plc/index-entry (codec/id-byte-string id) (:t @state))))
(d/type-list (d/db node) "Patient")))

(defn build-patient-last-change-index
[key {:keys [tx-log kv-store run? state poll-timeout] :as node}]
(let [{:keys [type t]} (plc/state kv-store)]
[key {:keys [kv-store] :as node}]
(let [{:keys [type]} (plc/state kv-store)]
(when (identical? :building type)
(let [start-t (inc t)
end-t (:t @state)
current-t (volatile! start-t)]
(log/info "Building PatientLastChange index of" (node-util/component-name key "node") "starting at t =" start-t)
(with-open [queue (tx-log/new-queue tx-log start-t)]
(while (and @run? (< @current-t end-t))
(try
(poll-and-index-patient-last-change-index! node queue current-t poll-timeout)
(catch Exception e
(log/error (format "Error while building the PatientLastChange index of %s."
(node-util/component-name key "node")) e)))))
(if (>= @current-t end-t)
(do
(store-tx-entries! kv-store [(plc/state-index-entry {:type :current})])
(log/info (format "Finished building PatientLastChange index of %s." (node-util/component-name key "node"))))
(log/info (format "Partially build PatientLastChange index of %s up to t ="
(node-util/component-name key "node")) @current-t
"at a goal of t =" end-t "Will continue at next start."))))))
(log/info "Building PatientLastChange index of" (node-util/component-name key "node"))
(store-tx-entries! kv-store (initial-plc-index-entries node))
(log/info (format "Finished building PatientLastChange index of %s." (node-util/component-name key "node"))))))

(defmethod m/pre-init-spec :blaze.db/node [_]
(s/keys
Expand Down
13 changes: 0 additions & 13 deletions modules/db/src/blaze/db/node/patient_last_change_index.clj

This file was deleted.

14 changes: 0 additions & 14 deletions modules/db/test/blaze/db/node/patient_last_change_index_spec.clj

This file was deleted.

42 changes: 0 additions & 42 deletions modules/db/test/blaze/db/node/patient_last_change_index_test.clj

This file was deleted.

0 comments on commit 1cfc66a

Please sign in to comment.