diff options
Diffstat (limited to 'vendor/google.golang.org/grpc/balancer.go')
-rw-r--r-- | vendor/google.golang.org/grpc/balancer.go | 46 |
1 files changed, 20 insertions, 26 deletions
diff --git a/vendor/google.golang.org/grpc/balancer.go b/vendor/google.golang.org/grpc/balancer.go index cde472c..a78e702 100644 --- a/vendor/google.golang.org/grpc/balancer.go +++ b/vendor/google.golang.org/grpc/balancer.go | |||
@@ -19,19 +19,20 @@ | |||
19 | package grpc | 19 | package grpc |
20 | 20 | ||
21 | import ( | 21 | import ( |
22 | "fmt" | 22 | "context" |
23 | "net" | 23 | "net" |
24 | "sync" | 24 | "sync" |
25 | 25 | ||
26 | "golang.org/x/net/context" | ||
27 | "google.golang.org/grpc/codes" | 26 | "google.golang.org/grpc/codes" |
28 | "google.golang.org/grpc/credentials" | 27 | "google.golang.org/grpc/credentials" |
29 | "google.golang.org/grpc/grpclog" | 28 | "google.golang.org/grpc/grpclog" |
30 | "google.golang.org/grpc/naming" | 29 | "google.golang.org/grpc/naming" |
30 | "google.golang.org/grpc/status" | ||
31 | ) | 31 | ) |
32 | 32 | ||
33 | // Address represents a server the client connects to. | 33 | // Address represents a server the client connects to. |
34 | // This is the EXPERIMENTAL API and may be changed or extended in the future. | 34 | // |
35 | // Deprecated: please use package balancer. | ||
35 | type Address struct { | 36 | type Address struct { |
36 | // Addr is the server address on which a connection will be established. | 37 | // Addr is the server address on which a connection will be established. |
37 | Addr string | 38 | Addr string |
@@ -41,6 +42,8 @@ type Address struct { | |||
41 | } | 42 | } |
42 | 43 | ||
43 | // BalancerConfig specifies the configurations for Balancer. | 44 | // BalancerConfig specifies the configurations for Balancer. |
45 | // | ||
46 | // Deprecated: please use package balancer. | ||
44 | type BalancerConfig struct { | 47 | type BalancerConfig struct { |
45 | // DialCreds is the transport credential the Balancer implementation can | 48 | // DialCreds is the transport credential the Balancer implementation can |
46 | // use to dial to a remote load balancer server. The Balancer implementations | 49 | // use to dial to a remote load balancer server. The Balancer implementations |
@@ -53,7 +56,8 @@ type BalancerConfig struct { | |||
53 | } | 56 | } |
54 | 57 | ||
55 | // BalancerGetOptions configures a Get call. | 58 | // BalancerGetOptions configures a Get call. |
56 | // This is the EXPERIMENTAL API and may be changed or extended in the future. | 59 | // |
60 | // Deprecated: please use package balancer. | ||
57 | type BalancerGetOptions struct { | 61 | type BalancerGetOptions struct { |
58 | // BlockingWait specifies whether Get should block when there is no | 62 | // BlockingWait specifies whether Get should block when there is no |
59 | // connected address. | 63 | // connected address. |
@@ -61,7 +65,8 @@ type BalancerGetOptions struct { | |||
61 | } | 65 | } |
62 | 66 | ||
63 | // Balancer chooses network addresses for RPCs. | 67 | // Balancer chooses network addresses for RPCs. |
64 | // This is the EXPERIMENTAL API and may be changed or extended in the future. | 68 | // |
69 | // Deprecated: please use package balancer. | ||
65 | type Balancer interface { | 70 | type Balancer interface { |
66 | // Start does the initialization work to bootstrap a Balancer. For example, | 71 | // Start does the initialization work to bootstrap a Balancer. For example, |
67 | // this function may start the name resolution and watch the updates. It will | 72 | // this function may start the name resolution and watch the updates. It will |
@@ -112,28 +117,10 @@ type Balancer interface { | |||
112 | Close() error | 117 | Close() error |
113 | } | 118 | } |
114 | 119 | ||
115 | // downErr implements net.Error. It is constructed by gRPC internals and passed to the down | ||
116 | // call of Balancer. | ||
117 | type downErr struct { | ||
118 | timeout bool | ||
119 | temporary bool | ||
120 | desc string | ||
121 | } | ||
122 | |||
123 | func (e downErr) Error() string { return e.desc } | ||
124 | func (e downErr) Timeout() bool { return e.timeout } | ||
125 | func (e downErr) Temporary() bool { return e.temporary } | ||
126 | |||
127 | func downErrorf(timeout, temporary bool, format string, a ...interface{}) downErr { | ||
128 | return downErr{ | ||
129 | timeout: timeout, | ||
130 | temporary: temporary, | ||
131 | desc: fmt.Sprintf(format, a...), | ||
132 | } | ||
133 | } | ||
134 | |||
135 | // RoundRobin returns a Balancer that selects addresses round-robin. It uses r to watch | 120 | // RoundRobin returns a Balancer that selects addresses round-robin. It uses r to watch |
136 | // the name resolution updates and updates the addresses available correspondingly. | 121 | // the name resolution updates and updates the addresses available correspondingly. |
122 | // | ||
123 | // Deprecated: please use package balancer/roundrobin. | ||
137 | func RoundRobin(r naming.Resolver) Balancer { | 124 | func RoundRobin(r naming.Resolver) Balancer { |
138 | return &roundRobin{r: r} | 125 | return &roundRobin{r: r} |
139 | } | 126 | } |
@@ -310,7 +297,7 @@ func (rr *roundRobin) Get(ctx context.Context, opts BalancerGetOptions) (addr Ad | |||
310 | if !opts.BlockingWait { | 297 | if !opts.BlockingWait { |
311 | if len(rr.addrs) == 0 { | 298 | if len(rr.addrs) == 0 { |
312 | rr.mu.Unlock() | 299 | rr.mu.Unlock() |
313 | err = Errorf(codes.Unavailable, "there is no address available") | 300 | err = status.Errorf(codes.Unavailable, "there is no address available") |
314 | return | 301 | return |
315 | } | 302 | } |
316 | // Returns the next addr on rr.addrs for failfast RPCs. | 303 | // Returns the next addr on rr.addrs for failfast RPCs. |
@@ -395,3 +382,10 @@ func (rr *roundRobin) Close() error { | |||
395 | } | 382 | } |
396 | return nil | 383 | return nil |
397 | } | 384 | } |
385 | |||
386 | // pickFirst is used to test multi-addresses in one addrConn in which all addresses share the same addrConn. | ||
387 | // It is a wrapper around roundRobin balancer. The logic of all methods works fine because balancer.Get() | ||
388 | // returns the only address Up by resetTransport(). | ||
389 | type pickFirst struct { | ||
390 | *roundRobin | ||
391 | } | ||