Fork me on GitHub
#datahike
<
2024-02-14
>
Bruno do Nascimento Maciel09:02:52

Hey folks! Its me again 🙂 It is possible to call transaction functions with in datahike.http.server? like we have in https://docs.datomic.com/pro/transactions/transaction-functions.html#writing

Bruno do Nascimento Maciel09:02:39

I know that we can do it when executing Datahike locally (https://github.com/macielti/carimbo/blob/71a3d75974437fff054a02c383908567b65dc8ba/src/carimbo/db/datahike/transaction.clj#L26-L52). But I need this transaction function to be executed on the Datahike server in order to guarantee consistency.

timo10:02:16

datahike server acts like a datomic transactor afaik. the level of consistency guarantee should be roughly the same as with datomic. I am not into the details though. https://github.com/replikativ/datahike/blob/main/http-server/datahike/http/server.clj#L164

Bruno do Nascimento Maciel10:02:58

I have the scenario where I have two API instances writing to the same Database. The flow consists in doing some validations on top of the data present on the database, so I have to apply the validation on top of an query result. After the validation result I persist the changes on the database.

Bruno do Nascimento Maciel10:02:04

The problem is that between the query and the persistence transactions, other instance can change the data.

timo10:02:10

ok, datomic has these kind of transactions in the sense of multiple operation consistency?

Bruno do Nascimento Maciel10:02:16

With Datahike I know that we can use :db.fn/call to have a transaction function being executed with in a single transaction context.

timo10:02:36

ok, cool. never used that one.

Bruno do Nascimento Maciel10:02:04

But I can make it work only with the "local transactor" without using a remote peer

timo10:02:40

I think the consistency guarantee is more like this:

Every peer sees completed transactions as of a particular point in time, called a time basis. The time basis of transactions is a global ordering of transactions for a particular system. Peers always see all transactions up to their time basis, in order, with no gaps.

timo10:02:10

datahike (and datomic afaik as well) only can guarantee sequential or linearizable consistency

timo11:02:25

snapshot isolation is not achievable with this kind of distributed setup with a central transactor.

Bruno do Nascimento Maciel11:02:47

While using datahike.http.server in order to establish one single writer, all transactions that arrive on Datahike Server should be executed in a serialized way, that is correct?

timo11:02:29

wait... not in the sense of serializable consistency in the model above

timo11:02:40

sequential is the right word

Bruno do Nascimento Maciel11:02:01

I found that Issue that is more related with what I am trying to achieve https://github.com/replikativ/datahike/issues/389 It is already possible to install a function on the Database in the context of an distributed setting with Datahike?

timo11:02:36

ok, probably @U1C36HC6N can help here

whilo18:02:40

@U0686RN9X0W For now the best thing to do is to add the functions you need to the server jar. I know this is a bit inconvenient, but we haven't got to the point of supporting transacting functions like Datomic yet.

whilo18:02:13

I am also not sure what the most convenient way for this is. In a sense having open source access to the server and just loading it in the jar gives you a lot more freedom.

whilo18:02:00

We definitely also need to document this.

Bruno do Nascimento Maciel18:02:17

I agree with you. I am going to try to make a PoC about adding the function directly on the server. Do you have some example?

whilo18:02:31

Just fork the repo and add namespaces.