mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
conn
This commit is contained in:
parent
7051c06c09
commit
a3055f53af
@ -107,7 +107,7 @@ func (s *ZkClient) GetConn(ctx context.Context, serviceName string, opts ...grpc
|
||||
if len(conns) == 0 {
|
||||
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) {
|
||||
|
@ -11,7 +11,10 @@ type RoundRobin struct {
|
||||
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()
|
||||
defer r.lock.Unlock()
|
||||
if r.index < len(conns)-1 {
|
||||
@ -19,5 +22,5 @@ func (r *RoundRobin) getConnBalance(conns []*grpc.ClientConn) (conn *grpc.Client
|
||||
} else {
|
||||
r.index = 0
|
||||
}
|
||||
return conns[r.index]
|
||||
return conns[r.index], nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user