mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-03 09:19:10 +01:00
kvdb/postgres: use readonly db transaction if possible
This commit is contained in:
parent
ed511bb37f
commit
99566b768e
1 changed files with 11 additions and 1 deletions
|
@ -4,6 +4,7 @@
|
|||
package postgres
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"sync"
|
||||
|
||||
|
@ -39,7 +40,16 @@ func newReadWriteTx(db *db, readOnly bool) (*readWriteTx, error) {
|
|||
}
|
||||
locker.Lock()
|
||||
|
||||
tx, err := db.db.Begin()
|
||||
// Start the transaction. Don't use the timeout context because it would
|
||||
// be applied to the transaction as a whole. If possible, mark the
|
||||
// transaction as read-only to make sure that potential programming
|
||||
// errors cannot cause changes to the database.
|
||||
tx, err := db.db.BeginTx(
|
||||
context.Background(),
|
||||
&sql.TxOptions{
|
||||
ReadOnly: readOnly,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
locker.Unlock()
|
||||
return nil, err
|
||||
|
|
Loading…
Add table
Reference in a new issue