Fork me on GitHub
#xtdb
<
2020-06-24
>
ouvasam13:06:27

Dear all, i have a problem with one query I have a record like this in the db

{:translation/value qsdqsdqsqs kjh qsdkjh qsd, :translation/id :translation-en-728-1-1-DRAFT, :code-system/id 1, :translation/language en, :translation/status :DRAFT, :concept/id 728, :app/type :app/Translation, :jurisdiction/id 1, :crux.db/id :translation-en-728-1-1-DRAFT, :app/modification-date Wed Jun 24 15:27:27 CEST 2020}
with a query like this i can't get the entity
(crux/q (crux/db node)
                     {:find '[?id]
                      :where '[[?e :crux.db/id ?id]
                               [?e :app/type :app/Translation]
                               [?e :translation/status status]
                               [?e :jurisdiction/id 1]]
                      :args [{'status :DRAFT
                              'jid jid}]
                      :order-by '[[?id :asc]]
                      :limit  limit
                      :offset offset})]
but if i remove the [?e :translation/status status] part, i can get it Do i do something wrong ? I did test the type of :translation/status and it is a keyword

refset14:06:03

Hi @ouvasam I can't see anything obviously wrong. Are you able to paste the response of running crux/entity such that I can see the entire document(s)?

refset14:06:29

Alternatively, I have some free time now if you wanted to pair for the next 30m 🙂 just DM me to arrange

ouvasam14:06:46

Yes that is this

{:translation/value qsdqsdqsqs kjh qsdkjh qsd, :translation/id :translation-en-728-1-1-DRAFT, :code-system/id 1, :translation/language en, :translation/status :DRAFT, :concept/id 728, :app/type :app/Translation, :jurisdiction/id 1, :crux.db/id :translation-en-728-1-1-DRAFT, :app/modification-date Wed Jun 24 15:27:27 CEST 2020}
I should something stupid but as explain above the problem appear once i modify the original entity to create a new one by changing its status and its crux.db/id That means that before doing that everything is correct

ouvasam14:06:43

the problematic query return [] and the last i sent return the correct [id? status?] I also tried to add status in :find but nothing more., I must do something wrong ...

refset14:06:01

Ah okay. Can you show what the :PUBLISHED version looks like also please?

ouvasam15:06:30

Dear all, i have a problem with one query I have a record like this in the db

{:translation/value qsdqsdqsqs kjh qsdkjh, :translation/id :translation-en-728-1-1-PUBLISHED, :code-system/id 1, :translation/language en, :translation/status :PUBLISHED, :concept/id 728, :app/type :app/Translation, :jurisdiction/id 1, :crux.db/id :translation-en-728-1-1-PUBLISHED, :app/modification-date Wed Jun 24 15:27:27 CEST 2020}

👍 3
refset16:06:54

Thanks, unfortunately I still can't see anything that might explain your situation. It could be useful to compare the two join orders, if you are able to set the logback.xml entry for crux.query=DEBUG If you are able to reproduce a minimal example in a gist or issue I can dig into it further. I can also see if I can reproduce it myself with some similar looking data

ouvasam06:06:26

Many thanks @U899JBRPF i'll try to find first what it can be cause i am sure it between my chair and my screen that the problem should be 🙂

🙏 3
ouvasam08:06:21

For now, i see that the problem appears after an "evict"

(defn evict
  [data]
  (println "evicting" data)
  (crux/submit-tx
   node
   (mapv (fn [d]
           (println "evict entity " d)
           [:crux.tx/evict d])
         data)))
I do an insert via crux.tx/put and then in a second transaction i do the evict of another item

refset09:06:20

so an item (i.e. document), with a completely unrelated :crux.db/id is somehow causing it, you think? hmm

ouvasam12:06:07

arff ... i switch back to version 20.05-1.8.5-alpha-SNAPSHOT and everything seems to work fine I did try to do a gist with the principles applied but could not find any errors there ... It seems that i have multiple call to crux in parallel the problem appear The same queries and transactions works perfectly and suddenly i can't get the results. If i recreate a new one, the items that should have appears before reappears ... I continue to find what i made wrong

ouvasam12:06:07

here is the gist but this code works perfectly ...

ouvasam12:06:01

Here is an example of the problem in the log i've made

# GET THE TRANSLATIONS FOR A CONCEPT PASSING params 728 and 1
java.lang.Long 728 java.lang.Long 1 TRANSLATIONS BY CONCEPT  #{[:translation-en-728-1-1-published] [:translation-fr-728-1-1-published] [:translation-en-728-1-1-draft] [:translation-fr-728-1-1-draft]}

# INSERT AN ITEM BASED ON A DRAFT ONE 
INSERT ITEM  {:translation/value qsdqsqsdqsqsdddq, :translation/id :translation-en-728-1-1-published, :code-system/id 1, :translation/language en, :translation/status :published, :concept/id 728, :app/type :app/Translation, :jurisdiction/id 1, :crux.db/id :translation-en-728-1-1-published, :app/modification-date Thu Jun 25 14:20:07 CEST 2020}

# EVICT THE DRAFT ONE
evict entity  :translation-en-728-1-1-draft

# GET THE TRANSLATIONS FOR A CONCEPT PASSING params 728 and 1
java.lang.Long 728 java.lang.Long 1 TRANSLATIONS BY CONCEPT  #{}

ouvasam12:06:26

As i said if create a new one, all the entities are retrieved after

ouvasam12:06:56

no problem anymore when i switched back 20.05-1.8.5-alpha-SNAPSHOT

refset13:06:21

so I just ran the code in the gist and left a comment, but I'm not sure if my output is what you expect or not though, it looks right to me, please take a look. https://gist.github.com/ouvanous/f046da540656ed17beb509d579ebb27c#gistcomment-3354175

refset13:06:58

out of interest, how come you want to use evict and not delete ? Do you have a regulatory requirement?

ouvasam13:06:30

I thought delete was only for an instance time not the complete record

ouvasam13:06:49

and yes i get the same result with the gist which is correct . Really don't know what's going on with my full code ...

ouvasam13:06:23

i try to add the logs with logback to have a better understanding

ouvasam14:06:16

Here are the logs

ouvasam14:06:17

15:58:01.171 [qtp1933800627-24] DEBUG crux.memory - :pool-allocation-stats {:allocated 4063232, :deallocated 262144, :in-use 3801088}
15:58:01.262 [crux-tx-consumer] DEBUG crux.tx - Indexing tx-id: 8 tx-events: 1
15:58:02.465 [crux.query.query-pool-thread-14] DEBUG crux.memory - :pool-allocation-stats {:allocated 4194304, :deallocated 262144, :in-use 3932160}
15:58:02.465 [crux.query.query-pool-thread-14] DEBUG crux.query - :query {:find [id? status?], :where [[e? :crux.db/id id?] [e? :app/type :app/Translation] [e? :translation/status status?] [e? :jurisdiction/id jid?]], :arg-keys [#{jid?}]}
15:58:02.465 [crux.query.query-pool-thread-14] DEBUG crux.query - :join-order :aev e? status? {:e e?, :a :translation/status, :v status?}
15:58:02.465 [crux.query.query-pool-thread-14] DEBUG crux.query - :join-order :ave jid? e? {:e e?, :a :jurisdiction/id, :v jid?}
15:58:02.465 [crux.query.query-pool-thread-14] DEBUG crux.query - :join-order :ave :app/Translation e? {:e e?, :a :app/type, :v :app/Translation}
15:58:02.465 [crux.query.query-pool-thread-14] DEBUG crux.query - :where [[:triple {:e e?, :a :crux.db/id, :v id?}] [:triple {:e e?, :a :app/type, :v :app/Translation}] [:triple {:e e?, :a :translation/status, :v status?}] [:triple {:e e?, :a :jurisdiction/id, :v jid?}]]
15:58:02.465 [crux.query.query-pool-thread-14] DEBUG crux.query - :vars-in-join-order [:app/Translation jid? e? status? id?]
15:58:02.466 [crux.query.query-pool-thread-14] DEBUG crux.query - :attr-stats {:crux.db/id 113, :translation/status 1, :jurisdiction/id 6}
15:58:02.466 [crux.query.query-pool-thread-14] DEBUG crux.query - :var->bindings {id? #crux.query.VarBinding{:e-var nil, :var id?, :attr nil, :result-index 4, :result-name crux.query.value/id?, :type :pred, :value? true}, jid? #crux.query.VarBinding{:e-var e?, :var jid?, :attr :jurisdiction/id, :result-index 1, :result-name e?, :type :entity, :value? false}, e? #crux.query.VarBinding{:e-var e?, :var e?, :attr :crux.db/id, :result-index 2, :result-name e?, :type :entity, :value? false}, status? #crux.query.VarBinding{:e-var e?, :var status?, :attr :translation/status, :result-index 3, :result-name e?, :type :entity, :value? false}}
15:58:02.466 [crux.query.query-pool-thread-14] DEBUG crux.query - :query-time-ms 2
15:58:02.466 [crux.query.query-pool-thread-14] DEBUG crux.query - :query-result-size 0

refset15:06:07

delete is simpler to use, as keeping the history around helps reason about how data changes. I would always use it instead of evict unless you really have a hard requirement to fully remove old data. Also you can delete from now until max-time

refset15:06:32

thanks for the debug log, the interesting line is:

15:58:02.465 [crux.query.query-pool-thread-14] DEBUG crux.query - :vars-in-join-order [:app/Translation jid? e? status? id?]

refset15:06:49

how does it compare with your other query? the one that fails?

ouvasam15:06:06

15:58:00.701 [crux.query.query-pool-thread-12] DEBUG crux.memory - :pool-allocation-stats {:allocated 3801088, :deallocated 262144, :in-use 3538944}
15:58:00.701 [crux.query.query-pool-thread-12] DEBUG crux.query - :query {:find [id? status?], :where [[e? :crux.db/id id?] [e? :app/type :app/Translation] [e? :translation/status status?] [e? :jurisdiction/id jid?]], :arg-keys [#{jid?}]}
15:58:00.701 [crux.query.query-pool-thread-12] DEBUG crux.query - :join-order :aev e? status? {:e e?, :a :translation/status, :v status?}
15:58:00.701 [crux.query.query-pool-thread-12] DEBUG crux.query - :join-order :ave jid? e? {:e e?, :a :jurisdiction/id, :v jid?}
15:58:00.701 [crux.query.query-pool-thread-12] DEBUG crux.query - :join-order :ave :app/Translation e? {:e e?, :a :app/type, :v :app/Translation}
15:58:00.701 [crux.query.query-pool-thread-12] DEBUG crux.query - :where [[:triple {:e e?, :a :crux.db/id, :v id?}] [:triple {:e e?, :a :app/type, :v :app/Translation}] [:triple {:e e?, :a :translation/status, :v status?}] [:triple {:e e?, :a :jurisdiction/id, :v jid?}]]
15:58:00.701 [crux.query.query-pool-thread-12] DEBUG crux.query - :vars-in-join-order [:app/Translation jid? e? status? id?]
15:58:00.701 [crux.query.query-pool-thread-12] DEBUG crux.query - :attr-stats {:crux.db/id 113, :translation/status 1, :jurisdiction/id 6}
15:58:00.701 [crux.query.query-pool-thread-12] DEBUG crux.query - :var->bindings {id? #crux.query.VarBinding{:e-var nil, :var id?, :attr nil, :result-index 4, :result-name crux.query.value/id?, :type :pred, :value? true}, jid? #crux.query.VarBinding{:e-var e?, :var jid?, :attr :jurisdiction/id, :result-index 1, :result-name e?, :type :entity, :value? false}, e? #crux.query.VarBinding{:e-var e?, :var e?, :attr :crux.db/id, :result-index 2, :result-name e?, :type :entity, :value? false}, status? #crux.query.VarBinding{:e-var e?, :var status?, :attr :translation/status, :result-index 3, :result-name e?, :type :entity, :value? false}}
15:58:00.702 [crux.query.query-pool-thread-12] DEBUG crux.query - :query-time-ms 2
15:58:00.702 [crux.query.query-pool-thread-12] DEBUG crux.query - :query-result-size 2
PATHOM QUERY by jid {:jurisdiction/id 1, :concept/id 728}
15:58:00.858 [crux.query.query-pool-thread-13] DEBUG crux.memory - :pool-allocation-stats {:allocated 3932160, :deallocated 262144, :in-use 3670016}
15:58:00.859 [crux.query.query-pool-thread-13] DEBUG crux.query - :query {:find [?id], :where [[?e :crux.db/id ?id] [?e :app/type :app/Translation] [?e :jurisdiction/id jurisdictionid] [?e :concept/id conceptid]], :arg-keys [#{conceptid jurisdictionid}]}
15:58:00.859 [crux.query.query-pool-thread-13] DEBUG crux.query - :join-order :ave conceptid ?e {:e ?e, :a :concept/id, :v conceptid}
15:58:00.859 [crux.query.query-pool-thread-13] DEBUG crux.query - :join-order :ave jurisdictionid ?e {:e ?e, :a :jurisdiction/id, :v jurisdictionid}
15:58:00.859 [crux.query.query-pool-thread-13] DEBUG crux.query - :join-order :aev ?e ?id {:e ?e, :a :crux.db/id, :v ?id}
15:58:00.859 [crux.query.query-pool-thread-13] DEBUG crux.query - :join-order :ave :app/Translation ?e {:e ?e, :a :app/type, :v :app/Translation}
15:58:00.859 [crux.query.query-pool-thread-13] DEBUG crux.query - :where [[:triple {:e ?e, :a :crux.db/id, :v ?id}] [:triple {:e ?e, :a :app/type, :v :app/Translation}] [:triple {:e ?e, :a :jurisdiction/id, :v jurisdictionid}] [:triple {:e ?e, :a :concept/id, :v conceptid}]]
15:58:00.860 [crux.query.query-pool-thread-13] DEBUG crux.query - :vars-in-join-order [:app/Translation conceptid jurisdictionid ?e ?id]
15:58:00.860 [crux.query.query-pool-thread-13] DEBUG crux.query - :attr-stats {:crux.db/id 112, :jurisdiction/id 5}
15:58:00.860 [crux.query.query-pool-thread-13] DEBUG crux.query - :var->bindings {conceptid #crux.query.VarBinding{:e-var ?e, :var conceptid, :attr :concept/id, :result-index 1, :result-name ?e, :type :entity, :value? false}, jurisdictionid #crux.query.VarBinding{:e-var ?e, :var jurisdictionid, :attr :jurisdiction/id, :result-index 2, :result-name ?e, :type :entity, :value? false}, ?e #crux.query.VarBinding{:e-var ?e, :var ?e, :attr :crux.db/id, :result-index 3, :result-name ?e, :type :entity, :value? false}, ?id #crux.query.VarBinding{:e-var ?e, :var ?id, :attr :crux.db/id, :result-index 4, :result-name ?e, :type :entity, :value? false}}
15:58:00.861 [crux.query.query-pool-thread-13] DEBUG crux.query - :query-time-ms 3
15:58:00.861 [crux.query.query-pool-thread-13] DEBUG crux.query - :query-result-size 2
java.lang.Long 728 java.lang.Long 1 TRANSLATIONS BY CONCEPT  #{[:translation-fr-728-1-1-published] [:translation-fr-728-1-1-draft]}
LOOKUPVECTOR #{[:translation-fr-728-1-1-published] [:translation-fr-728-1-1-draft]}
evicting data [:translation-fr-728-1-1-draft]
evict entity  :translation-fr-728-1-1-draft
15:58:01.171 [qtp1933800627-24] DEBUG crux.memory - :pool-allocation-stats {:allocated 4063232, :deallocated 262144, :in-use 3801088}
15:58:01.262 [crux-tx-consumer] DEBUG crux.tx - Indexing tx-id: 8 tx-events: 1
15:58:02.465 [crux.query.query-pool-thread-14] DEBUG crux.memory - :pool-allocation-stats {:allocated 4194304, :deallocated 262144, :in-use 3932160}
15:58:02.465 [crux.query.query-pool-thread-14] DEBUG crux.query - :query {:find [id? status?], :where [[e? :crux.db/id id?] [e? :app/type :app/Translation] [e? :translation/status status?] [e? :jurisdiction/id jid?]], :arg-keys [#{jid?}]}
15:58:02.465 [crux.query.query-pool-thread-14] DEBUG crux.query - :join-order :aev e? status? {:e e?, :a :translation/status, :v status?}
15:58:02.465 [crux.query.query-pool-thread-14] DEBUG crux.query - :join-order :ave jid? e? {:e e?, :a :jurisdiction/id, :v jid?}
15:58:02.465 [crux.query.query-pool-thread-14] DEBUG crux.query - :join-order :ave :app/Translation e? {:e e?, :a :app/type, :v :app/Translation}
15:58:02.465 [crux.query.query-pool-thread-14] DEBUG crux.query - :where [[:triple {:e e?, :a :crux.db/id, :v id?}] [:triple {:e e?, :a :app/type, :v :app/Translation}] [:triple {:e e?, :a :translation/status, :v status?}] [:triple {:e e?, :a :jurisdiction/id, :v jid?}]]
15:58:02.465 [crux.query.query-pool-thread-14] DEBUG crux.query - :vars-in-join-order [:app/Translation jid? e? status? id?]
15:58:02.466 [crux.query.query-pool-thread-14] DEBUG crux.query - :attr-stats {:crux.db/id 113, :translation/status 1, :jurisdiction/id 6}
15:58:02.466 [crux.query.query-pool-thread-14] DEBUG crux.query - :var->bindings {id? #crux.query.VarBinding{:e-var nil, :var id?, :attr nil, :result-index 4, :result-name crux.query.value/id?, :type :pred, :value? true}, jid? #crux.query.VarBinding{:e-var e?, :var jid?, :attr :jurisdiction/id, :result-index 1, :result-name e?, :type :entity, :value? false}, e? #crux.query.VarBinding{:e-var e?, :var e?, :attr :crux.db/id, :result-index 2, :result-name e?, :type :entity, :value? false}, status? #crux.query.VarBinding{:e-var e?, :var status?, :attr :translation/status, :result-index 3, :result-name e?, :type :entity, :value? false}}
15:58:02.466 [crux.query.query-pool-thread-14] DEBUG crux.query - :query-time-ms 2
15:58:02.466 [crux.query.query-pool-thread-14] DEBUG crux.query - :query-result-size 0
Here is a more complete log sequence. I have a first query that return correctly 2 results. Then i count by status. Then i evict a record and last the query return 0 results instead of one. Many thanks for taking your time ! I'll continue to search, it is may be a stupid thing ...

ouvasam15:06:45

The starnge part is that this can go good but suddenly it does stop working. Sames queries, same evict but may be a litttle bit faster ?

refset17:06:45

oh, so it's intermittent even if everything stays the same (code, data, crux version)? are you using await-tx between the queries?

refset17:06:23

what's interesting in that log is 1) the join order is the same, which is good, and 2) seeing the attribute-stats changing (which aren't completely consistent in how they get updated, but if you add a 50ms sleep between all ops they should be consistent enough):

:attr-stats {:crux.db/id 113, :translation/status 1, :jurisdiction/id 6}
:attr-stats {:crux.db/id 112, :jurisdiction/id 5}
:attr-stats {:crux.db/id 113, :translation/status 1, :jurisdiction/id 6}

ouvasam08:06:05

Hi Jeremy, i did try all the above, delete, await-tx, ... but at some times, i have the same trouble. I'll redo all the process to catch the problem. Many thanks for your help

refset09:06:21

It's no problem. The offer of pairing for 30m is still open, but it would have to be Monday :)

ouvasam11:06:04

Many thanks for this proposition ! I did restart from scratch and remove unnecessary calls and everything seems to work fine now. I also use delete instead as evict. And put some little delay between calls. Many many thanks for your help and sorry if all my questions were finally not related to crux but more about my code Have a nice day and a nice week-end

refset12:06:31

Wonderful! I'm glad you persevered and fingers crossed that's the end of it!

🎉 3
refset12:06:43

Have a lovely weekend also :)

🙏 3
ouvasam13:06:14

Many thanks for any tip

ouvasam14:06:30

With a query like this one i also get it

(crux/q (crux/db node)
                    {:find '[id? status?]
                     :where '[[e? :crux.db/id id?]
                              [e? :app/type :app/Translation]
                              [e? :abc/def status?]
                              [e? :jurisdiction/id jid?]]
                     :args [{'jid? jid}]})

refset15:06:49

is the :abc/def here correct?

ouvasam16:06:12

Yes I did try to change the name thinking stays was a reserved keyword

ouvasam14:06:13

I also did try to change the name but nothing works I also change the args part with two maps instead of one but no success

ouvasam14:06:39

What is strange is that this happen only after I post a new entity based on the same entity by modifying the status to :published and set a new crux.db/id

dominicm16:06:29

You aren't using jid @ouvasam

dominicm16:06:36

I think there was a bug related to that.

dominicm16:06:53

I think it's fixed in the latest crux, but I'm not certain.

3
refset20:06:02

Yeah both related issues with args got fixed in the last release: https://github.com/juxt/crux/pull/888 https://github.com/juxt/crux/pull/885