mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
etcd-runner: add lease ttl as a flag and fatal when err in lease-runner.
This commit is contained in:
parent
d57ad8ec8d
commit
72fb756af3
@ -22,11 +22,16 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/coreos/etcd/clientv3"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
)
|
||||
|
||||
var (
|
||||
leaseTTL int64
|
||||
)
|
||||
|
||||
// NewLeaseRenewerCommand returns the cobra command for "lease-renewer runner".
|
||||
func NewLeaseRenewerCommand() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
@ -34,6 +39,7 @@ func NewLeaseRenewerCommand() *cobra.Command {
|
||||
Short: "Performs lease renew operation",
|
||||
Run: runLeaseRenewerFunc,
|
||||
}
|
||||
cmd.Flags().Int64Var(&leaseTTL, "ttl", 5, "lease's ttl")
|
||||
return cmd
|
||||
}
|
||||
|
||||
@ -54,7 +60,7 @@ func runLeaseRenewerFunc(cmd *cobra.Command, args []string) {
|
||||
err error
|
||||
)
|
||||
for {
|
||||
l, err = c.Lease.Grant(ctx, 5)
|
||||
l, err = c.Lease.Grant(ctx, leaseTTL)
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
@ -65,14 +71,14 @@ func runLeaseRenewerFunc(cmd *cobra.Command, args []string) {
|
||||
lk, err = c.Lease.KeepAliveOnce(ctx, l.ID)
|
||||
if grpc.Code(err) == codes.NotFound {
|
||||
if time.Since(expire) < 0 {
|
||||
log.Printf("bad renew! exceeded: %v", time.Since(expire))
|
||||
log.Fatalf("bad renew! exceeded: %v", time.Since(expire))
|
||||
for {
|
||||
lk, err = c.Lease.KeepAliveOnce(ctx, l.ID)
|
||||
fmt.Println(lk, err)
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
}
|
||||
log.Printf("lost lease %d, expire: %v\n", l.ID, expire)
|
||||
log.Fatalf("lost lease %d, expire: %v\n", l.ID, expire)
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user