This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-07-11
Channels
- # babashka (13)
- # beginners (17)
- # bristol-clojurians (1)
- # calva (23)
- # cider (5)
- # clj-kondo (32)
- # cljsrn (2)
- # clojure (167)
- # clojure-dev (23)
- # clojure-europe (6)
- # clojure-uk (8)
- # clojurescript (5)
- # cursive (7)
- # datomic (12)
- # emacs (4)
- # events (6)
- # fulcro (2)
- # graalvm (1)
- # interop (10)
- # leiningen (8)
- # local-first-clojure (1)
- # luminus (2)
- # meander (36)
- # planck (3)
- # re-frame (3)
- # reagent (3)
- # sci (2)
- # spacemacs (4)
- # sql (1)
- # test-check (6)
- # tools-deps (22)
- # xtdb (75)
(let [node (crux/start-node
{:crux.node/topology '[crux.standalone/topology
crux.kv.lmdb/kv-store]
:crux.kv/db-dir (str (io/file "db"))})]
(crux/submit-tx node [[:crux.tx/put
{:crux.db/id :img,
:description "",
:tags
["female"
"grass"],
:source "",
:format "PNG",
:mime-type "image/png"}]])
(crux/q (crux/db node)
'{:find [id]
:where [[e :crux.db/id id]]
:full-results? true}))
OK, I've simplified it down to pretty much the simplest thing that doesn't work, and I'm baffled. Why when I do this lookup is the only thing in the database => #{[nil]}?
Hi @frosku. This could be that you need to use await-tx to know that that the tx has completed on the node, before you attempt a query.
It seems to work with rocksdb, but rocksdb has other issues for me -- it never seems to let go of its lock.
I'm aware that running a Crux node will result in a lock against the rocks db file, though we haven't encountered it being an issue for users.
20-07-11 02:57:48 canterlot WARN [crux.kv.memdb:1] - Using sync? on MemKv has no effect. Persistence is disabled.
20-07-11 02:57:48 canterlot INFO [crux.tx:1] - Started tx-consumer
20-07-11 02:57:48 canterlot INFO [crux.hash.jnr:1] - unknown
20-07-11 02:57:48 canterlot INFO [crux.hash:1] - Using libgcrypt for ID hashing.
(defn get-crux-node
[database]
(crux/start-node {:crux.node/topology '[crux.standalone/topology
crux.kv.lmdb/kv-store]
:crux.kv/db-dir (str (io/file database))}))
The standalone topologies uses two KV stores, one for the tx log and one for indexing. We are working on making this less confusing, I think you been caught up by https://github.com/juxt/crux/issues/818
Yeah this is a very recent change - the memdb used for indexing doesn't need to be logging a sync warning - now noted that we need to hide it, thanks!
Can someone explain what is going on here? Is this a case of the index not being updated before the query is run? How can this be prevented?
pengine.core> (defn start-standalone-node ^crux.api.ICruxAPI [storage-dir]
(crux/start-node {:crux.node/topology '[crux.standalone/topology]
:crux.kv/db-dir (str (io/file storage-dir "db"))}))
(def node (start-standalone-node "crux-store"))
=> #'pengine.core/start-standalone-node=> #'pengine.core/node
pengine.core> (defn q
[query]
(crux/q (crux/db node) query))
=> #'pengine.core/q
pengine.core> (defn add-test-doc []
(crux/submit-tx
node
[[:crux.tx/put
{:crux.db/id (uuid)
:type :test}]]))
=> #'pengine.core/add-test-doc
pengine.core> (defn find-test-doc-id []
(let [query {:find '[?e]
:where [['?e :type :test]]}] (q query)))
=> #'pengine.core/find-test-doc-id
pengine.core> (let [doc (add-test-doc)]
(find-test-doc-id))
=> #{}
pengine.core> (let [doc (add-test-doc)]
(find-test-doc-id))
=> #{[#uuid "72f065f8-522b-45fc-825e-360e6799cccc"]}
Hi @U09UV3WP6. Have you tried calling 'sync' (see crux api).?
Submit is async, so normally you'd have to wait for it to index before you can read.
Which version of Crux are you on?
@U09UV3WP6 1.9.0 has known bugs that might be related, see the announcement earlier in the chat yesterday https://clojurians.slack.com/archives/CG3AM2F7V/p1594394543220800 please try again with 1.9.2 and see if you have the same result
Could you verify the same behaviour on 1.9.2-beta? If it's still the same I'll try to replicate. I'm still learning the ropes myself so bear with me.
Sync isn't necessarily fool-proof in a read-your-writes scenario, try using await-tx and pass in the result of submit-tx
Ah yes, I should have mentioned await-tx. Thanks @refset
@frosku you can certainly do that. I usually have my Crux node defined as a component in an Integrant or component set up, and access it via the 'system'. Or you can just def it somewhere.
https://github.com/Frosku/mirrorpool/blob/master/src/mirrorpool/core.clj ^ The variable is parsed here
https://github.com/Frosku/mirrorpool/blob/master/src/mirrorpool/derpi.clj
^ Then fed into get-crux-node
here.
What I'd like to do is ideally while the script is running, query the db to make sure stuff is going into it.
Ok. So the question is whether 2 jvms can share a node's index dir structure. I'm not sure. What's your index engine, RocksDB or LMDB?
You just need a shared tx log, Kafka is one option.
LMDB should be good for that yes. I think you do need to scale out and create another node that is hooked up against the same tx log.
Just check my sanity here, once this script is finished, I should be able to re-mount the db from REPL and it should be queryable?
I believe so, yes.
Because I do a (System/exit 0)
at the end and I don't want to lose data lol, so not sure if I should be doing something explicit in cleanup step to wait for it to finish.
No. The configuration docs say the sync default is false.
But you can configure that
(defn h
[]
(let [node (get-crux-node "/derp/db")]
(crux/q (crux/db node) '{:find [id] :where [[e :crux.db/id id]] :full-results? true})))
(h)
=> #{[nil]}
Which Crux version @frosku
Try with 20.07-1.9.2-beta
There's a particular issue you're hitting with 1.9.1 that's fixed in 1.9.2
Yes, but I think that's irrelevant.
But better to align
I believe lmdb is still alpha, you'll get a maven download error if you get it wrong
When the script closes, the query returns data, but when I try to fire up a repl with the same node, it returns #{[nil]}
And then if I run it for a different set of data it returns nil at the end of script execution
OK, so turns out I needed to do a bit more to persist the event log and then I could query back again
(defn get-crux-node
[database]
(crux/start-node {:crux.node/topology '[crux.standalone/topology
crux.kv.lmdb/kv-store]
:crux.kv/db-dir (str (io/file database "db"))
:crux.standalone/event-log-kv-store 'crux.kv.lmdb/kv
:crux.standalone/event-log-dir (str (io/file database "evt"))
:crux.standalone/event-log-sync? true
:crux.kv/sync? true}))