summaryrefslogtreecommitdiff
path: root/vendor/google.golang.org/grpc/picker_wrapper.go
diff options
context:
space:
mode:
authorLibravatar dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>2023-09-18 13:47:28 +0100
committerLibravatar GitHub <noreply@github.com>2023-09-18 13:47:28 +0100
commitc6fdcd52fabb6984de280f763ec5dc2023613054 (patch)
tree939de6cc265fb0c73ef40c2129c8eb298fd93b0c /vendor/google.golang.org/grpc/picker_wrapper.go
parent[chore]: Bump github.com/miekg/dns from 1.1.55 to 1.1.56 (#2204) (diff)
downloadgotosocial-c6fdcd52fabb6984de280f763ec5dc2023613054.tar.xz
[chore]: Bump go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp from 1.17.0 to 1.18.0 (#2207)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Diffstat (limited to 'vendor/google.golang.org/grpc/picker_wrapper.go')
-rw-r--r--vendor/google.golang.org/grpc/picker_wrapper.go34
1 files changed, 27 insertions, 7 deletions
diff --git a/vendor/google.golang.org/grpc/picker_wrapper.go b/vendor/google.golang.org/grpc/picker_wrapper.go
index 02f975951..236837f41 100644
--- a/vendor/google.golang.org/grpc/picker_wrapper.go
+++ b/vendor/google.golang.org/grpc/picker_wrapper.go
@@ -28,21 +28,26 @@ import (
"google.golang.org/grpc/internal/channelz"
istatus "google.golang.org/grpc/internal/status"
"google.golang.org/grpc/internal/transport"
+ "google.golang.org/grpc/stats"
"google.golang.org/grpc/status"
)
// pickerWrapper is a wrapper of balancer.Picker. It blocks on certain pick
// actions and unblock when there's a picker update.
type pickerWrapper struct {
- mu sync.Mutex
- done bool
- idle bool
- blockingCh chan struct{}
- picker balancer.Picker
+ mu sync.Mutex
+ done bool
+ idle bool
+ blockingCh chan struct{}
+ picker balancer.Picker
+ statsHandlers []stats.Handler // to record blocking picker calls
}
-func newPickerWrapper() *pickerWrapper {
- return &pickerWrapper{blockingCh: make(chan struct{})}
+func newPickerWrapper(statsHandlers []stats.Handler) *pickerWrapper {
+ return &pickerWrapper{
+ blockingCh: make(chan struct{}),
+ statsHandlers: statsHandlers,
+ }
}
// updatePicker is called by UpdateBalancerState. It unblocks all blocked pick.
@@ -95,6 +100,7 @@ func (pw *pickerWrapper) pick(ctx context.Context, failfast bool, info balancer.
var ch chan struct{}
var lastPickErr error
+
for {
pw.mu.Lock()
if pw.done {
@@ -129,6 +135,20 @@ func (pw *pickerWrapper) pick(ctx context.Context, failfast bool, info balancer.
continue
}
+ // If the channel is set, it means that the pick call had to wait for a
+ // new picker at some point. Either it's the first iteration and this
+ // function received the first picker, or a picker errored with
+ // ErrNoSubConnAvailable or errored with failfast set to false, which
+ // will trigger a continue to the next iteration. In the first case this
+ // conditional will hit if this call had to block (the channel is set).
+ // In the second case, the only way it will get to this conditional is
+ // if there is a new picker.
+ if ch != nil {
+ for _, sh := range pw.statsHandlers {
+ sh.HandleRPC(ctx, &stats.PickerUpdated{})
+ }
+ }
+
ch = pw.blockingCh
p := pw.picker
pw.mu.Unlock()