Skip to content
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.

Commit

Permalink
storage/netstore: explicit errors
Browse files Browse the repository at this point in the history
  • Loading branch information
nonsense committed Jun 14, 2019
1 parent 3be2aeb commit 7cf5a1c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 4 additions & 1 deletion storage/feed/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,10 @@ func (h *Handler) Lookup(ctx context.Context, query *Query) (*cacheEntry, error)
r := storage.NewRequest(id.Addr())
ch, err := h.chunkStore.Get(ctx, chunk.ModeGetLookup, r)
if err != nil {
return nil, nil
if err == context.DeadlineExceeded || err == storage.ErrNoSuitablePeer { // chunk not found
return nil, nil
}
return nil, err
}

var request Request
Expand Down
8 changes: 6 additions & 2 deletions storage/netstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ const (
fetchersCapacity = 500000
)

var (
ErrNoSuitablePeer = errors.New("no suitable peer")
)

// Fetcher is a struct which maintains state of remote requests.
// Fetchers are stored in fetchers map and signal to all interested parties if a given chunk is delivered
// the mutex controls who closes the channel, and make sure we close the channel only once
Expand Down Expand Up @@ -234,7 +238,7 @@ func (n *NetStore) RemoteFetch(ctx context.Context, req *Request, fi *Fetcher) e
log.Trace(err.Error(), "ref", ref)
osp.LogFields(olog.String("err", err.Error()))
osp.Finish()
return err
return ErrNoSuitablePeer
}

// add peer to the set of peers to skip from now
Expand All @@ -260,7 +264,7 @@ func (n *NetStore) RemoteFetch(ctx context.Context, req *Request, fi *Fetcher) e

osp.LogFields(olog.Bool("fail", true))
osp.Finish()
return errors.New("chunk couldnt be retrieved from remote nodes")
return ctx.Err()
}
}
}
Expand Down

0 comments on commit 7cf5a1c

Please sign in to comment.