@@ -5,7 +5,6 @@ package sqlbase
55import (
66 "context"
77 "database/sql"
8- "sync"
98
109 "github.com/btcsuite/btcwallet/walletdb"
1110)
@@ -20,28 +19,11 @@ type readWriteTx struct {
2019
2120 // active is true if the transaction hasn't been committed yet.
2221 active bool
23-
24- // locker is a pointer to the global db lock.
25- locker sync.Locker
2622}
2723
2824// newReadWriteTx creates an rw transaction using a connection from the
2925// specified pool.
3026func newReadWriteTx (db * db , readOnly bool ) (* readWriteTx , error ) {
31- locker := newNoopLocker ()
32- if db .cfg .WithTxLevelLock {
33- // Obtain the global lock instance. An alternative here is to
34- // obtain a database lock from Postgres. Unfortunately there is
35- // no database-level lock in Postgres, meaning that each table
36- // would need to be locked individually. Perhaps an advisory
37- // lock could perform this function too.
38- locker = & db .lock
39- if readOnly {
40- locker = db .lock .RLocker ()
41- }
42- }
43- locker .Lock ()
44-
4527 // Start the transaction. Don't use the timeout context because it would
4628 // be applied to the transaction as a whole. If possible, mark the
4729 // transaction as read-only to make sure that potential programming
@@ -54,15 +36,13 @@ func newReadWriteTx(db *db, readOnly bool) (*readWriteTx, error) {
5436 },
5537 )
5638 if err != nil {
57- locker .Unlock ()
5839 return nil , err
5940 }
6041
6142 return & readWriteTx {
6243 db : db ,
6344 tx : tx ,
6445 active : true ,
65- locker : locker ,
6646 }, nil
6747}
6848
@@ -94,7 +74,6 @@ func (tx *readWriteTx) Rollback() error {
9474
9575 // Unlock the transaction regardless of the error result.
9676 tx .active = false
97- tx .locker .Unlock ()
9877 return err
9978}
10079
@@ -162,7 +141,6 @@ func (tx *readWriteTx) Commit() error {
162141
163142 // Unlock the transaction regardless of the error result.
164143 tx .active = false
165- tx .locker .Unlock ()
166144
167145 return err
168146}
@@ -204,25 +182,3 @@ func (tx *readWriteTx) Exec(query string, args ...interface{}) (sql.Result,
204182
205183 return tx .tx .ExecContext (ctx , query , args ... )
206184}
207-
208- // noopLocker is an implementation of a no-op sync.Locker.
209- type noopLocker struct {}
210-
211- // newNoopLocker creates a new noopLocker.
212- func newNoopLocker () sync.Locker {
213- return & noopLocker {}
214- }
215-
216- // Lock is a noop.
217- //
218- // NOTE: this is part of the sync.Locker interface.
219- func (n * noopLocker ) Lock () {
220- }
221-
222- // Unlock is a noop.
223- //
224- // NOTE: this is part of the sync.Locker interface.
225- func (n * noopLocker ) Unlock () {
226- }
227-
228- var _ sync.Locker = (* noopLocker )(nil )
0 commit comments