Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
Merge pull request #3 from filecoin-project/fix/duplicate-blockstore-…
Browse files Browse the repository at this point in the history
…puts

fix duplicate blockstore puts returning MDB_KEY_EXISTS.
  • Loading branch information
raulk authored Dec 1, 2020
2 parents 6874fef + d7f9ef6 commit bf54206
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions blockstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ func (b *Blockstore) GetSize(cid cid.Cid) (int, error) {
func (b *Blockstore) Put(block blocks.Block) error {
return b.env.Update(func(txn *lmdb.Txn) error {
err := txn.Put(b.db, block.Cid().Hash(), block.RawData(), lmdb.NoOverwrite)
if err != nil && !lmdb.IsErrno(err, lmdb.KeyExist) {
return err
if err == nil || lmdb.IsErrno(err, lmdb.KeyExist) {
return nil
}
return err
})
Expand All @@ -164,6 +164,7 @@ func (b *Blockstore) PutMany(blocks []blocks.Block) error {
for _, block := range blocks {
err := txn.Put(b.db, block.Cid().Hash(), block.RawData(), lmdb.NoOverwrite)
if err != nil && !lmdb.IsErrno(err, lmdb.KeyExist) {
txn.Abort() // short-circuit
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/multiformats/go-varint v0.0.6 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/raulk/go-bs-tests v0.0.3
github.com/raulk/go-bs-tests v0.0.4
go.uber.org/zap v1.16.0 // indirect
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a // indirect
golang.org/x/lint v0.0.0-20200130185559-910be7a94367 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/raulk/go-bs-tests v0.0.3 h1:Kg2BA12vA5oJ6BHb2BDinMkhcoL6IKME7dP/Ukvmb48=
github.com/raulk/go-bs-tests v0.0.3/go.mod h1:ZREaOSaReTvV4nY7Qh6Lkl+QisYXNBWcPRa0gjrIaG4=
github.com/raulk/go-bs-tests v0.0.4 h1:gYUYmIFMBnp2mtZQuiP/ZGtSTSPvmDBjWBz0xTZz4X8=
github.com/raulk/go-bs-tests v0.0.4/go.mod h1:ZREaOSaReTvV4nY7Qh6Lkl+QisYXNBWcPRa0gjrIaG4=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
Expand Down

0 comments on commit bf54206

Please sign in to comment.