当前位置:网站首页>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 .
边栏推荐
- [set theory] partition (partition | partition example | partition and equivalence relationship)
- JMeter JSON extractor extracts two parameters at the same time
- JMeter test result output
- 卡特兰数(Catalan)的应用场景
- mongodb
- Yolov3 learning notes
- How to specify the execution order for multiple global exception handling classes
- How to migrate or replicate VMware virtual machine systems
- [C /vb.net] convert PDF to svg/image, svg/image to PDF
- Journal quotidien des questions (11)
猜你喜欢

Summary of remote connection of MySQL

IC_ EDA_ All virtual machine (rich Edition): questasim, vivado, VCs, Verdi, DC, Pt, spyglass, icc2, synthesize, innovative, ic617, mmsim, process library

10000小时定律不会让你成为编程大师,但至少是个好的起点

Create your own deep learning environment with CONDA

Realize PDF to picture conversion with C #

Winter vacation work of software engineering practice

dataworks自定义函数开发环境搭建
![[classes and objects] explain classes and objects in simple terms](/img/41/250457530880dfe3728432c2ccd50b.png)
[classes and objects] explain classes and objects in simple terms

Jenkins

【无标题】
随机推荐
Inno setup production and installation package
The essence of interview
Upgrade CentOS php7.2.24 to php7.3
Arctic code vault contributor
Centos切换安装mysql5.7和mysql8.0
golang操作redis:写入、读取kv数据
Jmeter+influxdb+grafana of performance tools to create visual real-time monitoring of pressure measurement -- problem record
Abstract learning
(翻译)异步编程:Async/Await在ASP.NET中的介绍
Yolov2 learning and summary
Tool class static method calls @autowired injected service
Golang operation redis: write and read hash type data
2021 year end summary
Class and object summary
2022-06-23 vgmp OSPF inter domain security policy NAT policy (under update)
[Code] if (list! = null & list. Size() > 0) optimization, set empty judgment implementation method
Laravel frame step pit (I)
【code】偶尔取值、判空、查表、验证等
Ruoyi interface permission verification
How can I split a string at the first occurrence of “-” (minus sign) into two $vars with PHP?