1 zookeeper
-
What are they
- Maintains state machines for each system in a distributed environment
- Service registration, service discovery
- A distributed lock
- Distributed storage of a small amount of critical data
-
Zk system model
/ ├ ─ ─ / API │ ├ ─ ─ member - API │ ├ ─ ─ the order - API │ └ ─ ─ the product - API ├ ─ ─ / db │ ├ ─ ─ mysql │ └ ─ ─ redis └ ─ ─ / services ├ ─ ─ ├─ order-srv ├─ product-srvCopy the code
-
Zk Node type
- Persistent node
- Temporary node
- Persist sequential nodes
- Temporary sequence node
-
Zk distributed lock
- ZAB consistency protocol – Ensures the synchronization of node status
- Temporary sequential nodes – Ensure that each thread that requests a lock can create a node with an increasing node number
- When a thread disconnects from zK, the temporary node created by the thread can be automatically deleted, and subsequent threads can create a node with a minimum number to acquire the lock
- The amount of concurrent lock acquisition is limited by the amount of node creation concurrency zK can handle
2 Distributed lock – ETCD
-
What can ETCD do
- Distributed kv
- Service discovery/registration
- A distributed lock
- Release subscription
-
Principle of distributed locking
- Create a globally unique prefix_lock_key to lock
- The client creates the lease
- LeaseId + prefix_lock_key constitutes a globally unique session
- OpGet gets all revisions
3 Distributed lock – redis
- Distributed implementation
- red lock
- unlock
if redis.call('get',KEYS[1]) == ARGV[1] then
return redis.call('del',KEYS[1])
else
return 0
end
Copy the code