Skip to content

Commit

Permalink
use badger ErrConflict variable
Browse files Browse the repository at this point in the history
  • Loading branch information
fredcarle committed Jan 27, 2023
1 parent 5b0b3e5 commit 18fc86f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
5 changes: 4 additions & 1 deletion datastore/badger/v3/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ import (

var log = logger.Logger("badger")

var ErrClosed = errors.New("datastore closed")
var (
ErrClosed = errors.New("datastore closed")
ErrTxnConflict = badger.ErrConflict
)

type Datastore struct {
DB *badger.DB
Expand Down
3 changes: 2 additions & 1 deletion net/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

"github.com/sourcenetwork/defradb/client"
"github.com/sourcenetwork/defradb/core"
"github.com/sourcenetwork/defradb/datastore/badger/v3"
"github.com/sourcenetwork/defradb/errors"
"github.com/sourcenetwork/defradb/logging"
pb "github.com/sourcenetwork/defradb/net/pb"
Expand Down Expand Up @@ -208,7 +209,7 @@ func (s *server) PushLog(ctx context.Context, req *pb.PushLogRequest) (*pb.PushL
}

if txnErr = txn.Commit(ctx); txnErr != nil {
if txnErr.Error() == "Transaction Conflict. Please retry" {
if errors.Is(txnErr, badger.ErrTxnConflict) {
continue
}
return &pb.PushLogReply{}, txnErr
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/net/state/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/sourcenetwork/defradb/client"
"github.com/sourcenetwork/defradb/config"
"github.com/sourcenetwork/defradb/datastore/badger/v3"
coreDB "github.com/sourcenetwork/defradb/db"
"github.com/sourcenetwork/defradb/errors"
"github.com/sourcenetwork/defradb/logging"
Expand Down Expand Up @@ -179,7 +180,7 @@ func updateDocument(
// retry limit is breached - important incase this is a different error)
for i := 0; i < db.MaxTxnRetries(); i++ {
err = col.Save(ctx, doc)
if err != nil && err.Error() == "Transaction Conflict. Please retry" {
if err != nil && errors.Is(err, badger.ErrTxnConflict) {
time.Sleep(100 * time.Millisecond)
continue
}
Expand Down

0 comments on commit 18fc86f

Please sign in to comment.