Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions content/en/docs/v3.6/tasks/developer/how-to-create-locks.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to see more here for setup. For example, the user will need to have multiple, separate shell sessions with etcdctl clients in order to try this out.


## 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"
Comment on lines -20 to +27
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, this example is wrong, because the original tutorial is wrong. For this form of the lock, you need to actually send etcd a command, like updating a key.

```

### 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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, we don't recommend using GIF formats due to issues with maintainability, large file sizes, and lack of accessibility. Could you please consider explaining the guidance thoroughly in the written content first, and removing the GIF from this section?


## 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