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

Commit

Permalink
correctly convert the datastore not found errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Stebalien committed Aug 7, 2018
1 parent a17a33c commit 0d5887b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
7 changes: 3 additions & 4 deletions arc_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
lru "github.com/hashicorp/golang-lru"
blocks "github.com/ipfs/go-block-format"
cid "github.com/ipfs/go-cid"
ds "github.com/ipfs/go-datastore"
metrics "github.com/ipfs/go-metrics-interface"
)

Expand Down Expand Up @@ -41,7 +40,7 @@ func (b *arccache) DeleteBlock(k *cid.Cid) error {
b.arc.Remove(k) // Invalidate cache before deleting.
err := b.blockstore.DeleteBlock(k)
switch err {
case nil, ds.ErrNotFound, ErrNotFound:
case nil, ErrNotFound:
b.addCache(k, -1)
return err
default:
Expand Down Expand Up @@ -74,7 +73,7 @@ func (b *arccache) hasCached(k *cid.Cid) (has bool, size int, ok bool) {

func (b *arccache) Has(k *cid.Cid) (bool, error) {
blockSize, err := b.GetSize(k)
if err == ds.ErrNotFound {
if err == ErrNotFound {
return false, nil
}
return blockSize > -1, err
Expand All @@ -85,7 +84,7 @@ func (b *arccache) GetSize(k *cid.Cid) (int, error) {
return blockSize, nil
}
blockSize, err := b.blockstore.GetSize(k)
if err == ds.ErrNotFound {
if err == ErrNotFound {
b.addCache(k, -1)
} else if err == nil {
b.addCache(k, blockSize)
Expand Down
3 changes: 3 additions & 0 deletions blockstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ func (bs *blockstore) Has(k *cid.Cid) (bool, error) {

func (bs *blockstore) GetSize(k *cid.Cid) (int, error) {
maybeData, err := bs.datastore.Get(dshelp.CidToDsKey(k))
if err == ds.ErrNotFound {
return -1, ErrNotFound
}
if err != nil {
return -1, err
}
Expand Down
2 changes: 1 addition & 1 deletion bloom_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestPutManyAddsToBloom(t *testing.T) {
t.Fatal(err)
}
blockSize, err = cachedbs.GetSize(block2.Cid())
if err != nil && err != ds.ErrNotFound {
if err != nil && err != ErrNotFound {
t.Fatal(err)
}
if blockSize > -1 || has {
Expand Down

0 comments on commit 0d5887b

Please sign in to comment.