Fork me on GitHub
#xtdb
<
2023-03-15
>
Stef Coetzee22:03:05

Playing around with XTDB using PostgreSQL as storage and am running into an error when attempting transactions. The error:

; Execution error (NullPointerException) at xtdb.cache/evict (cache.clj:14).
; Cannot invoke "xtdb.cache.ICache.evict(Object)" because "cache" is null
Any guidance on why this might be would be greatly appreciated. 😃 The entirety of the project consists of deps.edn and a core.clj file. The contents of the deps.edn file:
{:paths ["src"]
 :deps {org.clojure/clojure {:mvn/version "1.11.1"}

        com.xtdb/xtdb-jdbc {:mvn/version "1.23.1"}
        org.postgresql/postgresql {:mvn/version "42.5.1"}}}
The contents of the core.clj file:
(ns api.db.core
  (:require [xtdb.jdbc]
            [xtdb.jdbc.psql]
            [xtdb.api :as xt]))

;; Edited after assistance: note quoting of dialect, tx-log, and document-store.
(def config
  {:xtdb.jdbc/connection-pool
   {:dialect {:xtdb/module 'xtdb.jdbc.psql/->dialect}
    :pool-opts {}
    :db-spec {:host "127.0.0.1"
              :port 5432
              :dbname "..."
              :user "..."
              :password "..."}}

   :xtdb/tx-log {:xtdb/module 'xtdb.jdbc/->tx-log
                 :connection-pool :xtdb.jdbc/connection-pool}

   :xtdb/document-store {:xtdb/module 'xtdb.jdbc/->document-store
                         :connection-pool :xtdb.jdbc/connection-pool}})

(def xtdb-node (xt/start-node config))

(comment
  (.close xtdb-node)

  ;; Example from docs
  (xt/submit-tx xtdb-node
                [[::xt/put
                  {:xt/id :dbpedia.resource/Pablo-Picasso :first-name :Pablo}]])

  (xt/q (xt/db xtdb-node)
        '{:find [?e]
          :where [[?e :xt/id ?eid]]}))
The query below the transaction in the listing above returns #{} , which I suspect is due to nothing having been transacted to the database. Thanks for your time!

refset23:03:34

Hey @U03CPPKDXBL I'll have a proper think tomorrow, but briefly just noticed you're missing xtdb-core in your deps. I'm not sure what the behaviour is without it. Might be a red herring

Stef Coetzee04:03:38

Thanks @U899JBRPF, I've added it to be safe:

;; deps.edn
{:paths ["src"]
 :deps {org.clojure/clojure {:mvn/version "1.11.1"}

        com.xtdb/xtdb-core {:mvn/version "1.23.1"}
        com.xtdb/xtdb-jdbc {:mvn/version "1.23.1"}
        org.postgresql/postgresql {:mvn/version "42.5.1"}}}
Running clj -P after didn't pull in any new dependencies AFAICT. Think it might've been pulled in with xtdb-jdbc. Seeing the same error as before. (Separately: is https://discuss.xtdb.com the preferred place to engage nowadays?)

👌 2
Thomas Moerman08:03:57

perhaps you have a race condition here, what happens if you add xt/await-tx after xt/submit-tx?

Thomas Moerman08:03:26

Like this:

(->> [[::xt/put
       {:xt/id :dbpedia.resource/Pablo-Picasso :first-name :Pablo}]]
     (xt/submit-tx xtdb-node)
     (xt/await-tx xtdb-node))

Stef Coetzee08:03:21

Thanks for the suggestion, @U052A8RUT. Tested this approach now; ran into the same error as above.

Thomas Moerman08:03:33

Ah sorry, i read the issue too quickly. My suggestion is irrelevant for your issue, my bad.

👍 2
refset11:03:49

@U03CPPKDXBL can you share the full stack trace please? Is it happening consistently? Try quoting 'xtdb.jdbc.psql/->dialect

refset11:03:09

naively it sounds like the CachedDocumentStore isn't initialised properly (likely along with much of the rest of node config), so it's failing on the start-node step but not giving you proper feedback

Stef Coetzee11:03:04

https://clojurians.slack.com/archives/CG3AM2F7V/p1678964749730039?thread_ts=1678919045.358149&amp;cid=CG3AM2F7V Sure thing:

; Execution error (NullPointerException) at xtdb.cache/evict (cache.clj:14).
; Cannot invoke "xtdb.cache.ICache.evict(Object)" because "cache" is null
xtdb.cache/evict (cache.clj:14)
xtdb.cache/evict (cache.clj:13)
xtdb.document-store.CachedDocumentStore/iter (document_store.clj:56)
clojure.lang.LazySeq/sval (LazySeq.java:42)
clojure.lang.LazySeq/seq (LazySeq.java:51)
clojure.lang.RT/seq (RT.java:535)
clojure.lang.LazilyPersistentVector/create (LazilyPersistentVector.java:44)
clojure.core/vec (core.clj:379)
clojure.core/vec (core.clj:369)
xtdb.document-store.CachedDocumentStore/submit_docs (document_store.clj:54)
xtdb.node.XtdbNode/submit_tx_async (node.clj:220)
xtdb.node.XtdbNode/submit_tx (node.clj:223)
api.db.core/eval25867 (NO_SOURCE_FILE:28)
clojure.lang.Compiler/eval (Compiler.java:7194)
clojure.core/eval (core.clj:3215)
clojure.core/eval (core.clj:3211)
nrepl.middleware.interruptible-eval/evaluate (interruptible_eval.clj:87)
clojure.core/apply (core.clj:667)
clojure.core/with-bindings* (core.clj:1990)
nrepl.middleware.interruptible-eval/evaluate (interruptible_eval.clj:87)
clojure.main/repl (main.clj:437)
clojure.main/repl (main.clj:458)
clojure.main/repl (main.clj:368)
nrepl.middleware.interruptible-eval/evaluate (interruptible_eval.clj:84)
nrepl.middleware.interruptible-eval/evaluate (interruptible_eval.clj:56)
nrepl.middleware.interruptible-eval/interruptible-eval (interruptible_eval.clj:152)
nrepl.middleware.session/session-exec (session.clj:218)
nrepl.middleware.session/session-exec (session.clj:217)
java.lang.Thread/run (Thread.java:833)

👌 2
Stef Coetzee11:03:52

https://clojurians.slack.com/archives/CG3AM2F7V/p1678964829898239?thread_ts=1678919045.358149&amp;cid=CG3AM2F7V Thanks @U899JBRPF. Should've thought about quoting; it works! For fellow travelers in future:

(def config
  {:xtdb.jdbc/connection-pool
   {:dialect {:xtdb/module 'xtdb.jdbc.psql/->dialect}
    :pool-opts {}
    :db-spec {:host "127.0.0.1"
              :port 5432
              :dbname "..."
              :user "..."
              :password "..."}}

   :xtdb/tx-log {:xtdb/module 'xtdb.jdbc/->tx-log
                 :connection-pool :xtdb.jdbc/connection-pool}

   :xtdb/document-store {:xtdb/module 'xtdb.jdbc/->document-store
                         :connection-pool :xtdb.jdbc/connection-pool}})

🙌 2
refset11:03:34

Great, thanks for confirming that. I just opened https://github.com/xtdb/xtdb/issues/1919 to improve the error handling - apologies for the confusion 🙂

gratitude 4
refset02:03:43

Whilst drifting off to sleep days later it occurred to me that I completely forgot about answering the Discuss forum question - more participation there would be most welcome, I'd like to see it grow much bigger than this channel :)

👍 2