Skip to content

Commit

Permalink
Fix CaS when the doc's provided in a different order, xtdb#362
Browse files Browse the repository at this point in the history
  • Loading branch information
jarohen committed Dec 13, 2019
1 parent 004ecc3 commit f0c439d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions crux-core/src/crux/tx.clj
Expand Up @@ -74,8 +74,8 @@
valid-time (or at-valid-time transact-time)
{:keys [content-hash]
:as entity} (first (idx/entities-at snapshot [eid] valid-time transact-time))]
{:pre-commit-fn #(if (= (c/new-id content-hash)
(c/new-id old-v))
{:pre-commit-fn #(if (= (db/get-single-object object-store snapshot (c/new-id content-hash))
(db/get-single-object object-store snapshot (c/new-id old-v)))
(let [correct-state? (not (nil? (db/get-single-object object-store snapshot (c/new-id new-v))))]
(when-not correct-state?
(log/error "CAS, incorrect doc state for:" (c/new-id new-v) "tx id:" tx-id))
Expand Down
7 changes: 7 additions & 0 deletions crux-test/test/crux/tx_test.clj
Expand Up @@ -632,3 +632,10 @@

(t/is (= {:crux.db/id :foo, :bar :baz}
(api/entity (api/db *api*) :foo))))))

(t/deftest cas-map-ordering-362
(sync-submit-tx *api* [[:crux.tx/put {:crux.db/id :foo, :foo :bar}]])
(sync-submit-tx *api* [[:crux.tx/cas {:foo :bar, :crux.db/id :foo} {:crux.db/id :foo, :foo :baz}]])

(t/is (= {:crux.db/id :foo, :foo :baz}
(api/entity (api/db *api*) :foo))))

0 comments on commit f0c439d

Please sign in to comment.