mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-31 08:02:25 +02:00
kvdb/sqlbase: fix build errors
We copy the `sqldb/sqlerrors.go` into `kvdb/sqlbase` to avoid import cycles.
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"math/rand"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -37,12 +38,6 @@ const (
|
||||
DefaultMaxRetryDelay = time.Second * 5
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrRetriesExceeded is returned when a transaction is retried more
|
||||
// than the max allowed valued without a success.
|
||||
ErrRetriesExceeded = errors.New("db tx retries exceeded")
|
||||
)
|
||||
|
||||
// Config holds a set of configuration options of a sql database connection.
|
||||
type Config struct {
|
||||
// DriverName is the string that defines the registered sql driver that
|
||||
@@ -238,7 +233,7 @@ func randRetryDelay(initialRetryDelay, maxRetryDelay time.Duration,
|
||||
attempt int) time.Duration {
|
||||
|
||||
halfDelay := initialRetryDelay / 2
|
||||
randDelay := prand.Int63n(int64(initialRetryDelay)) //nolint:gosec
|
||||
randDelay := rand.Int63n(int64(initialRetryDelay)) //nolint:gosec
|
||||
|
||||
// 50% plus 0%-100% gives us the range of 50%-150%.
|
||||
initialDelay := halfDelay + time.Duration(randDelay)
|
||||
@@ -286,11 +281,11 @@ func (db *db) executeTransaction(f func(tx walletdb.ReadWriteTx) error,
|
||||
select {
|
||||
// Before we try again, we'll wait with a random backoff based
|
||||
// on the retry delay.
|
||||
case time.After(retryDelay):
|
||||
case <-time.After(retryDelay):
|
||||
return true
|
||||
|
||||
// If the daemon is shutting down, then we'll exit early.
|
||||
case <-db.Context.Done():
|
||||
case <-db.ctx.Done():
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user