Fork me on GitHub
#datomic
<
2017-07-13
>
souenzzo14:07:03

Every question about datomic that I google, I arrive in a @val_waeselynck's github repo https://github.com/vvvvalvalval/datalog-rules

hmaurer15:07:45

Sounds like a new law. Similar to how you eventually end up on Wikipedia’s “Philosophy” page if you keep following the first link of every Wikipedia article

val_waeselynck17:07:47

@U2J4FRT2T and do you find the answer there? :)

souenzzo17:07:29

Almost always parrot

matan18:07:46

Is this an okay place for newb questions?

matan19:07:26

thanks 🙂

matan19:07:15

I probably do not understand in what way is datomic consistent, as I find the description at http://docs.datomic.com/acid.html#sec-2 well, cryptic. Is it simple enough to explain the consistency model of datomic in few lines of plain English? or would you recommend some other resource for it?

matan19:07:20

How is a peer's time basis determined by datomic?

hmaurer19:07:38

@matan which parts of the explanation given on that page do you not understand?

hmaurer19:07:47

Happy to try to clarify (but I’m a newb too :p)

matan19:07:03

section 2, where the above link points to

matan19:07:30

I think the key to my understanding would be answering ― > How is a peer's time basis managed by datomic?

matan19:07:22

Conceptually, if all peers need to have the same consistent view of the database, then either all peers have to synchronize with some network element before arriving at that consistent view, or something out of the box governs the peer nodes seeing the same consistent view of the data (?!)

matan19:07:31

I would like to learn what kind of "consistency" does datomic guarantee, and also, at a high level how is it internally accomplished

matan19:07:53

:thinking_face:

val_waeselynck19:07:13

@matan For writes, Datomic is serializable. For reads, the system that constitutes a set of peers (viewed as a database server) can have various degrees of consistency and/or availability based on your own decisions

val_waeselynck19:07:21

For instance, if you use datomic.api/sync, you can always read your writes

val_waeselynck19:07:35

if not, you may have stale reads

val_waeselynck19:07:55

(speaking under control of the cognitect guys of course)

matan19:07:52

I'm not sure I see how this translates to being consistent. It's easy to see that writes can be consistent, if at all a sentence like this isn't by definition void. I'm still stumped by the notion of consistency there.

val_waeselynck19:07:41

@matan well in the sense of the CAP theorem, consistent means linearizable, and a set of peers + a transactor behind a load balancer is typically not linearizable when implemented in the most naive way, since they allow for stale reads (updates are pushed asynchronously to peers, and peers remain available in case of a network partition which separates them from the transactor)

val_waeselynck19:07:38

Now, interestingly, you can return the new t to the client after each write and read, and call d/sync for each read, which I believe makes the system closer to CP

val_waeselynck19:07:48

so the client is kind of in control of consistency here

val_waeselynck19:07:41

Again, not an expert at all, so take what I say with a grain of salt 🙂

mss20:07:17

apologies for the newbie question, still wrapping my head around datomic: if you have an attribute that’s a ref to multiple entities, is there a way to enforce order? if not, how do people usually get around that? as a practical example, let’s say I’m making a recipe app. I have a recipe entity which has a ref with cardinality/many to possibly multiple recipe-stepentities, each of which may be edited/updated at any time would I want to put a recipe-step/step-number attribute on that entity and sort that way? any other idiomatic ideas?

hmaurer21:07:16

@mss no way to enforce order (there is no order) afaik

hmaurer21:07:47

You can add an “index” attribute to your entities, or store your data as a linked-list

hmaurer21:07:17

so yes, something like a step-number would be necessary I think

mss21:07:33

interesting. any intuition on if there’s a way to ease the pain of updating each affected step-number attribute as steps are inserted or removed?

mss21:07:26

obv if I have a list of 1-10 and step 2 gets removed, I can just update 3-10 to have a different value for that step-number attribute. just wondering if there’s a more idiomatic/convenient way

mss22:07:47

that example is pretty simple, but doing that on a collection of 10k elements seems painful

favila22:07:05

@mss If you are deleting an item, you do not need to renumber

favila22:07:31

only if you are inserting an item between two others do you need to renumber

mss22:07:33

yep, you’re right. let’s say inserting, then

favila22:07:13

that's exactly what you would do. For small lists this is the simplest thing

favila22:07:36

use :db.fn/cas on the sequence items you update to ensure there is no trouble

favila22:07:13

if it's important for you to renumber as few as possible, you can renumber from the insertion point to the top of the list (decrementing as you go)

favila22:07:31

i.e. with list [0 a 1 c 2 d], inserting b between a and c, it touches less to do [-1 a 0 b 1 c 2 d]

mss22:07:24

makes sense, really appreciate the help

beders22:07:53

you could use fractions (double/floats) as step numbers. For a reasonable amount of inserts, the order would stay the same if you use (atIndex*2 + 1) / 2 for the new step number

oli14:07:26

i was going to reply with choosing a suitably large integer step between each item.

oli14:07:42

10 PRINT "HELLO WORLD"

oli14:07:52

20 GOTO 10

oli14:07:02

for the old school

beders22:07:16

you'll renumber when showing it to the end-user on the fly

hmaurer22:07:47

@favila do you think representing a linked list in Datomic makes sense? It seems neat conceptually, but I’m not sure how it would play with querying etc