zoukankan      html  css  js  c++  java
  • etcd租约机制

    新建租约

    新建一个过期时间为120s的租约

    # etcdctl lease grant 120
    lease 018f6d7bb11aba0d granted with TTL(120s)

    查看新建的租约信息

    # etcdctl lease list
    found 1 leases
    018f6d7bb11aba0d

      # etcdctl lease timetolive 018f6d7bb11aba0d --keys
      lease 018f6d7bb11aba0d granted with TTL(120s), remaining(99s), attached keys([])

    新建key,并为该key指定租约

    # etcdctl put name alice --lease="018f6d7bb11aba0d"
    OK
    # etcdctl put name1 tina --lease="018f6d7bb11aba0d"
    OK

    # etcdctl lease timetolive 018f6d7bb11aba0d --keys
    lease 018f6d7bb11aba0d granted with TTL(120s), remaining(60s), attached keys([name name1])

      # etcdctl get --prefix ""
      name
      alice
      name1
      tina

     

    等到租约过期后,再次查看租约已经过期,对应的key也已经被自动删除

    # etcdctl lease timetolive 018f6d7bb11aba0d --keys
    lease 018f6d7bb11aba0d already expired

     续约

    新建租约并赋予key值

    # etcdctl lease grant 30
    lease 018f6d7bd032c117 granted with TTL(30s)
    # etcdctl put name alice --lease=018f6d7bd032c117
    OK

     在租约即将过期时进行续约,命令不会自动结束,会一直显示该窗口

    # etcdctl lease keep-alive 018f6d7bd032c117
    lease 018f6d7bd032c117 keepalived with TTL(30)
    lease 018f6d7bd032c117 keepalived with TTL(30)
    lease 018f6d7bd032c117 keepalived with TTL(30)
    ......

     重新打开一个窗口,查看该租约续约信息,可以看到该租约会自动续约,相应key值也不会被删除

    # etcdctl lease timetolive 018f6d7bd032c117 --keys
    lease 018f6d7bd032c117 granted with TTL(30s), remaining(23s), attached keys([name])
    # etcdctl lease timetolive 018f6d7bd032c117 --keys
    lease 018f6d7bd032c117 granted with TTL(30s), remaining(22s), attached keys([name])
    # etcdctl lease timetolive 018f6d7bd032c117 --keys
    lease 018f6d7bd032c117 granted with TTL(30s), remaining(21s), attached keys([name])
    # etcdctl lease timetolive 018f6d7bd032c117 --keys
    lease 018f6d7bd032c117 granted with TTL(30s), remaining(20s), attached keys([name])
    # etcdctl lease timetolive 018f6d7bd032c117 --keys
    lease 018f6d7bd032c117 granted with TTL(30s), remaining(29s), attached keys([name])
    # etcdctl lease timetolive 018f6d7bd032c117 --keys
    lease 018f6d7bd032c117 granted with TTL(30s), remaining(28s), attached keys([name])
    # etcdctl lease timetolive 018f6d7bd032c117 --keys
    lease 018f6d7bd032c117 granted with TTL(30s), remaining(27s), attached keys([name])
    # etcdctl lease timetolive 018f6d7bd032c117 --keys
    lease 018f6d7bd032c117 granted with TTL(30s), remaining(27s), attached keys([name])
    # etcdctl lease timetolive 018f6d7bd032c117 --keys
    lease 018f6d7bd032c117 granted with TTL(30s), remaining(26s), attached keys([name])
    # etcdctl lease timetolive 018f6d7bd032c117 --keys
    lease 018f6d7bd032c117 granted with TTL(30s), remaining(25s), attached keys([name])
    # etcdctl lease timetolive 018f6d7bd032c117 --keys
    lease 018f6d7bd032c117 granted with TTL(30s), remaining(25s), attached keys([name])
    # etcdctl lease timetolive 018f6d7bd032c117 --keys
    lease 018f6d7bd032c117 granted with TTL(30s), remaining(24s), attached keys([name])
    # etcdctl lease timetolive 018f6d7bd032c117 --keys
    lease 018f6d7bd032c117 granted with TTL(30s), remaining(23s), attached keys([name])
    # etcdctl lease timetolive 018f6d7bd032c117 --keys
    lease 018f6d7bd032c117 granted with TTL(30s), remaining(22s), attached keys([name])
    # etcdctl lease timetolive 018f6d7bd032c117 --keys
    lease 018f6d7bd032c117 granted with TTL(30s), remaining(22s), attached keys([name])
    # etcdctl lease timetolive 018f6d7bd032c117 --keys
    lease 018f6d7bd032c117 granted with TTL(30s), remaining(20s), attached keys([name])
    # etcdctl lease timetolive 018f6d7bd032c117 --keys
    lease 018f6d7bd032c117 granted with TTL(30s), remaining(29s), attached keys([name])

    回收租约 

    回收租约会自动删除与该租约关联的key

    # etcdctl lease revoke 018f6d7bd032c117
    lease 018f6d7bd032c117 revoked
    # etcdctl lease timetolive 018f6d7bd032c117 --keys
    lease 018f6d7bd032c117 already expired
    # etcdctl get name
  • 相关阅读:
    仅坚持了9天:京东今日宣布暂停火车票代购业务
    Highcharts JS——制作图表的纯js类库
    eclipse插件——php工具集成
    如何新增histats计数器到自己的 blog
    C#写入文本txt
    我怎么感觉js快无敌了~
    马云卸任演讲全文
    添加好玩的honehoneclock到自己的blog
    C#获取日期的年月日时分秒
    js闭包
  • 原文地址:https://www.cnblogs.com/ilifeilong/p/11607738.html
Copyright © 2011-2022 走看看