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
212c692228
@ -1,4 +1,4 @@
|
|||||||
package openKeeper
|
package zookeeper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/go-zookeeper/zk"
|
"github.com/go-zookeeper/zk"
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package openKeeper
|
package zookeeper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -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 conns[0], nil
|
return s.getConnBalance(conns), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
|
23
pkg/discoveryregistry/zookeeper/load_balancing.go
Normal file
23
pkg/discoveryregistry/zookeeper/load_balancing.go
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package zookeeper
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
type RoundRobin struct {
|
||||||
|
index int
|
||||||
|
lock sync.Mutex
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *RoundRobin) getConnBalance(conns []*grpc.ClientConn) (conn *grpc.ClientConn) {
|
||||||
|
r.lock.Lock()
|
||||||
|
defer r.lock.Unlock()
|
||||||
|
if r.index < len(conns)-1 {
|
||||||
|
r.index++
|
||||||
|
} else {
|
||||||
|
r.index = 0
|
||||||
|
}
|
||||||
|
return conns[r.index]
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package openKeeper
|
package zookeeper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/go-zookeeper/zk"
|
"github.com/go-zookeeper/zk"
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package openKeeper
|
package zookeeper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package openKeeper
|
package zookeeper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -38,6 +38,7 @@ type ZkClient struct {
|
|||||||
resolvers map[string]*Resolver
|
resolvers map[string]*Resolver
|
||||||
localConns map[string][]resolver.Address
|
localConns map[string][]resolver.Address
|
||||||
balancerName string
|
balancerName string
|
||||||
|
RoundRobin
|
||||||
}
|
}
|
||||||
|
|
||||||
type ZkOption func(*ZkClient)
|
type ZkOption func(*ZkClient)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user