From 80f5484863c3feed093bf2cf57b0e78d2bab8056 Mon Sep 17 00:00:00 2001 From: Akshat Jain Date: Sun, 8 Feb 2026 19:27:15 +0530 Subject: [PATCH] docs: add prerequisites, examples, and release info to locks tutorial Signed-off-by: Akshat Jain --- .../tasks/developer/how-to-create-locks.md | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/content/en/docs/v3.6/tasks/developer/how-to-create-locks.md b/content/en/docs/v3.6/tasks/developer/how-to-create-locks.md index 2232b85ed..e61b9e1f4 100644 --- a/content/en/docs/v3.6/tasks/developer/how-to-create-locks.md +++ b/content/en/docs/v3.6/tasks/developer/how-to-create-locks.md @@ -9,17 +9,39 @@ LOCK acquires a distributed mutex with a given name. Once the lock is acquired, ## Prerequisites * Install [`etcd` and `etcdctl`](https://etcd.io/docs/v3.6/install/) +* A running etcd cluster (see [How to Set Up a Demo etcd Cluster](/docs/v3.6/tasks/operator/how-to-setup-cluster/)) ## Creating a lock -`lock` for distributed lock: +Acquire a lock with a specified name: +```shell +etcdctl --endpoints=$ENDPOINTS lock mutex1 +``` -![08_etcdctl_lock_2016050501](https://storage.googleapis.com/etcd/demo/08_etcdctl_lock_2016050501.gif) +The lock will be held until the command is terminated with `Ctrl+C`. +### Lock with command execution + +You can also execute a command while holding the lock: ```shell -etcdctl --endpoints=$ENDPOINTS lock mutex1 +etcdctl --endpoints=$ENDPOINTS lock mutex1 echo "Lock acquired" ``` -### Options -- endpoints - defines a comma-delimited list of machine addresses in the cluster. -- ttl - time out in seconds of lock session. +When using this form, the lock is automatically released after the command completes. + +### Visual demonstration + +![08_etcdctl_lock_2016050501](https://storage.googleapis.com/etcd/demo/08_etcdctl_lock_2016050501.gif) + +## Options + +- `--endpoints` - Comma-delimited list of etcd cluster endpoints (default: `http://127.0.0.1:2379`) +- `--ttl` - Time to live in seconds for the lock session (default: 60) + +## Releasing a lock + +Locks are released in the following ways: + +- **Manual release**: Press `Ctrl+C` to terminate the etcdctl lock command +- **Automatic release**: When executing a command with the lock, it is released after the command completes +- **TTL expiration**: The lock automatically expires after the TTL period if not renewed \ No newline at end of file