Skip to content

Commit

Permalink
batch: handle serialization errors correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
aakselrod committed Nov 2, 2024
1 parent c20ef70 commit 6065746
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions batch/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"sync"

"github.com/lightningnetwork/lnd/kvdb"
"github.com/lightningnetwork/lnd/sqldb"
)

// errSolo is a sentinel error indicating that the requester should re-run the
Expand Down Expand Up @@ -55,8 +56,17 @@ func (b *batch) run() {
for i, req := range b.reqs {
err := req.Update(tx)
if err != nil {
failIdx = i
return err
// If we get a serialization error, we
// want the underlying SQL retry
// mechanism to retry the entire batch.
// Otherwise, we can succeed in an
// sqldb retry and still re-execute the
// failing request individually.
dbErr := sqldb.MapSQLError(err)
if !sqldb.IsSerializationError(dbErr) {
failIdx = i
}
return dbErr
}
}
return nil
Expand Down

0 comments on commit 6065746

Please sign in to comment.