This article is a mirror article of machine translation, please click here to jump to the original article.

View: 156057|Reply: 37

[Console Program] .net/c# Zookeeper Distributed Lock Implementation [Source Code]

[Copy link]
Posted on 4/4/2018 5:10:42 PM | | | |
First, the following two articles on .net/c# Zookeeper distributed locks:

The hyperlink login is visible.

The hyperlink login is visible.

In fact, the above two articles are wrong! Completely misleading programming developers!


AboutZookeeper installation tutorial:

【Practical Combat】Zookeeper installation tutorial in Windows environment
http://www.itsvse.com/thread-4603-1-1.html
(Source: Architect_Programmer)

The implementation principle of Zookeeper distributed lock is explained in simple terms:

1: Get all the child nodes under the locker

2: All sub-nodes are sorted, here are two situations

If your node has the smallest serial number, then the client is considered to have obtained the lock. You can do your own thing!
If your node is not the smallest serial number, the node that listens to the smallest node is not the previous node that is smaller than you!!! Pay attention here!
(Because, your previous node may time out and release the lock!) )

3: Wait for the Zookeeper notification, and then, repeat the operation of 2, pull all nodes, sort them, and judge whether you are the smallest node............

After we know the principle, let's take a look at why the top two introductions of the article are wrong?





Looking at the example of the order in the article, it feels correct, and the result after running is also correct! However, if you test it a few times, you will know that the code in the article is completely wrong!!!!

So, knowing the principle, let's write it ourselves! Anyway, it's not the first time I've been pitted by code on the Internet!

Here's the correct gif:



Calling Code:



The ZooKeeperNet.dll version used is 3.4.6.1

[Actual combat] ASP.NET Core is based on Redis distributed lock flash sale
https://www.itsvse.com/thread-9397-1-1.html

Finally, attach the source code:

Tourists, if you want to see the hidden content of this post, pleaseReply





Previous:Solve the problem of "Using a password on the command line interface... "
Next:jquery gets the label type of the jquery object
Posted on 5/6/2019 6:15:55 PM |
LZ, I looked at the source code and it didn't handle zk timeout operations such as releasing locks, whether it was because of the ZK temporary node mechanism. If the zk is disconnected, the node is automatically deleted.
Posted on 7/3/2019 11:16:25 AM |
Run error: Throws an exception of type ZooKeeperNet.KeeperException+ConnectionLossException.
Posted on 5/6/2019 6:17:02 PM |
In the case of a single zk, there may be no problem. If zk is a cluster, will there be problems with the performance of 3 zk data synchronized updates?
Posted on 4/8/2018 4:32:38 PM |
Thank you for sharing, let's take a look
Posted on 6/1/2018 12:01:39 PM |
Thanks for sharing
Posted on 7/5/2018 12:31:02 PM |
Nice post
Posted on 7/10/2018 12:11:14 PM |
mark
mark
mark
mark
Posted on 7/11/2018 3:47:20 PM |
Yes, we are working on a distribution lock implementation scheme
Posted on 8/1/2018 12:52:23 PM |
Let's take a look
Posted on 10/28/2018 7:55:23 PM |
Learn to learn
Posted on 10/31/2018 4:52:15 PM |
Studying, thank you
Posted on 11/23/2018 10:24:32 AM |
Not bad, very good
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com