当前位置:网站首页>Distributed lock
Distributed lock
2022-07-03 06:59:00 【W_ Meng_ H】
Catalog
Two 、Zookeeper Distributed lock
3、 ... and 、Redis Distributed lock
Why do I need distributed locks ?
Distributed projects , Each project is independent . The lock needs to be independent of each service , Not in service .
One 、 database
- Using primary key conflict control, only one thread can obtain the lock at a time , Non blocking 、 Do not reenter 、 Single point 、 Failure time, etc .
Two 、Zookeeper Distributed lock
zk Through temporary nodes , Solved the deadlock problem , Once the client gets the lock, it suddenly hangs up (Session Connection is broken ), Then the temporary node will be deleted automatically , Other clients automatically acquire locks , Temporary sequential nodes to solve the group shock effect ( In multiple processes / When multiple threads wait for the same resource , There will also be surprises . That is, when a resource is available , Multiple processes / The thread will wake up , Compete for resources . This is the surprise group in the operating system ).
3、 ... and 、Redis Distributed lock
settnx, Single threaded processing of network requests , There is no need to consider concurrency security , All service nodes have the same settings key, return 0, Lock acquisition fails .
setnx problem :
- Earlier versions did not have a timeout parameter , It needs to be set separately , There is a deadlock problem ( Halfway down ).
- Later versions provide atomic operations of locking and setting time , But there is a task timeout , Lock release , Causes concurrency problems , Locking and releasing locks are not the same thread problem .
Delete lock : Determine the unique ID of the thread , And then delete .
Reentry and lock renewal are not realized , adopt Redisson solve ( similar AQS The implementation of the )
redlock:redis Ensure high availability through sentinel mode , If this master For some reason, the node has switched from master to slave , Then the lock will be lost (redis Synchronization may cause data loss ).redlock Apply for locks from multiple nodes , When more than half of the nodes succeed , Lock is success ,Redisson There is a corresponding implementation .
边栏推荐
- Flask Foundation
- Realize PDF to picture conversion with C #
- 保险公司怎么查高血压?
- Yolov2 learning and summary
- Operation principle of lua on C: Foundation
- Hands on redis master-slave replication, sentinel master-slave switching, cluster sharding
- Laravel Web框架
- Understand software testing
- Winter vacation work of software engineering practice
- Summary of remote connection of MySQL
猜你喜欢

Reading notes of "learn to ask questions"

dataworks自定义函数开发环境搭建

VMware virtual machine C disk expansion

10000小時定律不會讓你成為編程大師,但至少是個好的起點

EasyExcel

How to migrate or replicate VMware virtual machine systems

Software testing learning - the next day

Ruoyi interface permission verification

如何迁移或复制VMware虚拟机系统

Notes on the core knowledge of Domain Driven Design DDD
随机推荐
The 10000 hour rule won't make you a master programmer, but at least it's a good starting point
Dbnet: real time scene text detection with differentiable binarization
A letter to graduating college students
[vscode - vehicle plug-in reports an error] cannot find module 'xxx' or its corresponding type declarations Vetur(2307)
Architecture notes
Summary of the design and implementation of the weapon system similar to the paladin of vitality
Class and object summary
[Fiddler actual operation] how to use Fiddler to capture packets on Apple Mobile Phones
Laravel Web Framework
Laravel frame step pit (I)
IC_EDA_ALL虚拟机(丰富版):questasim、vivado、vcs、verdi、dc、pt、spyglass、icc2、synplify、INCISIVE、IC617、MMSIM、工艺库
centos php7.3安装redis扩展
The essence of interview
How to migrate or replicate VMware virtual machine systems
CentOS php7.3 installing redis extensions
IC_ EDA_ All virtual machine (rich Edition): questasim, vivado, VCs, Verdi, DC, Pt, spyglass, icc2, synthesize, innovative, ic617, mmsim, process library
mongodb
golang操作redis:写入、读取hash类型数据
How can I split a string at the first occurrence of “-” (minus sign) into two $vars with PHP?
Centos切换安装mysql5.7和mysql8.0