This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-01-12
Channels
- # announcements (6)
- # babashka (45)
- # beginners (4)
- # calva (19)
- # cider (2)
- # clj-kondo (10)
- # clj-yaml (10)
- # clojure (25)
- # clojure-boston (1)
- # clojure-conj (3)
- # clojure-europe (34)
- # clojure-losangeles (5)
- # clojure-nl (1)
- # clojure-norway (11)
- # clojure-uk (2)
- # clojurescript (84)
- # cursive (10)
- # datalevin (3)
- # figwheel-main (1)
- # fulcro (1)
- # jobs (5)
- # joyride (25)
- # lsp (17)
- # malli (18)
- # nbb (1)
- # off-topic (1)
- # re-frame (22)
- # remote-jobs (9)
- # scittle (3)
- # shadow-cljs (26)
- # sql (16)
- # tools-build (12)
- # xtdb (44)
Looks like the last issue against milestone 1.22.2 got closed yesterday:crossed_fingers:
I got the following error message flashing very fast from log output:
[xtdb-tx-subscription-2] WARN xtdb.tx.subscribe - Error polling for txs, will retry
java.lang.IllegalArgumentException: No implementation of method: :get-connection of protocol: #'juxt.clojars-mirrors.nextjdbc.v1v2v674.next.jdbc.protocols/Connectable found for class: nil
at clojure.core$_cache_protocol_fn.invokeStatic(core_deftype.clj:584)
at clojure.core$_cache_protocol_fn.invoke(core_deftype.clj:576)
at juxt.clojars_mirrors.nextjdbc.v1v2v674.next.jdbc.protocols$eval19113$fn__19114$G__19104__19121.invoke(protocols.clj:24)
at juxt.clojars_mirrors.nextjdbc.v1v2v674.next.jdbc$get_connection.invokeStatic(jdbc.clj:167)
at juxt.clojars_mirrors.nextjdbc.v1v2v674.next.jdbc$get_connection.invoke(jdbc.clj:146)
at xtdb.jdbc.JdbcTxLog.open_tx_log(jdbc.clj:165)
at xtdb.tx.subscribe$handle_polling_subscription$fn__21561$fn__21562.invoke(subscribe.clj:52)
at xtdb.tx.subscribe$handle_polling_subscription$fn__21561.invoke(subscribe.clj:51)
at xtdb.tx.subscribe$completable_thread$fn__21549.invoke(subscribe.clj:21)
at clojure.lang.AFn.run(AFn.java:22)
at java.base/java.lang.Thread.run(Thread.java:829)
I have the postgres dep included in deps.edn org.postgresql/postgresql {:mvn/version "42.2.18"}
as well as many others from xtdb/jdbc
module.
The setting of the node starting is like:
{:xtdb/module module
:connection-pool
{:dialect {:xtdb/module psql/->dialect}
:db-spec {:jdbcUrl "jdbc:"
:dbname "xtdb" :user "name" :password "pass"}}
:poll-sleep-duration "PT1S"}
My jdk env is:
(System/getenv "JAVA_HOME")
;; => "/nix/store/cfhirlpfyad0ahwy7amm77y9xmyk4iqf-openjdk-11.0.15+10/lib/openjdk"
I tried to include different version of postgresql
and HikariCP
, but got no luck using the JDBC storage. Can you help? Thanks in advance.Hi @USJT4C8BT thanks for the report. Is everything else looking like it's working okay?
Thanks for your reply. Starting the memory node (def xtdb-mem-node (xt/start-node {}))
is working okey.
Yes, the retry never succeeded and above error flashing very fast (like PT0.1S) even I already have the setting :poll-sleep-duration "PT1S"
.
I tried to use jdbc, hikari and postgres separately. They can work fine as follows:
(ns user.db-pg
(:require [honey.sql :as sql]
[juxt.clojars-mirrors.nextjdbc.v1v2v674.next.jdbc :as jdbc]
[juxt.clojars-mirrors.nextjdbc.v1v2v674.next.jdbc.connection :as jdbcc]
[clojure.java.data :as jd]
[clojure.string :as str]
[ :as xio]
[xtdb.jdbc.psql :as psql])
(:import (clojure.lang MapEntry)
(com.zaxxer.hikari HikariConfig HikariDataSource)
( Closeable)
(java.sql Timestamp ResultSet)
(java.time Duration)
(java.util Date)))
(def db-spec
{:host "localhost"
:port 5432
:user "user"
:password "pass"
:dbname "xtdb"
:dbtype "postgres"})
(def ds (jdbc/get-datasource db-spec))
(defn r [m] (jdbc/execute! ds (sql/format m)))
(defrecord HikariConnectionPool [^HikariDataSource pool dialect]
Closeable
(close [_]
(xio/try-close pool)))
(comment
(r {:select [:table_name] :from [:'information_schema.tables] :where [:= :table_schema "public"]})
(let [jdbc-url (-> (jdbcc/jdbc-url db-spec) (str/replace #"\?$" ""))
pool-opts {:jdbcUrl jdbc-url}
pool (HikariDataSource. (jd/to-java HikariConfig pool-opts))]
(try
(catch Throwable t
(xio/try-close pool)
(throw t)))
(->HikariConnectionPool pool {:xtdb/module psql/->dialect}))
)
It seems the problem comes from here:
(subscribe [this after-tx-id f]
(tx-sub/handle-polling-subscription this after-tx-id {:poll-sleep-duration (Duration/ofMillis 100)} f))
it should look more like https://docs.xtdb.com/storage/jdbc/#_jdbc_as_a_transaction_log
Thanks. My config is like this:
(defn jdbc-module
[module]
{:xtdb/module module
:connection-pool
{:dialect {:xtdb/module psql/->dialect}
:db-spec {:host "localhost"
:port 5432
:user "user"
:password "pass"
:dbname "xtdb"
:dbtype "postgres"}}
:poll-sleep-duration "PT1S"})
(def node
(xt/start-node
{:xtdb/tx-log (jdbc-module jdbc/->tx-log)
:xtdb/document-store (jdbc-module jdbc/->document-store)}))
hmm, maybe there are some missing quotes :thinking_face: perhaps try with (jdbc-module 'jdbc/->tx-log)
(jdbc-module 'jdbc/->document-store)
and {:xtdb/module 'psql/->dialect}
?
re: count
aggregate, I’m baffled why adding more clauses causes to return a larger count number
for example
(xt/q db '{:find [(count e)] :where [[e :type :some-type]]})
vs
(xt/q db '{:find [(count e)] :where [[e :type :some-type] [e :rows]]})
I would expect the second one to return at most the same count as the first onethere is a warning of > Return a single count of all values including any duplicates (note: this always performs a scan - no statistics or other stateful materializations are used) in the docs, but I’m unable to determine what this means
ah, now I get it… because [e :rows]
being a multi valued vector, it will count each row it finds for e?
the thing count
is actually aggregating over is the output of the result stream (which is approximately the ~same thing as you see consuming from open-q
without the aggs in :find)
in practice this result stream may not correspond with the bag or set semantics you are looking for, and it can be affected by the join order
btw, should this table have count-distinct? https://docs.xtdb.com/language-reference/datalog-queries/#find-aggregate it is only mentioned in the example below
for your specific example however, I'm struggling to understand the behaviour. Is the value under :type
ever a set or vector?
if I do (xt/q db '{:find [(count r)] :where [[e :type :some-type] [e :rows r]]})
I get the same count value as the latter of the above examples
right, that makes sense, IIRC [e :rows]
is just sugar for [e :rows _]
which means it still uses the AEV index, so it will produce multiple (duplicate, because V is ignored) outputs when iterating
maybe the docs for count could be clearer as well, it wasn’t obvious to me that it wouldn’t have the same set semantics
arguably [e :rows]
could use the AE index and then it would give the 'correct' result you are expecting
I think most people who are doing pagination will see count and think that is the correct aggregate to use (if you need a list of pages and have to have a total count of items)
I agree, I think it's not unreasonable to be expecting bag->set transformation to be happening before aggregates are applied
and arguably XT therefore lacks an easy way to perform set-based aggregates, although you can workaround it by wrapping your query in an outer query and performing the aggregation at that level (since subquery results get converted to sets before being returned up)
tbh, ideally we'd return bags, we get too many questions around the set behaviour, and the different behaviours of q with/without limit/offset/etc are counter-intuitive
Can I get valid-timestamp or transaction-timestamp for a document in a :find
query somehow? (i.e. without using the History API)
I’ve tried ::xt/valid-time etc.
ah, yeah that would have been confusing without mentioning that I wasn't talking about the new built-in history predicates https://docs.xtdb.com/language-reference/datalog-queries/#_history_predicates - I was just showing what the alternative workaround approach (for tt)