@@ -9,17 +9,39 @@ LOCK acquires a distributed mutex with a given name. Once the lock is acquired,
99## Prerequisites
1010
1111* Install [ ` etcd ` and ` etcdctl ` ] ( https://etcd.io/docs/v3.6/install/ )
12+ * A running etcd cluster (see [ How to Set Up a Demo etcd Cluster] ( /docs/v3.6/tasks/operator/how-to-setup-cluster/ ) )
1213
1314## Creating a lock
1415
15- ` lock ` for distributed lock:
16+ Acquire a lock with a specified name:
17+ ``` shell
18+ etcdctl --endpoints=$ENDPOINTS lock mutex1
19+ ```
1620
17- ![ 08_etcdctl_lock_2016050501 ] ( https://storage.googleapis.com/etcd/demo/08_etcdctl_lock_2016050501.gif )
21+ The lock will be held until the command is terminated with ` Ctrl+C ` .
1822
23+ ### Lock with command execution
24+
25+ You can also execute a command while holding the lock:
1926``` shell
20- etcdctl --endpoints=$ENDPOINTS lock mutex1
27+ etcdctl --endpoints=$ENDPOINTS lock mutex1 echo " Lock acquired "
2128```
2229
23- ### Options
24- - endpoints - defines a comma-delimited list of machine addresses in the cluster.
25- - ttl - time out in seconds of lock session.
30+ When using this form, the lock is automatically released after the command completes.
31+
32+ ### Visual demonstration
33+
34+ ![ 08_etcdctl_lock_2016050501] ( https://storage.googleapis.com/etcd/demo/08_etcdctl_lock_2016050501.gif )
35+
36+ ## Options
37+
38+ - ` --endpoints ` - Comma-delimited list of etcd cluster endpoints (default: ` http://127.0.0.1:2379 ` )
39+ - ` --ttl ` - Time to live in seconds for the lock session (default: 60)
40+
41+ ## Releasing a lock
42+
43+ Locks are released in the following ways:
44+
45+ - ** Manual release** : Press ` Ctrl+C ` to terminate the etcdctl lock command
46+ - ** Automatic release** : When executing a command with the lock, it is released after the command completes
47+ - ** TTL expiration** : The lock automatically expires after the TTL period if not renewed
0 commit comments