当前位置:网站首页>Implementation of one interview question one distributed lock every day
Implementation of one interview question one distributed lock every day
2022-06-30 04:34:00 【Garfield cat】
redis Implement distributed locks
Use setnx command , This command means if does not exist , Then set the value , If it exists, the value... Will not be set .
The problem is
When the expiration time is not set , If a thread dies after obtaining a lock, it becomes a deadlock
When setting the expiration time , If the thread takes too long to process the business after obtaining the lock , Cause the expiration time to expire , Will cause the lock to release , Other threads get the lock , When it finishes processing business , It will release the lock obtained by other threads , Can cause data problems .
resolvent
You can use a daemon thread to renew the expiration time of a lock , When processing business takes too long , When the expiration time is approaching , Reset the expiration time .
defects
redis Finally, there is the problem of deploying multiple nodes , There may still be lock data loss , Of course, this is a small probability event , If the business can ignore such small probability events , Then you can use it redis Do distributed locks .
Zookeeper Implement distributed locks
First ,Zookeeper A lock node will be created , Then the client requests that need to be locked zk When locking , A temporary node will be created under the lock node , If multiple clients request , Then the temporary nodes will be created in the order of the requests , Each temporary node will have a sequence number , This serial number is zk Internally generated ; When the client acquires the lock , It will determine whether the temporary node with the minimum sequence number under the lock node is created by itself , If it is , Get lock , If not , Then listen to your last temporary node .
zk To release a lock is to delete the temporary node you created
When the client goes down ,zk Sense , The temporary node created by it will be deleted .
边栏推荐
- FortiGate creates multiple corresponding DDNS dynamic domain names for multiple ADSL interfaces
- FortiGate firewall configuration log uploading regularly
- Learn about threads
- Basic knowledge of redis
- Myrpc version 6
- Educoder group purchase suspension box page production
- Tea mall system based on SSM framework [project source code + database script + report]
- Troubleshooting of abnormal communication between FortiGate and fortiguard cloud
- Redis实现短信登入功能(二)Redis实现登入功能
- Detailed explanation of data link layer
猜你喜欢

IIS request SSL certificate

输入输出及中断技术——微机第六章学习笔记

Directory operations and virtual file systems

Explain the underlying principles of JVM garbage collection in simple terms

Machine learning notes

Junior students summarize JS advanced interview questions

Process architecture and process management

What is an optocoupler circuit and what should be paid attention to in actual use?

Issue SSL certificate with IP address

进程间通信之匿名管道
随机推荐
Machine learning notes
Qt Creator 8 Beta2发布
Enlist soldiers and generals, draw small programs, multi-threaded display time
How the FortiGate firewall rejects a port by using the local in policy policy
Fair lock and unfair lock
Paging query, using jdbc-- paging query
JS static method
7-3 打怪升级 单源最短路
El upload Upload file (Manual upload, Automatic upload, upload progress)
Difference between TCP three handshakes and four waves and tcp/udp
Threejs realizes the simulation of river, surface flow, pipe flow and sea surface
Myrpc version 0
A solution to the problem of "couldn't open file /mnt/repodata/repomd.xml"
Redis implements SMS login function (II) redis implements login function
After the win10 system uses the browser to download, the content is moved or deleted without reason
Use of thread pool
Troubleshooting of abnormal communication between FortiGate and fortiguard cloud
How to use div boxes to simulate line triangles
Modifier of JS regular expression
管道实现进程间通信之命名管道