From 3ada4f609f5666f0a047b58590f954000a06d4bd Mon Sep 17 00:00:00 2001 From: shen Date: Mon, 7 Sep 2020 09:37:08 +0800 Subject: [PATCH 1/2] etcdv3 lease --- registry/etcdv3/registry.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/registry/etcdv3/registry.go b/registry/etcdv3/registry.go index 2fec8eaad2..9cbc494560 100644 --- a/registry/etcdv3/registry.go +++ b/registry/etcdv3/registry.go @@ -112,8 +112,9 @@ func (r *etcdV3Registry) InitListeners() { } // DoRegister actually do the register job in the registry center of etcd +// for lease func (r *etcdV3Registry) DoRegister(root string, node string) error { - return r.client.Create(path.Join(root, node), "") + return r.client.RegisterTemp(path.Join(root, node), "") } // nolint From 0a9aa6d27da748957d4fbcff1d54f4b03997bc26 Mon Sep 17 00:00:00 2001 From: zhangshen023 <1292369127@qq.com> Date: Thu, 10 Sep 2020 21:25:44 +0800 Subject: [PATCH 2/2] modify etcd lease time --- remoting/etcdv3/client.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/remoting/etcdv3/client.go b/remoting/etcdv3/client.go index 4e7436e445..ebd454242d 100644 --- a/remoting/etcdv3/client.go +++ b/remoting/etcdv3/client.go @@ -408,7 +408,8 @@ func (c *Client) keepAliveKV(k string, v string) error { return ErrNilETCDV3Client } - lease, err := c.rawClient.Grant(c.ctx, int64(time.Second.Seconds())) + // make lease time longer, since 1 second is too short + lease, err := c.rawClient.Grant(c.ctx, int64(30*time.Second.Seconds())) if err != nil { return perrors.WithMessage(err, "grant lease") }