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?
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.
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?