Skip to content

Instantly share code, notes, and snippets.

@claj
Created June 1, 2015 15:09
Show Gist options
  • Save claj/f35a8258c1ea88bc3cea to your computer and use it in GitHub Desktop.
Save claj/f35a8258c1ea88bc3cea to your computer and use it in GitHub Desktop.
CAS/enum error in Datomic 0.9.5173
(ns traktor.error
(:require [datomic.api :as d :refer [db q]]))
(d/create-database "datomic:mem://casenum")
(def conn (d/connect "datomic:mem://casenum"))
;; simple schema
@(d/transact conn [{:db/id #db/id [:db.part/db]
:db/ident :state
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db.install/_attribute :db.part/db}
{:db/id #db/id [:db.part/user]
:db/ident :state-1}
{:db/id #db/id [:db.part/user]
:db/ident :state-2}])
;; :entity with :state :state-1
@(d/transact conn [{:db/id #db/id [:db.part/user]
:db/ident :entity
:state :state-1}])
;; ********* :state-1 as :db/ident
@(d/transact conn [[:db.fn/cas :entity :state :state-1 :state-2]])
;; gives the following:
;; 2. Unhandled java.util.concurrent.ExecutionException
;; java.lang.IllegalStateException: :db.error/cas-failed Compare
;; failed: :state-1 17592186045417
;; promise.clj: 10 datomic.promise/throw-executionexception-if-throwable
;; promise.clj: 54 datomic.promise/settable-future/reify
;; core.clj: 2204 clojure.core/deref
;; REPL: 1 traktor.error/eval28378
;; Compiler.java: 6792 clojure.lang.Compiler/eval
;; Compiler.java: 6755 clojure.lang.Compiler/eval
;; core.clj: 3079 clojure.core/eval
;; main.clj: 240 clojure.main/repl/read-eval-print/fn
;; main.clj: 240 clojure.main/repl/read-eval-print
;; main.clj: 258 clojure.main/repl/fn
;; main.clj: 258 clojure.main/repl
;; RestFn.java: 1523 clojure.lang.RestFn/invoke
;; interruptible_eval.clj: 53 clojure.tools.nrepl.middleware.interruptible-eval/evaluate/fn
;; AFn.java: 152 clojure.lang.AFn/applyToHelper
;; AFn.java: 144 clojure.lang.AFn/applyTo
;; core.clj: 628 clojure.core/apply
;; core.clj: 1866 clojure.core/with-bindings*
;; RestFn.java: 425 clojure.lang.RestFn/invoke
;; interruptible_eval.clj: 51 clojure.tools.nrepl.middleware.interruptible-eval/evaluate
;; interruptible_eval.clj: 183 clojure.tools.nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
;; interruptible_eval.clj: 152 clojure.tools.nrepl.middleware.interruptible-eval/run-next/fn
;; AFn.java: 22 clojure.lang.AFn/run
;; ThreadPoolExecutor.java: 1142 java.util.concurrent.ThreadPoolExecutor/runWorker
;; ThreadPoolExecutor.java: 617 java.util.concurrent.ThreadPoolExecutor$Worker/run
;; Thread.java: 745 java.lang.Thread/run
;; 1. Caused by datomic.impl.Exceptions$IllegalStateExceptionInfo
;; :db.error/cas-failed Compare failed: :state-1 17592186045417
;; {:e :entity,
;; :a :state,
;; :v-old :state-1,
;; :v 17592186045417,
;; :db/error :db.error/cas-failed}
;; error.clj: 88 datomic.error/state
;; builtins.clj: 74 datomic.builtins/compare-and-swap
;; REPL: 1 traktor.error/eval28334/fn
;; AFn.java: 171 clojure.lang.AFn/applyToHelper
;; AFn.java: 144 clojure.lang.AFn/applyTo
;; core.clj: 630 clojure.core/apply
;; db.clj: 2398 datomic.db.ProcessExpander/inject
;; db.clj: 2304 datomic.db.ProcessInpoint/inject
;; db.clj: 2454 datomic.db/with-tx/inject-all/fn
;; PersistentVector.java: 333 clojure.lang.PersistentVector/reduce
;; core.clj: 6514 clojure.core/reduce
;; db.clj: 2454 datomic.db/with-tx/inject-all
;; db.clj: 2458 datomic.db/with-tx
;; peer.clj: 556 datomic.peer.LocalConnection/fn
;; peer.clj: 556 datomic.peer.LocalConnection/transactAsync
;; peer.clj: 548 datomic.peer.LocalConnection/transact
;; api.clj: 94 datomic.api/transact
;; REPL: 1 traktor.error/eval28378
;; Compiler.java: 6792 clojure.lang.Compiler/eval
;; Compiler.java: 6755 clojure.lang.Compiler/eval
;; core.clj: 3079 clojure.core/eval
;; main.clj: 240 clojure.main/repl/read-eval-print/fn
;; main.clj: 240 clojure.main/repl/read-eval-print
;; main.clj: 258 clojure.main/repl/fn
;; main.clj: 258 clojure.main/repl
;; RestFn.java: 1523 clojure.lang.RestFn/invoke
;; interruptible_eval.clj: 53 clojure.tools.nrepl.middleware.interruptible-eval/evaluate/fn
;; AFn.java: 152 clojure.lang.AFn/applyToHelper
;; AFn.java: 144 clojure.lang.AFn/applyTo
;; core.clj: 628 clojure.core/apply
;; core.clj: 1866 clojure.core/with-bindings*
;; RestFn.java: 425 clojure.lang.RestFn/invoke
;; interruptible_eval.clj: 51 clojure.tools.nrepl.middleware.interruptible-eval/evaluate
;; interruptible_eval.clj: 183 clojure.tools.nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
;; interruptible_eval.clj: 152 clojure.tools.nrepl.middleware.interruptible-eval/run-next/fn
;; AFn.java: 22 clojure.lang.AFn/run
;; ThreadPoolExecutor.java: 1142 java.util.concurrent.ThreadPoolExecutor/runWorker
;; ThreadPoolExecutor.java: 617 java.util.concurrent.ThreadPoolExecutor$Worker/run
;; Thread.java: 745 java.lang.Thread/run
;; THIS WORKS:
;; ********* :state-1 as entid:
@(d/transact conn [[:db.fn/cas :entity :state (d/entid (db conn) :state-1) :state-2]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment