datahike

timo 2024-02-14T07:03:04.978679Z

Thanks to @brunodonascimentomaci for fixing our build 🎉

👍 1
Bruno do Nascimento Maciel 2024-02-14T09:29:52.338219Z

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 Maciel 2024-02-14T09:34:39.560789Z

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.

timo 2024-02-14T10:22:16.536609Z

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 Maciel 2024-02-14T10:47:58.313379Z

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 Maciel 2024-02-14T10:49:04.286369Z

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

timo 2024-02-14T10:49:10.832229Z

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

Bruno do Nascimento Maciel 2024-02-14T10:53:16.293109Z

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

timo 2024-02-14T10:53:36.587379Z

ok, cool. never used that one.

Bruno do Nascimento Maciel 2024-02-14T10:55:04.227749Z

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

timo 2024-02-14T10:55:40.803919Z

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.

timo 2024-02-14T10:59:10.208899Z

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

timo 2024-02-14T11:00:25.560699Z

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

Bruno do Nascimento Maciel 2024-02-14T11:06:47.792439Z

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?

timo 2024-02-14T11:07:05.174959Z

sure

timo 2024-02-14T11:07:29.105839Z

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

timo 2024-02-14T11:07:40.680849Z

sequential is the right word

timo 2024-02-14T11:08:13.178289Z

https://jepsen.io/consistency

Bruno do Nascimento Maciel 2024-02-14T11:27:01.083359Z

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?

timo 2024-02-14T11:28:36.031149Z

ok, probably @whilo can help here

whilo 2024-02-14T18:21:40.059389Z

@brunodonascimentomaci 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.

whilo 2024-02-14T18:22:13.197209Z

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.

whilo 2024-02-14T18:24:00.063489Z

We definitely also need to document this.

Bruno do Nascimento Maciel 2024-02-14T18:29:17.025999Z

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?

whilo 2024-02-14T18:45:31.441019Z

Just fork the repo and add namespaces.