Nested Transactions


Can we use the example @transactional decorator in the documentation to “nest” transactions? (i.e., call a decorated method from within another decorated method?) Does the layer keep track of the nesting or do we need to somehow keep track of the transaction stack to ensure we can only call “beginTransaction” and “commitTransaction” once?

(Bhaskar Muppana) #2

Transactions are coupled with the connection. At any point of time, there can be only one outstanding transaction per connection. In the future, we are planning on making transactions depend on sessions. That will allow us to have multiple transactions per connection. Even then, we wouldn’t have nested transactions. FoundationDB itself doesn’t support any nested transactions.


After looking into the fdb.transactional decorator a bit more closely, (which allows for decorated methods to call each other, unlike the example decorator for the document layer by checking to see whether you are already in a transaction…this is what I meant by “nested transactions”, not true nested transactions on the server), I was able to come up a with a simple solution that keeps track of whether there is an exiting outstanding transaction for the database being used.

On a somewhat related note would it be possible in the future to have some sort of FDB pass-through in the document layer service so that we could do raw FDB operations (in some other keyspace that is implementing some other sort of data model) as part of a transaction?