Skip to content

Commit

Permalink
Add debug logging for deduplicated queries
Browse files Browse the repository at this point in the history
  • Loading branch information
gammazero committed Nov 26, 2024
1 parent 8673560 commit 193bf5b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions routing/providerquerymanager/providerquerymanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,6 @@ func (pqm *ProviderQueryManager) FindProvidersAsync(sessionCtx context.Context,
close(ch)
span.End()
return ch
case <-sessionCtx.Done():
ch := make(chan peer.AddrInfo)
close(ch)
return ch
}

// DO NOT select on sessionCtx. We only want to abort here if we're
Expand Down Expand Up @@ -486,6 +482,13 @@ func (npqm *newProvideQueryMessage) handle(pqm *ProviderQueryManager) {
span.AddEvent("NewQuery", trace.WithAttributes(attribute.Stringer("cid", npqm.k)))
ctx = trace.ContextWithSpan(ctx, span)

// Use context derived from pqm.ctx here, and not the context from the
// request (npqm.ctx), because this inProgressRequestStatus applies to
// all in-progress requests for the CID (npqm.k).
//
// For tracing, this means that only the span from the first
// request-in-progress for a CID is used, even if there are multiple
// requests for the same CID.
requestStatus = &inProgressRequestStatus{
listeners: make(map[chan peer.AddrInfo]struct{}),
ctx: ctx,
Expand All @@ -504,6 +507,7 @@ func (npqm *newProvideQueryMessage) handle(pqm *ProviderQueryManager) {
}
} else {
trace.SpanFromContext(npqm.ctx).AddEvent("JoinQuery", trace.WithAttributes(attribute.Stringer("cid", npqm.k)))
log.Debugf("Joined existing query for cid %s which now has %d queries in progress", npqm.k, len(requestStatus.listeners)+1)
}
inProgressChan := make(chan peer.AddrInfo)
requestStatus.listeners[inProgressChan] = struct{}{}
Expand Down

0 comments on commit 193bf5b

Please sign in to comment.