From 6f4dcb14c6e5df85f4282362e52153bb8c216152 Mon Sep 17 00:00:00 2001 From: Anton Evangelatov Date: Mon, 4 Feb 2019 14:55:34 +0100 Subject: [PATCH] swarm/storage: fix tracing --- swarm/network/fetcher.go | 5 +---- swarm/network/stream/delivery.go | 3 ++- swarm/storage/netstore.go | 8 ++++---- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/swarm/network/fetcher.go b/swarm/network/fetcher.go index d42e95e2cc..1d29b87277 100644 --- a/swarm/network/fetcher.go +++ b/swarm/network/fetcher.go @@ -23,7 +23,6 @@ import ( "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/p2p/enode" - "github.com/ethereum/go-ethereum/swarm/spancontext" "github.com/ethereum/go-ethereum/swarm/storage" ) @@ -120,7 +119,6 @@ func (f *FetcherFactory) New(ctx context.Context, source storage.Address, peers // NewFetcher creates a new Fetcher for the given chunk address using the given request function. func NewFetcher(ctx context.Context, addr storage.Address, rf RequestFunc, skipCheck bool) *Fetcher { - sctx, sp := spancontext.StartSpan(ctx, "fetcher") return &Fetcher{ addr: addr, protoRequestFunc: rf, @@ -128,9 +126,8 @@ func NewFetcher(ctx context.Context, addr storage.Address, rf RequestFunc, skipC requestC: make(chan uint8), searchTimeout: defaultSearchTimeout, skipCheck: skipCheck, - ctx: sctx, + ctx: ctx, quitFunc: func() { - sp.Finish() }, } } diff --git a/swarm/network/stream/delivery.go b/swarm/network/stream/delivery.go index 988afcce84..29e75af6e4 100644 --- a/swarm/network/stream/delivery.go +++ b/swarm/network/stream/delivery.go @@ -213,11 +213,12 @@ func (d *Delivery) handleChunkDeliveryMsg(ctx context.Context, sp *Peer, req *Ch ctx, osp = spancontext.StartSpan( ctx, "chunk.delivery") - defer osp.Finish() processReceivedChunksCount.Inc(1) go func() { + defer osp.Finish() + req.peer = sp err := d.chunkStore.Put(ctx, storage.NewChunk(req.Addr, req.SData)) if err != nil { diff --git a/swarm/storage/netstore.go b/swarm/storage/netstore.go index 502e4ee2ea..e7a7998272 100644 --- a/swarm/storage/netstore.go +++ b/swarm/storage/netstore.go @@ -150,7 +150,7 @@ func (n *NetStore) get(ctx context.Context, ref Address) (Chunk, func(context.Co } // The chunk is not available in the LocalStore, let's get the fetcher for it, or create a new one // if it doesn't exist yet - f := n.getOrCreateFetcher(ref) + f := n.getOrCreateFetcher(ctx, ref) // If the caller needs the chunk, it has to use the returned fetch function to get it return nil, f.Fetch, nil } @@ -161,7 +161,7 @@ func (n *NetStore) get(ctx context.Context, ref Address) (Chunk, func(context.Co // getOrCreateFetcher attempts at retrieving an existing fetchers // if none exists, creates one and saves it in the fetchers cache // caller must hold the lock -func (n *NetStore) getOrCreateFetcher(ref Address) *fetcher { +func (n *NetStore) getOrCreateFetcher(ctx context.Context, ref Address) *fetcher { if f := n.getFetcher(ref); f != nil { return f } @@ -169,7 +169,7 @@ func (n *NetStore) getOrCreateFetcher(ref Address) *fetcher { // no fetcher for the given address, we have to create a new one key := hex.EncodeToString(ref) // create the context during which fetching is kept alive - ctx, cancel := context.WithTimeout(context.Background(), fetcherTimeout) + cctx, cancel := context.WithTimeout(ctx, fetcherTimeout) // destroy is called when all requests finish destroy := func() { // remove fetcher from fetchers @@ -183,7 +183,7 @@ func (n *NetStore) getOrCreateFetcher(ref Address) *fetcher { // the peers which requested the chunk should not be requested to deliver it. peers := &sync.Map{} - fetcher := newFetcher(ref, n.NewNetFetcherFunc(ctx, ref, peers), destroy, peers, n.closeC) + fetcher := newFetcher(ref, n.NewNetFetcherFunc(cctx, ref, peers), destroy, peers, n.closeC) n.fetchers.Add(key, fetcher) return fetcher