Skip to content

Commit e4e144e

Browse files
authored
Merge pull request #41 from unistack-org/backoff
use backoff for lookup too
2 parents e41b322 + 4a22454 commit e4e144e

File tree

3 files changed

+46
-27
lines changed

3 files changed

+46
-27
lines changed

drpc.go

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"go.unistack.org/micro/v3/codec"
1616
"go.unistack.org/micro/v3/errors"
1717
"go.unistack.org/micro/v3/metadata"
18+
"go.unistack.org/micro/v3/selector"
1819
"storj.io/drpc/drpcconn"
1920
dmetadata "storj.io/drpc/drpcmetadata"
2021
)
@@ -401,18 +402,7 @@ func (d *drpcClient) Call(ctx context.Context, req client.Request, rsp interface
401402
callOpts.Address = []string{d.opts.Proxy}
402403
}
403404

404-
// lookup the route to send the reques to
405-
// TODO apply any filtering here
406-
routes, err := d.opts.Lookup(ctx, req, callOpts)
407-
if err != nil {
408-
return errors.InternalServerError("go.micro.client", err.Error())
409-
}
410-
411-
// balance the list of nodes
412-
next, err := callOpts.Selector.Select(routes)
413-
if err != nil {
414-
return err
415-
}
405+
var next selector.Next
416406

417407
// return errors.New("go.micro.client", "request timeout", 408)
418408
call := func(i int) error {
@@ -427,6 +417,23 @@ func (d *drpcClient) Call(ctx context.Context, req client.Request, rsp interface
427417
time.Sleep(t)
428418
}
429419

420+
if next == nil {
421+
var routes []string
422+
423+
// lookup the route to send the reques to
424+
// TODO apply any filtering here
425+
routes, err = d.opts.Lookup(ctx, req, callOpts)
426+
if err != nil {
427+
return errors.InternalServerError("go.micro.client", err.Error())
428+
}
429+
430+
// balance the list of nodes
431+
next, err = callOpts.Selector.Select(routes)
432+
if err != nil {
433+
return err
434+
}
435+
}
436+
430437
// get the next node
431438
node := next()
432439

@@ -520,18 +527,7 @@ func (g *drpcClient) Stream(ctx context.Context, req client.Request, opts ...cli
520527
callOpts.Address = []string{g.opts.Proxy}
521528
}
522529
523-
// lookup the route to send the reques to
524-
// TODO: move to internal lookup func
525-
routes, err := g.opts.Lookup(ctx, req, callOpts)
526-
if err != nil {
527-
return nil, errors.InternalServerError("go.micro.client", err.Error())
528-
}
529-
530-
// balance the list of nodes
531-
next, err := callOpts.Selector.Select(routes)
532-
if err != nil {
533-
return nil, err
534-
}
530+
var next selector.Next
535531
536532
call := func(i int) (client.Stream, error) {
537533
// call backoff first. Someone may want an initial start delay
@@ -545,6 +541,23 @@ func (g *drpcClient) Stream(ctx context.Context, req client.Request, opts ...cli
545541
time.Sleep(t)
546542
}
547543
544+
if next == nil {
545+
var routes []string
546+
547+
// lookup the route to send the reques to
548+
// TODO apply any filtering here
549+
routes, err = d.opts.Lookup(ctx, req, callOpts)
550+
if err != nil {
551+
return nil, errors.InternalServerError("go.micro.client", err.Error())
552+
}
553+
554+
// balance the list of nodes
555+
next, err := callOpts.Selector.Select(routes)
556+
if err != nil {
557+
return nil, err
558+
}
559+
}
560+
548561
// get the next node
549562
node := next()
550563

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ module go.unistack.org/micro-client-drpc/v3
33
go 1.16
44

55
require (
6+
github.com/google/gnostic v0.6.9 // indirect
7+
github.com/zeebo/errs v1.3.0 // indirect
68
go.unistack.org/micro/v3 v3.9.7
9+
google.golang.org/protobuf v1.28.0 // indirect
710
storj.io/drpc v0.0.30
811
)

go.sum

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw
3939
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
4040
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
4141
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
42-
github.com/google/gnostic v0.6.6 h1:MVSM2r2j9aRUvYNym66JGW96Ddd5MN4sTi59yktb6yk=
4342
github.com/google/gnostic v0.6.6/go.mod h1:Nm8234We1lq6iB9OmlgNv3nH91XLLVZHCDayfA3xq+E=
43+
github.com/google/gnostic v0.6.9 h1:ZK/5VhkoX835RikCHpSUJV9a+S3e1zLh59YnyWeBW+0=
44+
github.com/google/gnostic v0.6.9/go.mod h1:Nm8234We1lq6iB9OmlgNv3nH91XLLVZHCDayfA3xq+E=
4445
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
4546
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
4647
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
@@ -71,8 +72,9 @@ github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:
7172
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
7273
github.com/zeebo/assert v1.3.0 h1:g7C04CbJuIDKNPFHmsk4hwZDO5O+kntRxzaUoNXj+IQ=
7374
github.com/zeebo/assert v1.3.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0=
74-
github.com/zeebo/errs v1.2.2 h1:5NFypMTuSdoySVTqlNs1dEoU21QVamMQJxW/Fii5O7g=
7575
github.com/zeebo/errs v1.2.2/go.mod h1:sgbWHsvVuTPHcqJJGQ1WhI5KbWlHYz+2+2C/LSEtCw4=
76+
github.com/zeebo/errs v1.3.0 h1:hmiaKqgYZzcVgRL1Vkc1Mn2914BbzB0IBxs+ebeutGs=
77+
github.com/zeebo/errs v1.3.0/go.mod h1:sgbWHsvVuTPHcqJJGQ1WhI5KbWlHYz+2+2C/LSEtCw4=
7678
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
7779
go.unistack.org/micro-proto/v3 v3.2.7 h1:zG6d69kHc+oij2lwQ3AfrCgdjiEVRG2A7TlsxjusWs4=
7880
go.unistack.org/micro-proto/v3 v3.2.7/go.mod h1:ZltVWNECD5yK+40+OCONzGw4OtmSdTpVi8/KFgo9dqM=
@@ -146,8 +148,9 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD
146148
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
147149
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
148150
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
149-
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
150151
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
152+
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
153+
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
151154
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
152155
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
153156
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

0 commit comments

Comments
 (0)