当前位置:网站首页>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 .
边栏推荐
- The difference between CONDA and pip
- Operation principle of lua on C: Foundation
- Golang operation redis: write and read kV data
- C2338 Cannot format an argument. To make type T formattable provide a formatter<T> specialization:
- The list of "I'm crazy about open source" was released in the first week, with 160 developers on the list
- A letter to graduating college students
- [Code] occasionally take values, judge blanks, look up tables, verify, etc
- golang操作redis:写入、读取hash类型数据
- Troubleshooting of high CPU load but low CPU usage
- Ruoyi interface permission verification
猜你喜欢

Inno Setup 制作安装包
![[untitled]](/img/72/4ff9354634342580a135debb58b60e.jpg)
[untitled]

Winter vacation work of software engineering practice

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

Software testing assignment - day 1

Software testing assignment - the next day

Ruoyi interface permission verification
![[classes and objects] explain classes and objects in simple terms](/img/41/250457530880dfe3728432c2ccd50b.png)
[classes and objects] explain classes and objects in simple terms

每日刷題記錄 (十一)
随机推荐
Modify MySQL password
2021 year end summary
Laravel frame step pit (I)
多个全局异常处理类,怎么规定执行顺序
Getting started with pytest
Search engine Bing Bing advanced search skills
[untitled]
2022-06-23 VGMP-OSPF-域間安全策略-NAT策略(更新中)
Climb movie paradise 2021 hot
Redis command
Win 10 find the port and close the port
HMS core helps baby bus show high-quality children's digital content to global developers
Golang operation redis: write and read hash type data
Shim and Polyfill in [concept collection]
Journal quotidien des questions (11)
Create your own deep learning environment with CONDA
golang操作redis:写入、读取kv数据
The 10000 hour rule won't make you a master programmer, but at least it's a good starting point
MySQL mistakenly deleted the root account and failed to log in
这两种驱蚊成份对宝宝有害,有宝宝的家庭,选购驱蚊产品要注意