Skip to content

Commit

Permalink
fix: zk
Browse files Browse the repository at this point in the history
  • Loading branch information
wangchuxiao-dev committed Jul 31, 2023
1 parent 5a9a890 commit f924f97
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
23 changes: 15 additions & 8 deletions discoveryregistry/zookeeper/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,22 @@ func (s *ZkClient) watch(ctx context.Context) {
log.ZDebug(context.Background(), "zk recv event", "event", event)
switch event.Type {
case zk.EventSession:
if event.State == zk.StateHasSession && s.isRegistered {
s.logger.Printf("zk session event stateHasSession: %+v, client prepare to create new temp node", event)
node, err := s.CreateTempNode(s.rpcRegisterName, s.rpcRegisterAddr)
if err != nil {
s.logger.Printf("zk session event stateHasSession: %+v, create temp node error: %v", event, err)
} else {
s.node = node
switch event.State {
case zk.StateHasSession:
if s.isRegistered && !s.isStateDisconnected {
s.logger.Printf("zk session event stateHasSession: %+v, client prepare to create new temp node", event)
node, err := s.CreateTempNode(s.rpcRegisterName, s.rpcRegisterAddr)
if err != nil {
s.logger.Printf("zk session event stateHasSession: %+v, create temp node error: %v", event, err)
} else {
s.node = node
}
}
} else {
case zk.StateDisconnected:
s.isStateDisconnected = true
case zk.StateConnected:
s.isStateDisconnected = false
default:
s.logger.Printf("zk session event: %+v", event)
}
case zk.EventNodeChildrenChanged:
Expand Down
10 changes: 5 additions & 5 deletions discoveryregistry/zookeeper/zk.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ type ZkClient struct {
lock sync.Locker
options []grpc.DialOption

resolvers map[string]*Resolver
localConns map[string][]grpc.ClientConnInterface
cancel context.CancelFunc

balancerName string
resolvers map[string]*Resolver
localConns map[string][]grpc.ClientConnInterface
cancel context.CancelFunc
isStateDisconnected bool
balancerName string

logger Logger
}
Expand Down

0 comments on commit f924f97

Please sign in to comment.