mirror of https://github.com/grpc/grpc-go.git
Merge pull request #752 from tamird/dupe-balancer
remove duplicate balancer field
This commit is contained in:
commit
daeb9cc0f2
|
@ -218,27 +218,26 @@ func Dial(target string, opts ...DialOption) (*ClientConn, error) {
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
opt(&cc.dopts)
|
opt(&cc.dopts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set defaults.
|
||||||
if cc.dopts.codec == nil {
|
if cc.dopts.codec == nil {
|
||||||
// Set the default codec.
|
|
||||||
cc.dopts.codec = protoCodec{}
|
cc.dopts.codec = protoCodec{}
|
||||||
}
|
}
|
||||||
|
|
||||||
if cc.dopts.bs == nil {
|
if cc.dopts.bs == nil {
|
||||||
cc.dopts.bs = DefaultBackoffConfig
|
cc.dopts.bs = DefaultBackoffConfig
|
||||||
}
|
}
|
||||||
|
if cc.dopts.balancer == nil {
|
||||||
cc.balancer = cc.dopts.balancer
|
cc.dopts.balancer = RoundRobin(nil)
|
||||||
if cc.balancer == nil {
|
|
||||||
cc.balancer = RoundRobin(nil)
|
|
||||||
}
|
}
|
||||||
if err := cc.balancer.Start(target); err != nil {
|
|
||||||
|
if err := cc.dopts.balancer.Start(target); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
ok bool
|
ok bool
|
||||||
addrs []Address
|
addrs []Address
|
||||||
)
|
)
|
||||||
ch := cc.balancer.Notify()
|
ch := cc.dopts.balancer.Notify()
|
||||||
if ch == nil {
|
if ch == nil {
|
||||||
// There is no name resolver installed.
|
// There is no name resolver installed.
|
||||||
addrs = append(addrs, Address{Addr: target})
|
addrs = append(addrs, Address{Addr: target})
|
||||||
|
@ -319,7 +318,6 @@ func (s ConnectivityState) String() string {
|
||||||
// ClientConn represents a client connection to an RPC server.
|
// ClientConn represents a client connection to an RPC server.
|
||||||
type ClientConn struct {
|
type ClientConn struct {
|
||||||
target string
|
target string
|
||||||
balancer Balancer
|
|
||||||
authority string
|
authority string
|
||||||
dopts dialOptions
|
dopts dialOptions
|
||||||
|
|
||||||
|
@ -328,7 +326,7 @@ type ClientConn struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cc *ClientConn) lbWatcher() {
|
func (cc *ClientConn) lbWatcher() {
|
||||||
for addrs := range cc.balancer.Notify() {
|
for addrs := range cc.dopts.balancer.Notify() {
|
||||||
var (
|
var (
|
||||||
add []Address // Addresses need to setup connections.
|
add []Address // Addresses need to setup connections.
|
||||||
del []*addrConn // Connections need to tear down.
|
del []*addrConn // Connections need to tear down.
|
||||||
|
@ -425,7 +423,7 @@ func (cc *ClientConn) newAddrConn(addr Address, skipWait bool) error {
|
||||||
|
|
||||||
func (cc *ClientConn) getTransport(ctx context.Context, opts BalancerGetOptions) (transport.ClientTransport, func(), error) {
|
func (cc *ClientConn) getTransport(ctx context.Context, opts BalancerGetOptions) (transport.ClientTransport, func(), error) {
|
||||||
// TODO(zhaoq): Implement fail-fast logic.
|
// TODO(zhaoq): Implement fail-fast logic.
|
||||||
addr, put, err := cc.balancer.Get(ctx, opts)
|
addr, put, err := cc.dopts.balancer.Get(ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
@ -462,7 +460,7 @@ func (cc *ClientConn) Close() error {
|
||||||
conns := cc.conns
|
conns := cc.conns
|
||||||
cc.conns = nil
|
cc.conns = nil
|
||||||
cc.mu.Unlock()
|
cc.mu.Unlock()
|
||||||
cc.balancer.Close()
|
cc.dopts.balancer.Close()
|
||||||
for _, ac := range conns {
|
for _, ac := range conns {
|
||||||
ac.tearDown(ErrClientConnClosing)
|
ac.tearDown(ErrClientConnClosing)
|
||||||
}
|
}
|
||||||
|
@ -610,7 +608,7 @@ func (ac *addrConn) resetTransport(closeTransport bool) error {
|
||||||
close(ac.ready)
|
close(ac.ready)
|
||||||
ac.ready = nil
|
ac.ready = nil
|
||||||
}
|
}
|
||||||
ac.down = ac.cc.balancer.Up(ac.addr)
|
ac.down = ac.cc.dopts.balancer.Up(ac.addr)
|
||||||
ac.mu.Unlock()
|
ac.mu.Unlock()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue