Alibaba cloud Q & A 2022-02-13 06:12:46 阅读数:457
Zookeeper Distributed lock ( file system 、 A notification mechanism ), How to achieve ?
With zookeeper The consistency file system , The problem of locks becomes easy . There are two types of lock services , One is to keep exclusive , The other is to control the timing .
For the first category , We will zookeeper On the one znode Think of it as a lock , adopt createznode The way to achieve . All clients are going to create /distribute_lock node , Finally, the client successfully created owns the lock . Delete the self created distribute_lock The node releases the lock .
For the second category , /distribute_lock Already exist in advance , All clients create temporary sequence number directory nodes under it , And choose master equally , Get the lock with the smallest number , Use up delete , Convenient in turn .
copyright:author[Alibaba cloud Q & A],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/02/202202130612453658.html