Merge pull request #10710 from zexi/fix/decouple-region-etcd

fix(region): decouple region and etcd service
This commit is contained in:
Zexi Li
2021-04-14 16:58:42 +08:00
committed by GitHub
2 changed files with 14 additions and 9 deletions
-2
View File
@@ -140,8 +140,6 @@ type ComputeOptions struct {
EnableHostHealthCheck bool `help:"enable host health check" default:"true"`
HostHealthTimeout int `help:"second of wait host reconnect" default:"60"`
FetchEtcdServiceInfoAndUseEtcdLock bool `default:"false" help:"fetch etcd service info and use etcd lock"`
GuestTemplateCheckInterval int `help:"interval between two consecutive inspections of Guest Template in hour unit" default:"12"`
ScheduledTaskQueueSize int `help:"the maximum number of scheduled tasks that are being executed simultaneously" default:"100"`
+14 -7
View File
@@ -70,11 +70,9 @@ func StartService() {
log.Fatalf("unable to init esxi configs: %v", err)
}
if opts.FetchEtcdServiceInfoAndUseEtcdLock {
err := initEtcdLockOpts(opts)
if err != nil {
log.Fatalln(err)
}
// always try to init etcd options
if err := initEtcdLockOpts(opts); err != nil {
log.Errorf("try to init etcd options error: %v", err)
}
app := app_common.InitApp(baseOpts, true)
@@ -179,13 +177,23 @@ func initDefaultEtcdClient(opts *common_options.DBOptions) error {
if err != nil {
return err
}
onKeepaliveFailure := func() {
cli := etcd.Default()
if opts.LockmanMethod == common_options.LockMethodEtcd {
log.Fatalf("etcd keepalive failed and exit when lockman_method is %s", common_options.LockMethodEtcd)
}
if err := cli.RestartSession(); err != nil {
log.Errorf("restart default session error: %v", err)
return
}
}
err = etcd.InitDefaultEtcdClient(&etcd.SEtcdOptions{
EtcdEndpoint: opts.EtcdEndpoints,
EtcdUsername: opts.EtcdUsername,
EtcdPassword: opts.EtcdPassword,
EtcdEnabldSsl: opts.EtcdUseTLS,
TLSConfig: tlsConfig,
}, nil)
}, onKeepaliveFailure)
if err != nil {
return errors.Wrap(err, "init default etcd client")
}
@@ -202,7 +210,6 @@ func initEtcdLockOpts(opts *options.ComputeOptions) error {
}
if etcdEndpoint != nil {
opts.EtcdEndpoints = []string{etcdEndpoint.Url}
opts.LockmanMethod = common_options.LockMethodEtcd
if len(etcdEndpoint.CertId) > 0 {
dir, err := ioutil.TempDir("", "etcd-cluster-tls")
if err != nil {