tianxiaoliang commented on a change in pull request #1205:
URL: 
https://github.com/apache/servicecomb-service-center/pull/1205#discussion_r780086179



##########
File path: client/set.go
##########
@@ -19,13 +28,35 @@ type Set struct {
 }
 
 // NewSetForConfig dial grpc connection and create all grpc clients
-func NewSetForConfig(c SetConfig) (*Set, error) {
-       conn, err := grpc.Dial(c.Addr, grpc.WithInsecure())
+func NewSetForConfig(c SetConfig) (*grpc.ClientConn, *Set, error) {
+       if len(c.Addr) <= 0 {
+               return nil, nil, ErrAddrEmpty
+       }
+
+       var conn *grpc.ClientConn
+       var err error
+
+       if len(c.Addr) <= 1 {
+               conn, err = grpc.Dial(c.Addr[0], grpc.WithInsecure())
+       } else {
+               addr := make([]resolver.Address, 0, len(c.Addr))

Review comment:
       不必维护分支,都是resolver,之所以可以代码合一是因为用例就一个:集群

##########
File path: client/set.go
##########
@@ -19,13 +28,35 @@ type Set struct {
 }
 
 // NewSetForConfig dial grpc connection and create all grpc clients
-func NewSetForConfig(c SetConfig) (*Set, error) {
-       conn, err := grpc.Dial(c.Addr, grpc.WithInsecure())
+func NewSetForConfig(c SetConfig) (*grpc.ClientConn, *Set, error) {
+       if len(c.Addr) <= 0 {
+               return nil, nil, ErrAddrEmpty
+       }
+
+       var conn *grpc.ClientConn
+       var err error
+
+       if len(c.Addr) <= 1 {
+               conn, err = grpc.Dial(c.Addr[0], grpc.WithInsecure())
+       } else {
+               addr := make([]resolver.Address, 0, len(c.Addr))

Review comment:
       不必维护分支,都是resolver,之所以可以代码合一是因为用例就一个:拨集群

##########
File path: client/set.go
##########
@@ -19,13 +28,35 @@ type Set struct {
 }
 
 // NewSetForConfig dial grpc connection and create all grpc clients
-func NewSetForConfig(c SetConfig) (*Set, error) {
-       conn, err := grpc.Dial(c.Addr, grpc.WithInsecure())
+func NewSetForConfig(c SetConfig) (*grpc.ClientConn, *Set, error) {
+       if len(c.Addr) <= 0 {
+               return nil, nil, ErrAddrEmpty
+       }
+
+       var conn *grpc.ClientConn
+       var err error
+
+       if len(c.Addr) <= 1 {
+               conn, err = grpc.Dial(c.Addr[0], grpc.WithInsecure())
+       } else {
+               addr := make([]resolver.Address, 0, len(c.Addr))
+               for _, a := range c.Addr {
+                       addr = append(addr, resolver.Address{Addr: a})
+               }
+               r := manual.NewBuilderWithScheme(c.Scheme)
+               r.InitialState(resolver.State{Addresses: addr})
+               conn, err = grpc.Dial(r.Scheme()+":///", grpc.WithInsecure(), 
grpc.WithResolvers(r))

Review comment:
       为什么有3个/  给下标准的依据

##########
File path: client/set.go
##########
@@ -1,16 +1,25 @@
 package client
 
 import (
+       "errors"
        "fmt"
 
        v1sync "github.com/apache/servicecomb-service-center/api/sync/v1"
        "github.com/apache/servicecomb-service-center/pkg/log"
        "google.golang.org/grpc"
+       "google.golang.org/grpc/resolver"
+       "google.golang.org/grpc/resolver/manual"
+)
+
+var (
+       ErrAddrEmpty = errors.New("addr is empty")
+       ErrConnNil   = errors.New("conn is nil")
 )
 
 // SetConfig is client configs
 type SetConfig struct {
-       Addr string
+       Addr   []string

Review comment:
       复数,还是全拼吧

##########
File path: client/set.go
##########
@@ -1,16 +1,25 @@
 package client
 
 import (
+       "errors"
        "fmt"
 
        v1sync "github.com/apache/servicecomb-service-center/api/sync/v1"
        "github.com/apache/servicecomb-service-center/pkg/log"
        "google.golang.org/grpc"
+       "google.golang.org/grpc/resolver"
+       "google.golang.org/grpc/resolver/manual"
+)
+
+var (
+       ErrAddrEmpty = errors.New("addr is empty")
+       ErrConnNil   = errors.New("conn is nil")
 )
 
 // SetConfig is client configs
 type SetConfig struct {
-       Addr string
+       Addr   []string
+       Scheme string

Review comment:
       如何理解schema字段的设计,枚举值有哪些

##########
File path: etc/conf/app.yaml
##########
@@ -144,6 +144,10 @@ registry:
     # the allowable minimum value of instance heartbeat interval
     # if interval < minInterval, instance TTL still set with minInterval
     minInterval: 5s
+    datacenter:

Review comment:
       这数据是否和sync路径下的配置冗余了

##########
File path: etc/conf/app.yaml
##########
@@ -144,6 +144,10 @@ registry:
     # the allowable minimum value of instance heartbeat interval
     # if interval < minInterval, instance TTL still set with minInterval
     minInterval: 5s
+    datacenter:

Review comment:
       确保这些配置项和sync下的一模一样




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to