How to make several operations as one transaction

This thread doesn’t answer your question but gives a bit of context: Rollback mechanism for storage objects and wallet - #2 by sesposito.

We do not expose transactions through the APIs so there is no way to rollback the operations or make them atomical at the DB level through them, but some of the operations are done within transactions internally (some examples are given in the thread).

First of all, you should wrap any sequence of operations that should be grouped together into custom RPCs to ensure these won’t fail midway due to potential network or client issues, making them logical blocks that while do not guarantee atomicity, should be good enough.

What you could do to keep the system in a consistent state in case of an error, is to attempt to delete any previously created entities up to the point of the failure, and just ignore error checking to make them no-ops in case the entity does not exist (although this may be a bit different case-by-case).

Invoking Leaderboard/Tournament create APIs if they already exist are no-ops, so need to check that.

To remove the scores from the leaderboard after LeaveGroup is successful, I’d take the same approach of attempting to delete the records but ignoring any failures due to no records existing.

Hope this helps

1 Like