I was wondering if there is CAS operation available in Dgraph. Here is one use case for CAS -
Let’s say I look up the UID for a certain node in the database
After lookup I use the UID to update/delete edges or literal values of the node
I want to be able to do this operation using multiple threads to achieve higher throughput. Now, while I am performing the second step, the UID may get deleted or values may be updated. Is there way to abort the transaction if for example, the version of the node is updated?
Let’s say I am trying to keep highest timestamp value. I have to read the value first, compute the higher value and then write it. Can I do it in single transaction? What about the case when my logic is more complex than just computing higher value?
Yes, you can do that in a single transaction. Transactions can contain any number of queries/mutations. That’s the purpose of ACID transactions. See this Wikipedia page for more info: ACID - Wikipedia
Increment transaction example
You can see transactions at work in our increment example that increments a counter stored in Dgraph. If multiple clients are trying to increment the counter value concurrently, they will not be able to successfully increment to the same value. Because transactions are ACID, the counter always increases.
This example explains the solution. Thank you so much.
One more question, are there way to reduce transaction aborts? When I was running the live loader, I observed decent number of transaction aborts. It directly takes away the throughput while still consuming resources.
For live loader specifically, you can decrease the number of concurrent requests with -c. By default the live loader does 100 concurrent requests. You can set it to around 10 or so to reduce the number of aborts.