diff options
author | lash <nolash@users.noreply.github.com> | 2019-02-20 21:50:37 +0800 |
---|---|---|
committer | Viktor TrĂ³n <viktor.tron@gmail.com> | 2019-02-20 21:50:37 +0800 |
commit | d36e974ba303d12d79d769d0811dd5babcf6688f (patch) | |
tree | 22073c5ae7d6e0b243ed7f4bed4ed9aae054a116 /swarm/storage | |
parent | 460d206f309fc0884c666bd191a1b6a4b63462fc (diff) | |
download | go-tangerine-d36e974ba303d12d79d769d0811dd5babcf6688f.tar go-tangerine-d36e974ba303d12d79d769d0811dd5babcf6688f.tar.gz go-tangerine-d36e974ba303d12d79d769d0811dd5babcf6688f.tar.bz2 go-tangerine-d36e974ba303d12d79d769d0811dd5babcf6688f.tar.lz go-tangerine-d36e974ba303d12d79d769d0811dd5babcf6688f.tar.xz go-tangerine-d36e974ba303d12d79d769d0811dd5babcf6688f.tar.zst go-tangerine-d36e974ba303d12d79d769d0811dd5babcf6688f.zip |
swarm/network: Keep span across roundtrip (#19140)
* swarm/newtork: WIP Span request span until delivery and put
* swarm/storage: Introduce new trace across single fetcher lifespan
* swarm/network: Put span ids for sendpriority in context value
* swarm: Add global span store in tracing
* swarm/tracing: Add context key constants
* swarm/tracing: Add comments
* swarm/storage: Remove redundant fix for filestore
* swarm/tracing: Elaborate constants comments
* swarm/network, swarm/storage, swarm:tracing: Minor cleanup
Diffstat (limited to 'swarm/storage')
-rw-r--r-- | swarm/storage/netstore.go | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/swarm/storage/netstore.go b/swarm/storage/netstore.go index 202af2bf5..8a44f51a8 100644 --- a/swarm/storage/netstore.go +++ b/swarm/storage/netstore.go @@ -26,6 +26,9 @@ import ( "github.com/ethereum/go-ethereum/p2p/enode" "github.com/ethereum/go-ethereum/swarm/log" + "github.com/ethereum/go-ethereum/swarm/spancontext" + "github.com/opentracing/opentracing-go" + lru "github.com/hashicorp/golang-lru" ) @@ -208,7 +211,11 @@ func (n *NetStore) getOrCreateFetcher(ctx context.Context, ref Address) *fetcher // the peers which requested the chunk should not be requested to deliver it. peers := &sync.Map{} - fetcher := newFetcher(ref, n.NewNetFetcherFunc(cctx, ref, peers), destroy, peers, n.closeC) + cctx, sp := spancontext.StartSpan( + cctx, + "netstore.fetcher", + ) + fetcher := newFetcher(sp, ref, n.NewNetFetcherFunc(cctx, ref, peers), destroy, peers, n.closeC) n.fetchers.Add(key, fetcher) return fetcher @@ -233,15 +240,16 @@ func (n *NetStore) RequestsCacheLen() int { // One fetcher object is responsible to fetch one chunk for one address, and keep track of all the // peers who have requested it and did not receive it yet. type fetcher struct { - addr Address // address of chunk - chunk Chunk // fetcher can set the chunk on the fetcher - deliveredC chan struct{} // chan signalling chunk delivery to requests - cancelledC chan struct{} // chan signalling the fetcher has been cancelled (removed from fetchers in NetStore) - netFetcher NetFetcher // remote fetch function to be called with a request source taken from the context - cancel func() // cleanup function for the remote fetcher to call when all upstream contexts are called - peers *sync.Map // the peers which asked for the chunk - requestCnt int32 // number of requests on this chunk. If all the requests are done (delivered or context is done) the cancel function is called - deliverOnce *sync.Once // guarantees that we only close deliveredC once + addr Address // address of chunk + chunk Chunk // fetcher can set the chunk on the fetcher + deliveredC chan struct{} // chan signalling chunk delivery to requests + cancelledC chan struct{} // chan signalling the fetcher has been cancelled (removed from fetchers in NetStore) + netFetcher NetFetcher // remote fetch function to be called with a request source taken from the context + cancel func() // cleanup function for the remote fetcher to call when all upstream contexts are called + peers *sync.Map // the peers which asked for the chunk + requestCnt int32 // number of requests on this chunk. If all the requests are done (delivered or context is done) the cancel function is called + deliverOnce *sync.Once // guarantees that we only close deliveredC once + span opentracing.Span // measure retrieve time per chunk } // newFetcher creates a new fetcher object for the fiven addr. fetch is the function which actually @@ -250,7 +258,7 @@ type fetcher struct { // 1. when the chunk has been fetched all peers have been either notified or their context has been done // 2. the chunk has not been fetched but all context from all the requests has been done // The peers map stores all the peers which have requested chunk. -func newFetcher(addr Address, nf NetFetcher, cancel func(), peers *sync.Map, closeC chan struct{}) *fetcher { +func newFetcher(span opentracing.Span, addr Address, nf NetFetcher, cancel func(), peers *sync.Map, closeC chan struct{}) *fetcher { cancelOnce := &sync.Once{} // cancel should only be called once return &fetcher{ addr: addr, @@ -264,6 +272,7 @@ func newFetcher(addr Address, nf NetFetcher, cancel func(), peers *sync.Map, clo }) }, peers: peers, + span: span, } } @@ -276,6 +285,7 @@ func (f *fetcher) Fetch(rctx context.Context) (Chunk, error) { if atomic.AddInt32(&f.requestCnt, -1) == 0 { f.cancel() } + f.span.Finish() }() // The peer asking for the chunk. Store in the shared peers map, but delete after the request |