Skip to content

Wrap transactions to run finalization logic

Sami Hiltunen requested to merge smh-no-ptn-logic-in-txn into master

The PartitionManager needs to track the number of in-flight transactions for each partition. Partitions without any in-flight transactions are stopped as idle.

The tracking is currently done by injecting a factory method into TransactionManager, which is used to associate a finalizer with each Transaction. While this is now done in TransactionManager, this is not really its responsibility as it doesn't need this information at all. This makes TransactionManager more complex as it has to keep calling the finalizer in the right location and has to care about details it doesn't need. The finalizer should always be run after the transaction's Commit or Rollback call has finished.

This commit improves the situation by instead wrapping the Transaction returned from TransactionManager and running the finalizer logic once Commit or Rollback is called on the wrapper. This makes the call flow clearer as it doesn't go back and forth between types. It also keeps unneeded details out from the TransactionManager which is already complex enough on its own.

The wrapper type finalizableTransaction is private as it won't be used directly in other packages. This is different from the other types as the Transaction itself is public. We'll fix this later by making it and other types private which are now unnecessarily public. The storagemgr package will handle the lifecycle of the transactions as well when we eventually integrate it in Gitaly. We'll only expose a minimal interface publicly.

Merge request reports