mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
swarm/network: Make trace persist across priorityqueue
This commit is contained in:
parent
cdef279a6b
commit
6c7f2db9cb
4 changed files with 23 additions and 18 deletions
|
|
@ -144,7 +144,6 @@ func (d *Delivery) handleRetrieveRequestMsg(ctx context.Context, sp *Peer, req *
|
||||||
ctx, osp = spancontext.StartSpan(
|
ctx, osp = spancontext.StartSpan(
|
||||||
ctx,
|
ctx,
|
||||||
"retrieve.request")
|
"retrieve.request")
|
||||||
defer osp.Finish()
|
|
||||||
|
|
||||||
s, err := sp.getServer(NewStream(swarmChunkServerStreamName, "", true))
|
s, err := sp.getServer(NewStream(swarmChunkServerStreamName, "", true))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -167,6 +166,7 @@ func (d *Delivery) handleRetrieveRequestMsg(ctx context.Context, sp *Peer, req *
|
||||||
}()
|
}()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
defer osp.Finish()
|
||||||
chunk, err := d.chunkStore.Get(ctx, req.Addr)
|
chunk, err := d.chunkStore.Get(ctx, req.Addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
retrieveChunkFail.Inc(1)
|
retrieveChunkFail.Inc(1)
|
||||||
|
|
@ -272,7 +272,7 @@ func (d *Delivery) RequestFromPeers(ctx context.Context, req *network.Request) (
|
||||||
Addr: req.Addr,
|
Addr: req.Addr,
|
||||||
SkipCheck: req.SkipCheck,
|
SkipCheck: req.SkipCheck,
|
||||||
HopCount: req.HopCount,
|
HopCount: req.HopCount,
|
||||||
}, Top)
|
}, Top, "request.from.peers")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -300,7 +300,7 @@ func (p *Peer) handleOfferedHashesMsg(ctx context.Context, req *OfferedHashesMsg
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Trace("sending want batch", "peer", p.ID(), "stream", msg.Stream, "from", msg.From, "to", msg.To)
|
log.Trace("sending want batch", "peer", p.ID(), "stream", msg.Stream, "from", msg.From, "to", msg.To)
|
||||||
err := p.SendPriority(ctx, msg, c.priority)
|
err := p.SendPriority(ctx, msg, c.priority, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn("SendPriority error", "err", err)
|
log.Warn("SendPriority error", "err", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,7 @@ type Peer struct {
|
||||||
// on creating a new client in offered hashes handler.
|
// on creating a new client in offered hashes handler.
|
||||||
clientParams map[Stream]*clientParams
|
clientParams map[Stream]*clientParams
|
||||||
quit chan struct{}
|
quit chan struct{}
|
||||||
|
spans sync.Map
|
||||||
}
|
}
|
||||||
|
|
||||||
type WrappedPriorityMsg struct {
|
type WrappedPriorityMsg struct {
|
||||||
|
|
@ -82,10 +83,16 @@ func NewPeer(peer *protocols.Peer, streamer *Registry) *Peer {
|
||||||
clients: make(map[Stream]*client),
|
clients: make(map[Stream]*client),
|
||||||
clientParams: make(map[Stream]*clientParams),
|
clientParams: make(map[Stream]*clientParams),
|
||||||
quit: make(chan struct{}),
|
quit: make(chan struct{}),
|
||||||
|
spans: sync.Map{},
|
||||||
}
|
}
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
go p.pq.Run(ctx, func(i interface{}) {
|
go p.pq.Run(ctx, func(i interface{}) {
|
||||||
wmsg := i.(WrappedPriorityMsg)
|
wmsg := i.(WrappedPriorityMsg)
|
||||||
|
defer p.spans.Delete(wmsg.Context)
|
||||||
|
sp, ok := p.spans.Load(wmsg.Context)
|
||||||
|
if ok {
|
||||||
|
defer sp.(opentracing.Span).Finish()
|
||||||
|
}
|
||||||
err := p.Send(wmsg.Context, wmsg.Msg)
|
err := p.Send(wmsg.Context, wmsg.Msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Message send error, dropping peer", "peer", p.ID(), "err", err)
|
log.Error("Message send error, dropping peer", "peer", p.ID(), "err", err)
|
||||||
|
|
@ -130,7 +137,6 @@ func NewPeer(peer *protocols.Peer, streamer *Registry) *Peer {
|
||||||
// Deliver sends a storeRequestMsg protocol message to the peer
|
// Deliver sends a storeRequestMsg protocol message to the peer
|
||||||
// Depending on the `syncing` parameter we send different message types
|
// Depending on the `syncing` parameter we send different message types
|
||||||
func (p *Peer) Deliver(ctx context.Context, chunk storage.Chunk, priority uint8, syncing bool) error {
|
func (p *Peer) Deliver(ctx context.Context, chunk storage.Chunk, priority uint8, syncing bool) error {
|
||||||
var sp opentracing.Span
|
|
||||||
var msg interface{}
|
var msg interface{}
|
||||||
|
|
||||||
spanName := "send.chunk.delivery"
|
spanName := "send.chunk.delivery"
|
||||||
|
|
@ -151,18 +157,21 @@ func (p *Peer) Deliver(ctx context.Context, chunk storage.Chunk, priority uint8,
|
||||||
}
|
}
|
||||||
spanName += ".retrieval"
|
spanName += ".retrieval"
|
||||||
}
|
}
|
||||||
ctx, sp = spancontext.StartSpan(
|
|
||||||
ctx,
|
|
||||||
spanName)
|
|
||||||
defer sp.Finish()
|
|
||||||
|
|
||||||
return p.SendPriority(ctx, msg, priority)
|
return p.SendPriority(ctx, msg, priority, spanName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendPriority sends message to the peer using the outgoing priority queue
|
// SendPriority sends message to the peer using the outgoing priority queue
|
||||||
func (p *Peer) SendPriority(ctx context.Context, msg interface{}, priority uint8) error {
|
func (p *Peer) SendPriority(ctx context.Context, msg interface{}, priority uint8, traceId string) error {
|
||||||
defer metrics.GetOrRegisterResettingTimer(fmt.Sprintf("peer.sendpriority_t.%d", priority), nil).UpdateSince(time.Now())
|
defer metrics.GetOrRegisterResettingTimer(fmt.Sprintf("peer.sendpriority_t.%d", priority), nil).UpdateSince(time.Now())
|
||||||
metrics.GetOrRegisterCounter(fmt.Sprintf("peer.sendpriority.%d", priority), nil).Inc(1)
|
metrics.GetOrRegisterCounter(fmt.Sprintf("peer.sendpriority.%d", priority), nil).Inc(1)
|
||||||
|
if traceId != "" {
|
||||||
|
ctx, sp := spancontext.StartSpan(
|
||||||
|
ctx,
|
||||||
|
traceId,
|
||||||
|
)
|
||||||
|
p.spans.Store(ctx, sp)
|
||||||
|
}
|
||||||
wmsg := WrappedPriorityMsg{
|
wmsg := WrappedPriorityMsg{
|
||||||
Context: ctx,
|
Context: ctx,
|
||||||
Msg: msg,
|
Msg: msg,
|
||||||
|
|
@ -177,11 +186,6 @@ func (p *Peer) SendPriority(ctx context.Context, msg interface{}, priority uint8
|
||||||
|
|
||||||
// SendOfferedHashes sends OfferedHashesMsg protocol msg
|
// SendOfferedHashes sends OfferedHashesMsg protocol msg
|
||||||
func (p *Peer) SendOfferedHashes(s *server, f, t uint64) error {
|
func (p *Peer) SendOfferedHashes(s *server, f, t uint64) error {
|
||||||
var sp opentracing.Span
|
|
||||||
ctx, sp := spancontext.StartSpan(
|
|
||||||
context.TODO(),
|
|
||||||
"send.offered.hashes")
|
|
||||||
defer sp.Finish()
|
|
||||||
|
|
||||||
hashes, from, to, proof, err := s.setNextBatch(f, t)
|
hashes, from, to, proof, err := s.setNextBatch(f, t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -205,7 +209,7 @@ func (p *Peer) SendOfferedHashes(s *server, f, t uint64) error {
|
||||||
Stream: s.stream,
|
Stream: s.stream,
|
||||||
}
|
}
|
||||||
log.Trace("Swarm syncer offer batch", "peer", p.ID(), "stream", s.stream, "len", len(hashes), "from", from, "to", to)
|
log.Trace("Swarm syncer offer batch", "peer", p.ID(), "stream", s.stream, "len", len(hashes), "from", from, "to", to)
|
||||||
return p.SendPriority(ctx, msg, s.priority)
|
return p.SendPriority(context.TODO(), msg, s.priority, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Peer) getServer(s Stream) (*server, error) {
|
func (p *Peer) getServer(s Stream) (*server, error) {
|
||||||
|
|
|
||||||
|
|
@ -359,7 +359,7 @@ func (r *Registry) Subscribe(peerId enode.ID, s Stream, h *Range, priority uint8
|
||||||
}
|
}
|
||||||
log.Debug("Subscribe ", "peer", peerId, "stream", s, "history", h)
|
log.Debug("Subscribe ", "peer", peerId, "stream", s, "history", h)
|
||||||
|
|
||||||
return peer.SendPriority(context.TODO(), msg, priority)
|
return peer.SendPriority(context.TODO(), msg, priority, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Registry) Unsubscribe(peerId enode.ID, s Stream) error {
|
func (r *Registry) Unsubscribe(peerId enode.ID, s Stream) error {
|
||||||
|
|
@ -729,7 +729,8 @@ func (c *client) batchDone(p *Peer, req *OfferedHashesMsg, hashes []byte) error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := p.SendPriority(context.TODO(), tp, c.priority); err != nil {
|
|
||||||
|
if err := p.SendPriority(context.TODO(), tp, c.priority, ""); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if c.to > 0 && tp.Takeover.End >= c.to {
|
if c.to > 0 && tp.Takeover.End >= c.to {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue