From 8dbc2213f1a25b71c95632f67e1a13ee4de0bc94 Mon Sep 17 00:00:00 2001 From: Zexi Li Date: Tue, 13 Apr 2021 18:32:08 +0800 Subject: [PATCH] fix(region): decouple region and etcd service --- pkg/compute/options/options.go | 2 -- pkg/compute/service/service.go | 21 ++++++++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/pkg/compute/options/options.go b/pkg/compute/options/options.go index bc5e7a8339..ce77bf07dc 100644 --- a/pkg/compute/options/options.go +++ b/pkg/compute/options/options.go @@ -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"` diff --git a/pkg/compute/service/service.go b/pkg/compute/service/service.go index 2be257dda2..e3c11d580c 100644 --- a/pkg/compute/service/service.go +++ b/pkg/compute/service/service.go @@ -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 {