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
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.
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
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.
The problem is that between the query and the persistence transactions, other instance can change the data.
ok, datomic has these kind of transactions in the sense of multiple operation consistency?
With Datahike I know that we can use :db.fn/call to have a transaction function being executed with in a single transaction context.
ok, cool. never used that one.
Here is an example https://github.com/macielti/carimbo/blob/71a3d75974437fff054a02c383908567b65dc8ba/src/carimbo/db/datahike/transaction.clj#L45
But I can make it work only with the "local transactor" without using a remote peer
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.datahike (and datomic afaik as well) only can guarantee sequential or linearizable consistency
snapshot isolation is not achievable with this kind of distributed setup with a central transactor.
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?
sure
wait... not in the sense of serializable consistency in the model above
sequential is the right word
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?
ok, probably @whilo can help here
@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.
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.
We definitely also need to document this.
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?
Just fork the repo and add namespaces.