• 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
  • 相关阅读:
    Markdown实用教程
    Python三次登陆
    Python猜年龄
    Pycharm用鼠标滚轮控制字体大小
    检测浏览器是否存在某个css或者js的api
    隐式绑定和显式绑定实现一个apply
    promise顺序执行的多种方案
    数据结构栈的定义和使用
    数据以及数据结构是数据处理的起点
    Vue的高阶组件(HOC)使用举例
  • 原文地址:https://www.cnblogs.com/ilifeilong/p/11607738.html
Copyright © 2020-2023  润新知