enhance: Add `WithBlock` option for etcd client creation (#32641)

Related to #32598

Use `WithBlock` may fail fast when create etcd client to some invalid
etcd endpoints and make it easier to check problem.

Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
pull/32664/head
congqixia 2024-04-28 14:45:25 +08:00 committed by GitHub
parent 2ab57ca10c
commit 967cfb3133
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 0 deletions

View File

@ -28,6 +28,7 @@ import (
clientv3 "go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/server/v3/embed"
"go.uber.org/zap"
"google.golang.org/grpc"
"github.com/milvus-io/milvus/pkg/log"
)
@ -64,6 +65,9 @@ func GetRemoteEtcdClient(endpoints []string) (*clientv3.Client, error) {
return clientv3.New(clientv3.Config{
Endpoints: endpoints,
DialTimeout: 5 * time.Second,
DialOptions: []grpc.DialOption{
grpc.WithBlock(),
},
})
}
@ -73,6 +77,9 @@ func GetRemoteEtcdClientWithAuth(endpoints []string, userName, password string)
DialTimeout: 5 * time.Second,
Username: userName,
Password: password,
DialOptions: []grpc.DialOption{
grpc.WithBlock(),
},
})
}
@ -119,6 +126,8 @@ func GetRemoteEtcdSSLClientWithCfg(endpoints []string, certFile string, keyFile
return nil, errors.Errorf("unknown TLS version,%s", minVersion)
}
cfg.DialOptions = append(cfg.DialOptions, grpc.WithBlock())
return clientv3.New(cfg)
}