Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Commit

Permalink
update comment
Browse files Browse the repository at this point in the history
  • Loading branch information
camdencheek committed Jun 14, 2022
1 parent d63d365 commit 3eb6b8b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions internal/database/basestore/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,21 +156,21 @@ func makeSavepointID() (string, error) {
return fmt.Sprintf("sp_%s", strings.ReplaceAll(id.String(), "-", "_")), nil
}

var ErrConcurrentTransactions = errors.New("transaction used concurrently")
var ErrConcurrentTransactionAccess = errors.New("transaction used concurrently")

// lockingTx wraps a *sql.Tx with a mutex, and reports when a caller tries
// to use the transaction concurrently. Since using a transaction concurrently
// is unsafe, we want to catch these issues. Currently, lockingTx will just
// log an error and serialize accesses to the wrapped *sql.Tx, but in the future
// concurrent calls may be upgraded to an error.
// lockingTx wraps a *sql.Tx with a mutex, and reports when a caller tries to
// use the transaction concurrently. Since using a transaction concurrently is
// unsafe, we want to catch these issues. If lockingTx detects that a
// transaction is being used concurrently, it will return
// ErrConcurrentTransactionAccess and log an error.
type lockingTx struct {
tx *sql.Tx
mu sync.Mutex
}

func (t *lockingTx) lock() error {
if !t.mu.TryLock() {
err := errors.WithStack(ErrConcurrentTransactions)
err := errors.WithStack(ErrConcurrentTransactionAccess)
log.Scoped("internal", "database").Error("transaction used concurrently", log.Error(err))
return err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/database/basestore/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func TestConcurrentTransactions(t *testing.T) {
})
}
err = g.Wait()
require.ErrorIs(t, err, ErrConcurrentTransactions)
require.ErrorIs(t, err, ErrConcurrentTransactionAccess)
})

t.Run("parallel insertions on a single transaction fails", func(t *testing.T) {
Expand All @@ -123,7 +123,7 @@ func TestConcurrentTransactions(t *testing.T) {
})
}
err = g.Wait()
require.ErrorIs(t, err, ErrConcurrentTransactions)
require.ErrorIs(t, err, ErrConcurrentTransactionAccess)
})
}

Expand Down

0 comments on commit 3eb6b8b

Please sign in to comment.