Zookeeper distributed lock?
Client A obtains the distributed lock by first creating A temporary sequential node (node_n) under locker and then immediately acquiring all (level 1) child nodes under Locker. The number of children under locker is greater than 1 because multiple clients are fighting for the lock at the same time. For sequential node, the characteristic is the node name behind a number automatically, to create the first created after the node number is less than, so the child nodes can be according to the number of node name suffix order smallest, so the first one is the first to create the order of the node, at that moment, it is the first to lock the client! At this time whether the smallest this node for the client A previously created node_n, if it is represents A client access to the lock, lock if not say have been other client, so the client to wait for it to release A lock, which is waiting for the client to lock himself creates the node B. At this point, client B knows whether the lock has been released by listening for the drop event of the sequential node smaller than node_n. If so, client A again obtains all the child nodes under Locker and compares them with the node_n node. Until the created node_n is the smallest of locker’s children, client A has acquired the lock!