Fork me on GitHub
#datomic
<
2020-02-26
>
csm00:02:50

one can (and should) split stacks in a solo cloud install, correct? And recreate the storage stack and solo compute stack?

vemv12:02:25

Hi. I use datomic on-prem (via the Peer API) with a number of Datomic installations (think production, staging etc) In most of them everything is OK, but for one of them, query latency is consistently high; 1500ms, for the simplest, cheapest possible query. Indices are in place. We also tried to rule out basic stuff (configuration/environment differences, etc) What are some possible causes, or things we can do to troubleshoot this?

vemv12:02:27

In case it helps: how come the latency is slow every time? Given the Datomic architecture (AIUI), queries should be in-memory, with updates being pushed over the wire. So after a slow first query, subsequent queries should be fast... but nope.

marshall15:02:20

@vemv what is different about the one that is high latency?

vemv15:02:38

We haven't noticed any significant difference - DB size, indices, infrastructure details

mavbozo03:02:06

@vemv how many peers you have? is it just 1 peer - 1 transactor - 1 storage ?

mavbozo03:02:01

maybe in staging you have only 1 peer but in production you have multiple peers and 1 of the peers has high latency?

vemv07:02:54

We have: 1 Peer Lib per webapp instance 2 transactors 1 postgresql DB

vemv07:02:42

> maybe in staging [...] All our environments are alike in terms of size, topology etc

dvingo16:02:31

I noticed in on-prem there is an optional :db/index attribute (https://docs.datomic.com/on-prem/schema.html#operational-schema-attributes) but I don't see one in the cloud docs. Are all attributes indexed in cloud?

4
dvingo17:02:09

I don't see it exlicitly stated in the docs, just alluded to here: "Datomic datalog queries automatically use multiple indexes to support a variety of access patterns" (https://docs.datomic.com/cloud/whatis/data-model.html) The differences page, doesn't mention it other than the full-text difference: https://docs.datomic.com/on-prem/moving-to-cloud.html#text-search

ghadi17:02:35

all attributes are indexed in cloud

em21:02:28

Are lookup refs not valid values for transactions for ref attributes in cloud? As per https://blog.datomic.com/2014/02/datomic-lookup-refs.html Similarly, they can be used in transactions to build ref relationships. but I get “entity not resolved” with the full tuple as an error in cloud

ghadi21:02:22

what did you try and what did it error?

em22:02:05

@ghadi

(d/with with-db {:tx-data [{:space/uuid #uuid "some-space-uuid"
                                     :space/devices [:device/id "some-device-id"]}]})
:space/devices is cardinality many, type ref. I realized the issue with this version is the cardinality many means that the vector is interpreted as a vector of refs, so i’m actually pointing to the ident :device/id and an unknown tempid. I then tried another version:
(d/with with-db {:tx-data [{:space/uuid #uuid "some-space-uuid"
                                     :space/devices [[:device/id "some-device-id"]]}]})
And this time after querying the database and looking at the committed transactions it seemed like nothing changed. Solved this issue just splitting the reference into temp ids as mentioned (coincidentally) in the latest conversation here, but was just wondering if it’s possible to use lookup refs as the value in ref type attributes.

ghadi22:02:44

what error did you get?

ghadi22:02:35

and what is the schema definition of :space/uuid and :space/devices?

em22:02:43

:space/uuid is identity, type uuid :space/devices is type ref, cardinality many No error on the second one, just nothing updated (looking at the after-db, the intended space->device datom was not found)

em22:02:48

First one errored

tempid 'd5f2962bd37b24c1c7cb076b9053ae77' used only as value in transaction
which made sense per above reasoning, I then added another pair of square brackets to intend it as a lookup ref

em22:02:06

#:db{:ident :space/devices,
      :valueType :db.type/ref,
      :cardinality :db.cardinality/many}
 #:db{:ident :space/uuid,
      :valueType :db.type/uuid,
      :cardinality :db.cardinality/one,
      :unique :db.unique/identity}

ghadi22:02:18

that second try seems like it should have worked....

ghadi22:02:37

hang on to the transact return value if you try it again

em22:02:36

Turns out another false alarm, thanks for your time! Am I correct to assume that datomic will automatically infer the meaning of a vector based on both schema ident cardinality and type? Got a little confused from how overloaded the square brackets were

marshall21:02:55

@eagonmeng what version of cloud?

em22:02:50

@U05120CBV Hmm, was there a rollback for the released version of cloud? I’m on DatomicCFTVersion 616, which I believe was just released recently on 2/21 (https://webcache.googleusercontent.com/search?q=cache:cWl9SuBuZeMJ:https://docs.datomic.com/cloud/releases.html+&amp;cd=1&amp;hl=en&amp;ct=clnk&amp;gl=us) but it’s mysteriously disappeared off the main page (https://docs.datomic.com/cloud/releases.html)

marshall22:02:00

No thats a doc issue. Will fix

marshall21:02:35

note: https://docs.datomic.com/cloud/releases.html#569-8835 • (Fix: resolve tempids for reference attributes inside tuples.)

marshall21:02:21

however, you should move to the latest; it includes a fix for a different regression in that version

hadils22:02:02

I need to write to several different "schemas" in a single Datomic transaction, e.g., phone numbers, emails accounts, person information and address information. All of these write create eids which are then stored in a customer. I need to do this atomically, but I cannot figure out how to recover eids from within a transaction function. Any ideas?

ghadi22:02:59

transaction functions don't resolve tempids

ghadi22:02:36

transaction functions (the ones that run inside datomic) return transaction data, which is later committed

hadils22:02:05

@ghaid @shaun-mahood Understood. How do I create such a transaction atomically?

ghadi22:02:29

if you need to transact something compound in the same Datomic transaction, you just give it to transact: (d/transact conn {:tx-data [thing1 ... thing2.... thing3]})

ghadi22:02:41

the things can be arbitrary

ghadi22:02:43

transaction functions are something different and should be used to achieve specific purposes (they're like macros that run while the tx is being committed)

hadils22:02:40

Thanks @ghadi. I have a one->many relationship between phone numbers and persons. How would I do that in a single transaction?

ghadi22:02:08

I don't mean to brush off the question, but you should really go through the tutorials

ghadi22:02:17

all of this is covered

ghadi22:02:24

and I'll do a bad job explaining 😃

ghadi22:02:18

you're using Cloud?

shaun-mahood22:02:21

I've got an example I can paste in here - will redact it quickly and throw it in a thread (the docs are great, but I sometimes need a few extra examples to figure things out the first time)

shaun-mahood22:02:32

(d/transact conn {:tx-data 
[[:db/add "request" :request/date request-date]
 [:db/add "client" :client/name client-name]
 [:db/add "job" :job/name job-name]
 [:db/add "job" :job/client "client"]
 [:db/add "job" :job/request "request"]]})

hadils22:02:41

Thanks @ghadi. I have gone through all the tutorials and the videos.

hadils22:02:18

if you wish.

ghadi22:02:17

linking tempids together is how you assert relationships between things

hadils22:02:30

@ghadi. The problem is that i need to commit data atomically, not how to retrieve tempids.

ghadi22:02:34

[{:db/id "customer1"
 :customer/name "hadils"}
{:db/id "customer2"
 :customer/name "ghadi"
 :friends/with "customer1"}]

ghadi22:02:05

things sent in the same tx-data are committed together

ghadi22:02:23

in that example, two new entities are created, and the second entity points to the first entity

ghadi22:02:51

two tempids "customer1" "customer2" will be resolved into two entity-ids when committed

ghadi22:02:15

you can send in arbitrary graphs of entities in the same tx

hadils22:02:32

@ghadi. I am with you. So I need to not use tempids then, I need some other reference for a one-many relationship.

ghadi22:02:46

(those are tempids above)

ghadi22:02:31

if you have a unique ID you can send that in instead of the tempid -- but the end result is the same: datomic needs to know what entities you're asserting things about

hadils22:02:40

@ghadi. yes i see that now. is :firends/with a fre value type?

hadils22:02:03

thanks. that answers my question.

steveb8n22:02:05

this got me as well. in cloud, tempids are just strings in the :db/id

ghadi22:02:01

the tx data grammar at the top of that page is useful, along with the examples

shaun-mahood22:02:03

I think my biggest stumbling blocks in learning Datomic have all been related to how simple it is at the core

hadils22:02:39

What about one to many relationships?

ghadi22:02:50

"cardinality many" attributes can be asserted in a similar way

ghadi22:02:05

:friends/with [joe hadils...]

ghadi22:02:16

in the transaction data

hadils22:02:31

Thanks a lot @ghadi !