I have a problem finding a detailed explanation of datastore behaviour in the following scenario.
- A transaction is started
- Some changes are made
- Another, independent, transaction is started using ndb.TransactionOptions.INDEPENDENT propagation level. It’s purpose is to increment a sharded counter. I need it as a nested transaction, because I’ll have many counters and it’s only possible to use 5 entity groups in one transaction
- Nested transaction is committing successfully
- Main transaction is trying to commit, but fails
- Main transaction is committing after some retries
I suppose that nested transaction is run only once, but I cannot verify this assumption.
Does anybody know how it works?
Put some logging statements in to see the behavior. If steps 3-4 are initiated by the code of the main transaction, the independent transaction will be started each time the main transaction is retried. That’s why it’s called INDEPENDENT, not NESTED.