File tree Expand file tree Collapse file tree 4 files changed +18
-3
lines changed
Expand file tree Collapse file tree 4 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -322,6 +322,10 @@ JVM 这部分内容主要参考 [JVM 虚拟机规范-Java8 ](https://docs.oracle
322322
323323[ 为什么要分布式 id ?分布式 id 生成方案有哪些?] ( ./docs/distributed-system/distributed-id.md )
324324
325+ ### 分布式锁
326+
327+ [ 分布式锁] ( ./docs/distributed-system/distributed-lock.md )
328+
325329### 分布式事务
326330
327331[ 分布式事务] ( ./docs/distributed-system/distributed-transaction.md )
Original file line number Diff line number Diff line change @@ -394,6 +394,7 @@ export const sidebarConfig = defineSidebarConfig({
394394 } ,
395395 "api-gateway" ,
396396 "distributed-id" ,
397+ "distributed-lock" ,
397398 {
398399 text : "RPC" ,
399400 prefix : "rpc/" ,
Original file line number Diff line number Diff line change 1+ ---
2+ title : 分布式锁
3+ category : 分布式
4+ ---
5+
16## 什么是分布式锁?
27
38对于单机多线程,在 Java 中,我们通常使用 ` ReetrantLock ` 这类 JDK 自带的 ** 本地锁** 来控制本地多个线程对本地共享资源的访问。对于分布式系统,我们通常使用 ** 分布式锁** 来控制多个服务对共享资源的访问。
@@ -103,9 +108,10 @@ Redlock 算法的思想是让客户端向 Redis 集群中的多个独立的 Redi
103108
104109即使部分 Redis 节点出现问题,只要保证 Redis 集群中有半数以上的 Redis 节点可用,分布式锁服务就是正常的。
105110
106- Redlock 是直接操作 Redis 节点的,并不是通过 Redis 集群操作的,这样才可以避免Redis集群主从切换导致的锁丢失问题。
107-
108- Redlock 实现比较复杂,性能也比较差。 《数据密集型应用系统设计》一书的作者曾经专门发文 diss 过Redlock。
111+ Redlock 是直接操作 Redis 节点的,并不是通过 Redis 集群操作的,这样才可以避免 Redis 集群主从切换导致的锁丢失问题。
109112
113+ Redlock 实现比较复杂,性能比较差,发生时钟变迁的情况下还存在安全性隐患。《数据密集型应用系统设计》一书的作者 Martin Kleppmann 曾经专门发文怼过 Redlock,他认为这是一个很差的分布式锁实现。感兴趣的朋友可以看看[ Redis 锁从面试连环炮聊到神仙打架] ( https://mp.weixin.qq.com/s?__biz=Mzg3NjU3NTkwMQ==&mid=2247505097&idx=1&sn=5c03cb769c4458350f4d4a321ad51f5a&source=41#wechat_redirect ) 这篇文章,有详细介绍到 antirez 和 Martin Kleppmann 关于 Redlock 的激烈辩论。
110114
115+ 实际项目中不建议使用 Redlock 算法,成本和收益不成正比。
111116
117+ 如果不是非要实现绝对可靠的分布式锁的话,其实单机版 Redis 就完全够了,实现简单,性能也非常高。如果你必须要实现一个绝对可靠的分布式锁的话,可以基于 Zookeeper 来做,只是性能会差一些。
Original file line number Diff line number Diff line change @@ -325,6 +325,10 @@ JVM 这部分内容主要参考 [JVM 虚拟机规范-Java8 ](https://docs.oracle
325325
326326[ 为什么要分布式 id ?分布式 id 生成方案有哪些?] ( ./distributed-system/distributed-id.md )
327327
328+ ### 分布式锁
329+
330+ [ 分布式锁] ( ./distributed-system/distributed-lock.md )
331+
328332### 分布式事务
329333
330334[ 分布式事务] ( ./distributed-system/distributed-transaction.md )
You can’t perform that action at this time.
0 commit comments