新建租约

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

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

查看新建的租约信息

# etcdctl lease list
found 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
lease 018f6d7bd032c117 granted with TTL(30s)
# etcdctl put name alice --lease=018f6d7bd032c117
OK

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

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

重新打开一个窗口,查看该租约续约信息,可以看到该租约会自动续约,相应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

etcd租约机制的更多相关文章

  1. ETCD核心机制解析

    ETCD整体机制 etcd 是一个分布式的.可靠的 key-value 存储系统,它适用于存储分布式系统中的关键数据. etcd 集群中多个节点之间通过Raft算法完成分布式一致性协同,算法会选举出一 ...

  2. HDFS租约机制

    https://www.cnblogs.com/cssdongl/p/6699919.html

  3. 从零开始入门 K8s | 手把手带你理解 etcd

    作者 | 曾凡松(逐灵) 阿里云容器平台高级技术专家 本文整理自<CNCF x Alibaba 云原生技术公开课>第 16 讲. 导读:etcd 是用于共享配置和服务发现的分布式.一致性的 ...

  4. [转帖]从零开始入门 K8s | 手把手带你理解 etcd

    从零开始入门 K8s | 手把手带你理解 etcd https://zhuanlan.zhihu.com/p/96721097 导读:etcd 是用于共享配置和服务发现的分布式.一致性的 KV 存储系 ...

  5. 第16 章 : 深入理解 etcd:基于原理解析

    深入理解 etcd:基于原理解析 本文将主要分享以下三方面的内容: 第一部分,会为大家介绍 etcd 项目发展的整个历程,从诞生至今 etcd 经历的那些重要的时刻: 第二部分,会为大家介绍 etcd ...

  6. etcd的使用

    etcd的使用 什么是etcd etcd的特点 etcd的应用场景 服务注册与发现 消息发布和订阅 负载均衡 分布式通知与协调 分布式锁 分布式队列 集群监控与Leader竞选 参考 etcd的使用 ...

  7. 长篇图解etcd核心应用场景及编码实战

    大家好啊,我是字母哥,今天写一篇关于etcd的文章,其实网上也有很多关于etcd的介绍,我就简明扼要,总结提炼,期望大家通过这一篇文章掌握etcd的核心知识以及编码技能! 本文首先用大白话给大家介绍一 ...

  8. PacificA中的租约与失效检测解读

    PacificA是微软的在基于log的分布式存储系统中的复制技术. 由于配置管理器维护着当前配置的真实情况,因此主节点不必保持不变. 这是因为配置的本地视图在不同服务器上是不必同步的. 特别是,我们必 ...

  9. Golang etcd服务注册与发现

    //sevice.go package discovery import ( "context" "errors" "sync" " ...

随机推荐

  1. java和c中i++(i--)的区别(网易笔试2014)

    java代码: public class Test{ public static void main(String[] args){ int a=5; int b=(a++)*(a++);//5*6自 ...

  2. 计算机网络(十),HTTP的关键问题

    目录 1.在浏览器地址栏键入URL,按下回车之后经历的流程 2.HTTP状态码 3.GET请求和POST请求的区别 4.Cookie和Session的区别 5.IPV4和IPV6 十.HTTP的关键问 ...

  3. JSP大文件上传断点续传解决方案

    我们平时经常做的是上传文件,上传文件夹与上传文件类似,但也有一些不同之处,这次做了上传文件夹就记录下以备后用. 首先我们需要了解的是上传文件三要素: 1.表单提交方式:post (get方式提交有大小 ...

  4. TensorFlow使用记录 (一): 基本概念

    基本使用 使用graph来表示计算任务 在被称之为Session的上下文中执行graph 使用tensor表示数据 通过Variable维护状态 使用feed和fetch可以为任意的操作(op)赋值或 ...

  5. python实现的一个中文文本摘要程序

    文本摘要方法有很多,主要分为抽取式和生成式,应用比较多的是抽取式,也比较简单,就是从文本中抽取重要的句子或段落.本方法主要是利用句子中的关键词的距离,主要思想和参考来自阮一峰的网络日志http://w ...

  6. Jmeter(一) 安装

    一.检查JDK版本 执行cmd > java -version 查看本机JDK版本,JDK版本不能低于1.6 二.软件下载 登录Jmeter官网:https://jmeter.apache.or ...

  7. sql 建立索引之前计算区分度

    select cutomer_id,title,content from product_comment where audit_status=1 and product_id=1 and produ ...

  8. 如何在一个页面使用多个router-view显示不同的内容

    todo https://www.jianshu.com/p/92f61bf9db81

  9. mysql报错处理:incompatible with sql_mode=only_full_group_by

    问题: 服务报错:incompatible with sql_mode=only_full_group_by,如下图所示: 分析: NLY_FULL_GROUP_BY是MySQL提供的一个sql_mo ...

  10. SpringBoot导入导出Excel到Mysql

    2018.11.11 10:44:52字数 96阅读 1320 一.包的引用 除了引用SpringBoot基本包之外,还需要引入对Excel操作的包,如下: <dependency> &l ...