Fork me on GitHub
#xtdb
<
2023-01-12
>
Hukka06:01:02

Looks like the last issue against milestone 1.22.2 got closed yesterday:crossed_fingers:

🔜 2
Kaka09:01:59

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.

refset14:01:09

Hi @USJT4C8BT thanks for the report. Is everything else looking like it's working okay?

refset14:01:00

Or do you mean the retry never succeeds and you see this message + error repeatedly?

Kaka23:01:05

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" .

Kaka00:01:19

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))

refset11:01:32

I think your config is wrong, as the pool is nil as per the error

refset11:01:41

can you share the full config map?

Kaka13:01:46

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)}))

refset16:01:00

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} ?

👍 2
Kaka23:01:11

Thanks! Problem is fixed.

tatut12:01:38

re: count aggregate, I’m baffled why adding more clauses causes to return a larger count number

tatut12:01:21

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 one

tatut12:01:37

If I just find e and count the returned ids, I get the correct number

tatut12:01:30

as well as with count-distinct aggregate… what am I missing in the behaviour of count

tatut13:01:04

there 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

tatut13:01:22

ah, now I get it… because [e :rows] being a multi valued vector, it will count each row it finds for e?

refset13:01:06

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)

refset13:01:24

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

tatut13:01:25

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

refset13:01:25

ah yep, that's an oversight, thanks for mentioning it

refset13:01:04

for your specific example however, I'm struggling to understand the behaviour. Is the value under :type ever a set or vector?

tatut13:01:23

no the type is a keyword, but the :rows is a vector

tatut13:01:03

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

tatut13:01:09

so it seems to be counting all the rows

refset13:01:43

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

👍 2
tatut13:01:21

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

refset13:01:27

arguably [e :rows] could use the AE index and then it would give the 'correct' result you are expecting

tatut13:01:56

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)

tatut13:01:45

ah it does say “including any duplicates”

refset13:01:47

I agree, I think it's not unreasonable to be expecting bag->set transformation to be happening before aggregates are applied

tatut13:01:49

but I still didn’t get it

refset13:01:52

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)

jarohen13:01:06

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

jarohen13:01:15

but that'd be quite a breaking change

tatut13:01:38

now introduce q2 function, as Rich would say to do 😄

😄 2
💡 2
flefik17:01:56

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.

FiVo19:01:37

For valid timestamp we recently added this. See the 1.22.1 release notes.

2
FiVo19:01:17

There also is history predicate section on that doc page.

refset21:01:09

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)

flefik13:01:26

Thank you!