mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-23 18:00:32 +08:00
Merge remote-tracking branch 'origin/errcode' into errcode
This commit is contained in:
commit
f6921161a0
@ -107,7 +107,7 @@ func (s *ZkClient) GetConn(ctx context.Context, serviceName string, opts ...grpc
|
|||||||
if len(conns) == 0 {
|
if len(conns) == 0 {
|
||||||
return nil, ErrConnIsNil
|
return nil, ErrConnIsNil
|
||||||
}
|
}
|
||||||
return s.getConnBalance(conns), nil
|
return s.getConnBalance(conns)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ZkClient) GetFirstConn(ctx context.Context, serviceName string, opts ...grpc.DialOption) (*grpc.ClientConn, error) {
|
func (s *ZkClient) GetFirstConn(ctx context.Context, serviceName string, opts ...grpc.DialOption) (*grpc.ClientConn, error) {
|
||||||
|
@ -11,7 +11,10 @@ type RoundRobin struct {
|
|||||||
lock sync.Mutex
|
lock sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RoundRobin) getConnBalance(conns []*grpc.ClientConn) (conn *grpc.ClientConn) {
|
func (r *RoundRobin) getConnBalance(conns []*grpc.ClientConn) (conn *grpc.ClientConn, err error) {
|
||||||
|
if len(conns) == 0 {
|
||||||
|
return nil, ErrConnIsNil
|
||||||
|
}
|
||||||
r.lock.Lock()
|
r.lock.Lock()
|
||||||
defer r.lock.Unlock()
|
defer r.lock.Unlock()
|
||||||
if r.index < len(conns)-1 {
|
if r.index < len(conns)-1 {
|
||||||
@ -19,5 +22,5 @@ func (r *RoundRobin) getConnBalance(conns []*grpc.ClientConn) (conn *grpc.Client
|
|||||||
} else {
|
} else {
|
||||||
r.index = 0
|
r.index = 0
|
||||||
}
|
}
|
||||||
return conns[r.index]
|
return conns[r.index], nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user