Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
dennis-tra committed Sep 27, 2023
1 parent bf7ff23 commit 6b86134
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions v2/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"context"
"errors"
"fmt"
"os"
"runtime/pprof"
"time"

ds "github.com/ipfs/go-datastore"
Expand Down Expand Up @@ -389,6 +391,17 @@ func (d *DHT) searchValueRoutine(ctx context.Context, backend Backend, ns string
// cancel the query.
quorum := d.getQuorum(ropt)

dumpCtx, dumpCancel := context.WithCancel(ctx)
defer dumpCancel()
go func() {
select {
case <-dumpCtx.Done():
case <-time.After(2 * time.Second):
fmt.Println("TIMED OUT:")
pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)

Check warning on line 401 in v2/routing.go

View check run for this annotation

Codecov / codecov/patch

v2/routing.go#L399-L401

Added lines #L399 - L401 were not covered by tests
}
}()

fn := func(ctx context.Context, id kadt.PeerID, resp *pb.Message, stats coordt.QueryStats) error {
rec := resp.GetRecord()
if rec == nil {
Expand All @@ -402,17 +415,16 @@ func (d *DHT) searchValueRoutine(ctx context.Context, backend Backend, ns string

idx, _ := backend.Validate(ctx, path, best, rec.GetValue())
switch idx {
case 0:
case 0: // "best" is still the best value
if bytes.Equal(best, rec.GetValue()) {
quorumPeers[id] = struct{}{}
}
case 1:
case 1: // rec.GetValue() is better than our current "best"
best = rec.GetValue()
quorumPeers = map[kadt.PeerID]struct{}{}
quorumPeers[id] = struct{}{}
out <- rec.GetValue()
case -1:
// no valid value found yet
case -1: // "best" and rec.GetValue() are both invalid
return nil
default:
d.log.Warn("unexpected validate index", slog.Int("idx", idx))

Check warning on line 430 in v2/routing.go

View check run for this annotation

Codecov / codecov/patch

v2/routing.go#L429-L430

Added lines #L429 - L430 were not covered by tests
Expand Down

0 comments on commit 6b86134

Please sign in to comment.