新建租约

新建一个过期时间为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. linux完整卸载mysql数据库

    由于本机测试环境数据库装错了,需要卸载数据库,记录一下 yum -y remove mysql find / -name mysql /etc/selinux/targeted/active/modu ...

  2. 25. ClustrixDB 使用sierra_stats导出概率分布

    ClustrixDB提供了导出概率分布(PDs)的能力,这可以与模式(DDL)一起用于调查查询的性能.通常,这个过程是在Clustrix支持请求时执行的.下面的部分概述了如何使用python脚本sie ...

  3. Springboot 默认静态路径

    springboot 默认静态路径 代码如下所示 类ResourceProperties.class private static final String[] CLASSPATH_RESOURCE_ ...

  4. 原生Js_制作简易日历

    javascript制作简易日历,月份信息已经放在一个数组中,在<script>...</script>中编写代码实现其功能 实现步骤 a) 获取需要操作的dom对象 b) 在 ...

  5. [CSP-S模拟测试]:五子棋(模拟)

    题目传送门(内部题122) 输入格式 输入文件第一行为一个正整数$n$,表示双方总共下了多少步棋. 接下来$n$行,输入文件每行两个正整数.第$i$行的两个数$x,y$表示第$i$步的棋子下在了第$x ...

  6. 关于JDK8对List的分组汇总

    1. 跟据某个属性分组OfficeId: Map<String, List<IncomeSumPojo>> collect = list.stream().collect(Co ...

  7. Java实现QQ微信轰炸机1.2(斗图乞丐版)

    之前有小可爱评论可以实现斗图的功能,原理上是行的通的,所以我就稍微改了一下,能够实现单个图片循环轰炸,如果大家感兴趣也可以自己探究实现多张图片循环轰炸,不废话了,直接上源码package QQWcha ...

  8. 【Linux】单计算机安装PBS系统(Torque)与运维

    1.此次使用torque-5.0.0-1_43d8f09a.tar.gz这个版本http://www.adaptivecomputing.com/downloading/?file=/torque/t ...

  9. LeetCode 17. 电话号码的字母组合(Letter Combinations of a Phone Number)

    题目描述 给定一个仅包含数字 2-9 的字符串,返回所有它能表示的字母组合. 给出数字到字母的映射如下(与电话按键相同).注意 1 不对应任何字母. 示例: 输入:"23" 输出: ...

  10. python模块------pyautogui

    安装 pip install pyautogui 基本使用 查询 screenWidth, screenHeight = pyautogui.size() # 屏幕尺寸 mouseX, mouseY ...