diff options
author | Sami Hiltunen <shiltunen@gitlab.com> | 2023-05-31 18:58:25 +0300 |
---|---|---|
committer | Sami Hiltunen <shiltunen@gitlab.com> | 2023-05-31 18:58:25 +0300 |
commit | 9749fd48f67d093ce8e135fcd2a0b68295537a99 (patch) | |
tree | 3bb8d4d5e38f0cef64706983e4dd98ac2d5dc603 /internal/gitaly/transaction_manager.go | |
parent | c3794da5ff0fe85a5055f41e63de6fa82da233b4 (diff) | |
parent | 300bb4f35cd8e28db08cc646079e013192200759 (diff) |
Merge branch 'pks-go-v1.20' into 'master'
go: Use Go 1.19 as minimum required version
Closes #5324
See merge request https://gitlab.com/gitlab-org/gitaly/-/merge_requests/5831
Merged-by: Sami Hiltunen <shiltunen@gitlab.com>
Approved-by: Quang-Minh Nguyen <qmnguyen@gitlab.com>
Reviewed-by: Patrick Steinhardt <psteinhardt@gitlab.com>
Reviewed-by: Quang-Minh Nguyen <qmnguyen@gitlab.com>
Co-authored-by: Patrick Steinhardt <psteinhardt@gitlab.com>
Diffstat (limited to 'internal/gitaly/transaction_manager.go')
-rw-r--r-- | internal/gitaly/transaction_manager.go | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/internal/gitaly/transaction_manager.go b/internal/gitaly/transaction_manager.go index fd1b71284..ab493dd34 100644 --- a/internal/gitaly/transaction_manager.go +++ b/internal/gitaly/transaction_manager.go @@ -131,12 +131,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 denotes whether the transaction was admitted for processing in the TransactionManager. + // admitted is closed 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 bool + admitted chan struct{} // finish cleans up the transaction releasing the resources associated with it. It must be called // once the transaction is done with. finish func() error @@ -197,6 +197,7 @@ func (mgr *TransactionManager) Begin(ctx context.Context) (_ *Transaction, retur CustomHookIndex: mgr.customHookIndex, CustomHookPath: customHookPathForLogIndex(mgr.repositoryPath, mgr.customHookIndex), }, + admitted: make(chan struct{}), finished: make(chan struct{}), } @@ -290,11 +291,12 @@ 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 { - if txn.admitted { + select { + case <-txn.admitted: return nil + default: + return txn.finish() } - - return txn.finish() } // Snapshot returns the details of the Transaction's read snapshot. @@ -524,7 +526,7 @@ func (mgr *TransactionManager) commit(ctx context.Context, transaction *Transact select { case mgr.admissionQueue <- transaction: - transaction.admitted = true + close(transaction.admitted) select { case err := <-transaction.result: |