当前位置:网站首页>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 .
边栏推荐
- System programming summary
- Find the interface and add parameters to the form
- How to repair expired SSL certificates?
- 输入输出及中断技术——微机第六章学习笔记
- Requirements for transfer transaction cases: 1 Employee 1 transfers money to employee 2. Therefore, two update sals should be executed. Purpose: either both updates are successful or both implementati
- Learning about signals
- If you encounter problems when using spark for the first time, please ask for help
- Network high concurrency
- SQL error caused by entity class: Oracle "ora-00904" error: possible case of invalid identifier
- The subsystem implementing transaction persistence in DBMS is ()
猜你喜欢

The new paradigm of AI landing is "hidden" in the next major upgrade of software infrastructure

El upload Upload file (Manual upload, Automatic upload, upload progress)

Mongodb learning

Anonymous pipeline for interprocess communication

Learn about threads

Break through the existing customer group marketing, and try customer grouping management (including clustering model and other practical effect evaluation)

Basic knowledge of redis

JS inheritance

管道实现进程间通信之命名管道

How to repair expired SSL certificates?
随机推荐
Es2019 key summary
Refers to the difference between IP and *ip at output
Requirements for transfer transaction cases: 1 Employee 1 transfers money to employee 2. Therefore, two update sals should be executed. Purpose: either both updates are successful or both implementati
IIS request SSL certificate
FortiGate firewall modifies the default timeout of a session
Encapsulating JDBC tool classes
Salary management system based on servlet+jsp+mysql [source code + database]
Break through the existing customer group marketing, and try customer grouping management (including clustering model and other practical effect evaluation)
QT 6.3.1conan software package release
Transport layer protocol tcp/udp
JS static method
Slam mapping, automatic navigation and obstacle avoidance based on ROS (bingda robot)
Educoder group purchase suspension box page production
Intern method of string
What to do when the alicloud SSL certificate expires
Stack implementation integrated Calculator - code implementation
Qt 6.3.1Conan软件包发布
小C的数组(array)
Qt Creator 8 Beta2发布
Issue SSL certificate with IP address