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 1e7b192 commit 1e67a84
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

Check failure on line 69 in batch/batch.go

View workflow job for this annotation

GitHub Actions / lint code

return with no blank line before (nlreturn)
}
}
return nil
Expand Down

0 comments on commit 1e67a84

Please sign in to comment.