symfonic.memory.backends.pool_transaction¶
pool_transaction ¶
Making several backends commit together without telling any of them.
A consolidation cycle applies its whole batch of graph mutations at once, and has to verify it still holds the scope's lease in the same transaction -- otherwise the check and the write are two moments with a gap between them, and the gap is exactly where another worker takes over.
The obvious way to do that is to pass a connection down: add_node(scope,
node, connection=conn). It is also the wrong way. GraphBackend is a
protocol with a dozen implementations and none of them should carry a
transport detail in its signature to serve one caller; the lease port is a
separate protocol that would need the same parameter; and every future backend
author would have to thread it through or silently fall out of the
transaction.
So the connection is ambient instead. A block opens a transaction, binds its
connection here, and every acquire() on that same pool hands the connection
back rather than taking a new one. Backends are unchanged and unaware. The
binding is task-local, so an ordinary turn running beside the block keeps its
own connections; and it is keyed by pool identity, so a deployment with two
pools does not accidentally splice them into one transaction.
bound_connection ¶
pool's transaction connection on this task, or None.
is_bound ¶
Whether conn belongs to a transaction and must not be released.
run_in_transaction
async
¶
Run a block so every operation on pool commits or rolls back together.
Nested use joins the outer transaction rather than opening a savepoint: the callers here want "all of this together", and a nested block that could commit on its own would be a quieter way of not having a transaction.