Skip to content

Commit 5ee9616

Browse files
committed
ignore txn conflicts in blockstore
1 parent 37c72ba commit 5ee9616

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

datastore/blockstore.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
ipld "github.com/ipfs/go-ipld-format"
2323
"github.com/ipld/go-ipld-prime/storage/bsadapter"
2424

25+
"github.com/sourcenetwork/defradb/datastore/badger/v4"
2526
"github.com/sourcenetwork/defradb/errors"
2627
)
2728

@@ -113,19 +114,17 @@ func (bs *bstore) Put(ctx context.Context, block blocks.Block) error {
113114
if err == nil && exists {
114115
return nil // already stored.
115116
}
116-
return bs.store.Put(ctx, k, block.RawData())
117+
err = bs.store.Put(ctx, k, block.RawData())
118+
if errors.Is(err, badger.ErrTxnConflict) {
119+
return nil // ignore conflicts data is immutable
120+
}
121+
return err
117122
}
118123

119124
// PutMany stores multiple blocks to the blockstore.
120125
func (bs *bstore) PutMany(ctx context.Context, blocks []blocks.Block) error {
121126
for _, b := range blocks {
122-
k := dshelp.MultihashToDsKey(b.Cid().Hash())
123-
exists, err := bs.store.Has(ctx, k)
124-
if err == nil && exists {
125-
continue
126-
}
127-
128-
err = bs.store.Put(ctx, k, b.RawData())
127+
err := bs.Put(ctx, b)
129128
if err != nil {
130129
return err
131130
}

0 commit comments

Comments
 (0)