Fork me on GitHub
#datomic
<
2017-09-29
>
favila05:09:07

Is there any way to make datomic with sql storage use a different table name than datomic_kvs?

stuarthalloway13:09:16

@favila not at present. The last time somebody hit this I think they found they could do a level of indirection on the SQL side.

cch114:09:43

In a transaction, I’m stuck trying to retrieve the (temp) entity id or the (temp) transaction id and using it as a value for unique attribute. Use case: I want to create a low-cost, shortish unique id for an entity that will survive backup/restore and other cross-database operations. db:/id seems like the obvious choice, but I am slightly worried about their stability across backup/restore.

cch114:09:04

Is there any way to have the tempid usable as the value for a custom attribute? What would be the db.valueType of such an attribute?

cch114:09:06

Squuids are unsavory due to length.

cch114:09:51

I’ve considered an alias to :db/id, but I think that would suffer from the same stability issues across backup/restore.

cch114:09:41

Alternatively, can anybody confirm that :db/id is intended to be stable across backup/restore?

ovan15:09:49

We think we've discovered a bug in Datomic related to string tempids being resolved incorrectly (two entities get mixed up in single transaction under certain conditions). Does anyone know what's the proper channel to report it to the Datomic team?

favila15:09:41

@cch1 Cognitect has warned that :db/ids are not guaranteed to survive backups/restores and should not be used as stable identifiers. (but they have been stable so far). I don't get how a tempid would help you though!

favila15:09:21

What do you mean specifically by "retrieve the (temp) entity id"?

cch115:09:12

By “retrieve the (temp) entity id” I mean “reference the (temp) entity id so that I can assign it as a value to my attribute”.

cch115:09:40

Thanks for confirming my concern about the stability of :db/id across backup/restore.

favila15:09:49

I'm still not sure what you mean. Can you show me a transaction?

cch115:09:02

{:db/id "user"
 :my/identifier "user"}

favila15:09:45

the tempid there is literally "user"

favila15:09:58

there's nothing else to retrieve?

cch115:09:44

That’s enough to illustrate my example. In that case, :db/id is assigned a value (reported in the tempid resolution key of the transaction) and my custom identifier uses the same value. Significantly, my attribute does survive backup/restore because it is stored independently of the :db/id.

cch115:09:50

Does that make sense?

favila15:09:32

You mean you want the entity id which finally replaces the tempid?

cch115:09:08

yes. I want it to be a value of my custom attribute.

favila15:09:27

so, if :my/identifier is a ref type, this is done automatically

favila15:09:57

if :my/identifier is not a ref type, there is no replacement done, what gets written in is literally whatever you put

cch115:09:05

So can I create an explicit self-reference? Or a ref to the transaction itself?

cch115:09:18

That’s an interesting idea.

favila15:09:19

tempids are placeholders for real entity ids

cch115:09:33

Right. So a reference to myself would work.

favila15:09:35

the final step of tx expansion is to replace all tempids with ids

favila15:09:53

yes, it would work, but also be pointless for what you seem to want, which is a short stable identifier

cch115:09:03

I see. It would not be stable.

favila15:09:10

also, just use the db id

favila15:09:22

the db id is already there, why add another attr that just asserts itself?

favila15:09:29

it's pointless

cch115:09:51

IFF it were stored separately, it would be stable across backup/restore. But as a reference, that would probably not work.

cch115:09:13

What I really need is access to the tempid creation mechanism as a value, not a reference/entity-id

favila15:09:26

Again, I still don't see what that would accomplish

favila15:09:35

tempids are syntax

cch115:09:48

Unique identifier, stable across backup/restore, short-ish, cheap.

favila15:09:55

tempids are none of those things

cch115:09:59

squuid works, but too long

cch115:09:22

No, but the resolved value is all of those things except stable across backup/restore.

cch115:09:30

My hope was to store it as a value.

favila15:09:34

but the resolved value is the db id itself

cch115:09:35

Maybe not possible.

cch115:09:40

That’s OK.

cch115:09:22

The resolved value is unique, short-ish and very cheap (already computed in fact). I just need to get it assigned as a value during the transaction. But maybe that is not possible.

favila15:09:44

why does it need to be in the value slot of a datom? that I don't understand

cch115:09:14

Because otherwise I suspect it is not guaranteed to survive the backup/restore process.

cch115:09:34

As an entity id, it could be regenerated as long as the references were presevered.

cch115:09:44

As a value, it should be stable.

favila15:09:06

yes, but suppose datomic renumbers db/ids at some point. your "unique id" mechanism is now broken, because newly-issued ids may collide

favila15:09:13

you need to control the issuance mechanism too

cch115:09:30

That is a very good point.

cch115:09:48

Sigh. Maybe use squuids-as-a-long then.

favila15:09:10

so, we have created autoincrement counters in datomic for this purpose

cch115:09:26

Using a db fn?

favila15:09:33

external systems couldn't tolerate uuids because they were too long, and we couldn't find an encoding method that could compress them enough

favila15:09:41

yes, with db.fn

cch115:09:54

OK. Point to example? You have been very helpful.

favila15:09:18

it has the limitation that you can only increment one counter once per TX

cch115:09:39

Your scenario sounds exactly like mine. I was hoping for a solution that leveraged the internal uniqueness of tempids, but your point about clashes post-restore is the kiss-of-death for that.

cch115:09:51

That limitation might be OK…

favila15:09:36

I also vaguely heard that there are counter services (which just issue guaranteed-monotonically-increasing counters), or you could build something with zookeeper; and call these from within a tx fn

favila15:09:51

(you have to tolerate gaps in ids from failed txs)

favila15:09:03

anyway, let me dig up our solution

cch115:09:06

gaps are ok too.

cch115:09:25

Your solution will be appreciated. ZK might work too since we are already using it.

cch115:09:30

Gotta run, work emergency

favila15:09:50

our solution doesn't have gaps and doesn't require coordination with other services, but has the one-increment-per-tx limitation

cch116:09:11

Thanks for your help, @favila