diff options
author | Sami Hiltunen <shiltunen@gitlab.com> | 2023-09-27 13:13:49 +0300 |
---|---|---|
committer | Sami Hiltunen <shiltunen@gitlab.com> | 2023-09-29 14:10:12 +0300 |
commit | ff27b2f4bf89a226d18b694d8c5f1eafd45a4c68 (patch) | |
tree | 5039119375b6242a79e14fc88f08ca2324a4810d | |
parent | 1f966f092d836881be57cd9d6983763780f92e86 (diff) |
Change admission to a boolean
Transaction's admission field tracks whether it has been dequeued by
the TransactionManager for processing. If so, the TransactionManager
is now responsible for the clean up of the transaction. This was a
channel as we previously had to wait for a transaction to be dequeued
in tests to ensure a repository deletion has been processed where we
expect it to. As deletions are no longer done async in tests, change
the admission field back to a simple boolean.
-rw-r--r-- | internal/gitaly/storage/storagemgr/transaction_manager.go | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/internal/gitaly/storage/storagemgr/transaction_manager.go b/internal/gitaly/storage/storagemgr/transaction_manager.go index f06b75d2b..0fe5427ba 100644 --- a/internal/gitaly/storage/storagemgr/transaction_manager.go +++ b/internal/gitaly/storage/storagemgr/transaction_manager.go @@ -148,12 +148,12 @@ type Transaction struct { // result is where the outcome of the transaction is sent ot by TransactionManager once it // has been determined. result chan error - // admitted is closed when the transaction was admitted for processing in the TransactionManager. + // admitted is set when the transaction was admitted for processing in the TransactionManager. // Transaction queues in admissionQueue to be committed, and is considered admitted once it has // been dequeued by TransactionManager.Run(). Once the transaction is admitted, its ownership moves // from the client goroutine to the TransactionManager.Run() goroutine, and the client goroutine must // not do any modifications to the state of the transcation anymore to avoid races. - admitted chan struct{} + admitted bool // finish cleans up the transaction releasing the resources associated with it. It must be called // once the transaction is done with. finish func() error @@ -223,7 +223,6 @@ func (mgr *TransactionManager) Begin(ctx context.Context, opts TransactionOption CustomHookIndex: mgr.customHookIndex, CustomHookPath: customHookPathForLogIndex(mgr.repositoryPath, mgr.customHookIndex), }, - admitted: make(chan struct{}), finished: make(chan struct{}), } @@ -465,12 +464,11 @@ func (txn *Transaction) Rollback() error { // the Transaction is being processed by TransactionManager. The clean up responsibility moves there as well // to avoid races. func (txn *Transaction) finishUnadmitted() error { - select { - case <-txn.admitted: + if txn.admitted { return nil - default: - return txn.finish() } + + return txn.finish() } // Snapshot returns the details of the Transaction's read snapshot. @@ -772,7 +770,7 @@ func (mgr *TransactionManager) commit(ctx context.Context, transaction *Transact select { case mgr.admissionQueue <- transaction: - close(transaction.admitted) + transaction.admitted = true select { case err := <-transaction.result: |