Multiple dgraph4j clients read the same transaction

Hi all,

writing a Spark Dgraph connector, I have a very particular requirement. I need to run dgraph4j Java clients in multiple JVMs all querying the cluster in the same read-only transaction. All clients need to see the exact same data though running on different nodes and at different times.

From what I have seen in the code of the client those transactions are created on each client node and there is no way to provide the client an open read-only transaction to use.

I think the query @transaction(txnContext: $txnContext) proposed here is exactly what I need. Is this or something similar already available?

Thanks for any pointers and suggestions,
Enrico

You can customize the client and make them communicate with each other to share the transaction context. They way transaction works in Dgraph is that when you start a transaction the response has TxnContext which contains 3 important fields: StartTs, Keys, and Preds. These are used for transaction conflict detection.

So, you need to keep merging the TxnContext and when you are done you can call commit.

In your case, since you have multiple clients you need to share the transaction context among them.

Thanks for the pointers @arijit .

Since I am only querying (read-only), I do not need to merge any contexts, right? Or better phrased, merging contexts will not modify them.

I have extended the dgraph4j client to allow for creating Transactions from TxnContexts. Given the TxnContext from a response, I can create Transactions in multiple JVMs that all (read-only) query at the corresponding startTs. Since those Transactions are not used for mutation, merging within the JVMs will not make the TxnContexts diverge, right?

Do you see any problems with that approach?

Hi @EnricoMi,

As I mentioned in the dgraph4j PR, I will take a look at it by the end of this week.

Thanks