pull/455/head
wenxu12345 3 years ago committed by Xinwei Xiong(cubxxw-openim)
parent 41d94e2f40
commit e1ee0500ea

@ -1,6 +1,7 @@
package getcdv3 package getcdv3
import ( import (
"Open_IM/pkg/common/log"
"context" "context"
"fmt" "fmt"
"strings" "strings"
@ -48,6 +49,8 @@ func NewResolver(schema, etcdAddr, serviceName string) (*Resolver, error) {
conn, err := grpc.DialContext(ctx, GetPrefix(schema, serviceName), conn, err := grpc.DialContext(ctx, GetPrefix(schema, serviceName),
grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"LoadBalancingPolicy": "%s"}`, roundrobin.Name)), grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"LoadBalancingPolicy": "%s"}`, roundrobin.Name)),
grpc.WithInsecure()) grpc.WithInsecure())
log.Debug("", "etcd key ", GetPrefix(schema, serviceName), "value ", *r.grpcClientConn)
//conn, err := grpc.Dial( //conn, err := grpc.Dial(
// GetPrefix(schema, serviceName), // GetPrefix(schema, serviceName),
// grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"LoadBalancingPolicy": "%s"}`, roundrobin.Name)), // grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"LoadBalancingPolicy": "%s"}`, roundrobin.Name)),
@ -71,6 +74,7 @@ func GetConn(schema, etcdaddr, serviceName string) *grpc.ClientConn {
r, ok := nameResolver[schema+serviceName] r, ok := nameResolver[schema+serviceName]
rwNameResolverMutex.RUnlock() rwNameResolverMutex.RUnlock()
if ok { if ok {
log.Debug("", "etcd key ", schema+serviceName, "value ", *r.grpcClientConn, *r)
return r.grpcClientConn return r.grpcClientConn
} }
@ -78,15 +82,18 @@ func GetConn(schema, etcdaddr, serviceName string) *grpc.ClientConn {
r, ok = nameResolver[schema+serviceName] r, ok = nameResolver[schema+serviceName]
if ok { if ok {
rwNameResolverMutex.Unlock() rwNameResolverMutex.Unlock()
log.Debug("", "etcd key ", schema+serviceName, "value ", *r.grpcClientConn, *r)
return r.grpcClientConn return r.grpcClientConn
} }
r, err := NewResolver(schema, etcdaddr, serviceName) r, err := NewResolver(schema, etcdaddr, serviceName)
if err != nil { if err != nil {
log.Error("", "etcd failed ", schema, etcdaddr, serviceName)
rwNameResolverMutex.Unlock() rwNameResolverMutex.Unlock()
return nil return nil
} }
log.Debug("", "etcd key ", schema+serviceName, "value ", *r.grpcClientConn, *r)
nameResolver[schema+serviceName] = r nameResolver[schema+serviceName] = r
rwNameResolverMutex.Unlock() rwNameResolverMutex.Unlock()
return r.grpcClientConn return r.grpcClientConn

Loading…
Cancel
Save