Skip to content

Commit

Permalink
Fixed documentation and scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
ptabor committed May 17, 2021
1 parent 949c1c2 commit 3f7a038
Show file tree
Hide file tree
Showing 7 changed files with 213 additions and 53 deletions.
1 change: 1 addition & 0 deletions Dockerfile-release.amd64
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ FROM k8s.gcr.io/build-image/debian-base:buster-v1.4.0

ADD etcd /usr/local/bin/
ADD etcdctl /usr/local/bin/
ADD etcdutl /usr/local/bin/
RUN mkdir -p /var/etcd/
RUN mkdir -p /var/lib/etcd/

Expand Down
1 change: 1 addition & 0 deletions Dockerfile-release.arm64
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ FROM k8s.gcr.io/build-image/debian-base-arm64:buster-v1.4.0

ADD etcd /usr/local/bin/
ADD etcdctl /usr/local/bin/
ADD etcdutl /usr/local/bin/
ADD var/etcd /var/etcd
ADD var/lib/etcd /var/lib/etcd
ENV ETCD_UNSUPPORTED_ARCH=arm64
Expand Down
1 change: 1 addition & 0 deletions Dockerfile-release.ppc64le
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ FROM k8s.gcr.io/build-image/debian-base-ppc64le:buster-v1.4.0

ADD etcd /usr/local/bin/
ADD etcdctl /usr/local/bin/
ADD etcdutl /usr/local/bin/
ADD var/etcd /var/etcd
ADD var/lib/etcd /var/lib/etcd

Expand Down
1 change: 1 addition & 0 deletions Dockerfile-release.s390x
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ FROM k8s.gcr.io/build-image/debian-base-s390x:buster-v1.4.0

ADD etcd /usr/local/bin/
ADD etcdctl /usr/local/bin/
ADD etcdutl /usr/local/bin/
ADD var/etcd /var/etcd
ADD var/lib/etcd /var/lib/etcd

Expand Down
63 changes: 11 additions & 52 deletions etcdctl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -913,15 +913,17 @@ If NOSPACE alarm is present:

### DEFRAG [options]

DEFRAG defragments the backend database file for a set of given endpoints while etcd is running, or directly defragments an etcd data directory while etcd is not running. When an etcd member reclaims storage space from deleted and compacted keys, the space is kept in a free list and the database file remains the same size. By defragmenting the database, the etcd member releases this free space back to the file system.
DEFRAG defragments the backend database file for a set of given endpoints while etcd is running, ~~or directly defragments an etcd data directory while etcd is not running~~. When an etcd member reclaims storage space from deleted and compacted keys, the space is kept in a free list and the database file remains the same size. By defragmenting the database, the etcd member releases this free space back to the file system.

**Note: to defragment offline (`--data-dir` flag), use: `etcutl defrag` instead**

**Note that defragmentation to a live member blocks the system from reading and writing data while rebuilding its states.**

**Note that defragmentation request does not get replicated over cluster. That is, the request is only applied to the local node. Specify all members in `--endpoints` flag or `--cluster` flag to automatically find all cluster members.**

#### Options

- data-dir -- Optional. If present, defragments a data directory not in use by etcd.
- data-dir -- Optional. **Deprecated**. If present, defragments a data directory not in use by etcd. To be removed in v3.6.

#### Output

Expand All @@ -944,11 +946,12 @@ Finished defragmenting etcd member[http://127.0.0.1:22379]
Finished defragmenting etcd member[http://127.0.0.1:32379]
```

To defragment a data directory directly, use the `--data-dir` flag:
To defragment a data directory directly, use the `etcdutl` with `--data-dir` flag
(`etcdctl` will remove this flag in v3.6):

``` bash
# Defragment while etcd is not running
./etcdctl defrag --data-dir default.etcd
./etcdutl defrag --data-dir default.etcd
# success (exit status 0)
# Error: cannot open database at default.etcd/member/snap/db
```
Expand Down Expand Up @@ -978,6 +981,8 @@ Save a snapshot to "snapshot.db":

### SNAPSHOT RESTORE [options] \<filename\>

Note: Deprecated. Use `etcdutl snapshot restore` instead. To be removed in v3.6.

SNAPSHOT RESTORE creates an etcd data directory for an etcd cluster member from a backend database snapshot and a new cluster configuration. Restoring the snapshot into each member for a new cluster configuration will initialize a new etcd cluster preloaded by the snapshot data.

#### Options
Expand Down Expand Up @@ -1021,6 +1026,8 @@ bin/etcd --name sshot3 --listen-client-urls http://127.0.0.1:32379 --advertise-c

### SNAPSHOT STATUS \<filename\>

Note: Deprecated. Use `etcdutl snapshot restore` instead. To be removed in v3.6.

SNAPSHOT STATUS lists information about a given backend database snapshot file.

#### Output
Expand Down Expand Up @@ -1495,54 +1502,6 @@ The approximate total number of keys transferred to the destination cluster, upd

[mirror]: ./doc/mirror_maker.md

### MIGRATE [options]

Migrates keys in a v2 store to a v3 mvcc store. Users should run migration command for all members in the cluster.

#### Options

- data-dir -- Path to the data directory

- wal-dir -- Path to the WAL directory

- transformer -- Path to the user-provided transformer program (default if not provided)

#### Output

No output on success.

#### Default transformer

If user does not provide a transformer program, migrate command will use the default transformer. The default transformer transforms `storev2` formatted keys into `mvcc` formatted keys according to the following Go program:

```go
func transform(n *storev2.Node) *mvccpb.KeyValue {
if n.Dir {
return nil
}
kv := &mvccpb.KeyValue{
Key: []byte(n.Key),
Value: []byte(n.Value),
CreateRevision: int64(n.CreatedIndex),
ModRevision: int64(n.ModifiedIndex),
Version: 1,
}
return kv
}
```

#### User-provided transformer

Users can provide a customized 1:n transformer function that transforms a key from the v2 store to any number of keys in the mvcc store. The migration program writes JSON formatted [v2 store keys][v2key] to the transformer program's stdin, reads protobuf formatted [mvcc keys][v3key] back from the transformer program's stdout, and finishes migration by saving the transformed keys into the mvcc store.

The provided transformer should read until EOF and flush the stdout before exiting to ensure data integrity.

#### Example

```
./etcdctl migrate --data-dir=/var/etcd --transformer=k8s-transformer
# finished transforming keys
```

### VERSION

Expand Down
196 changes: 196 additions & 0 deletions etcdutl/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
etcdutl
========

`etcdutl` is a command line administration utility for [etcd][etcd].

It's designed to operate directly on etcd data files.
For operations over a network, please use `etcdctl`.

### DEFRAG [options]

DEFRAG directly defragments an etcd data directory while etcd is not running.
When an etcd member reclaims storage space from deleted and compacted keys, the space is kept in a free list and the database file remains the same size. By defragmenting the database, the etcd member releases this free space back to the file system.

In order to defrag a live etcd instances over the network, please use `etcdctl defrag` instead.

#### Options

- data-dir -- Optional. If present, defragments a data directory not in use by etcd.

#### Output

Exit status '0' when the process was successful.

#### Example

To defragment a data directory directly, use the `--data-dir` flag:

``` bash
# Defragment while etcd is not running
./etcdutl defrag --data-dir default.etcd
# success (exit status 0)
# Error: cannot open database at default.etcd/member/snap/db
```

#### Remarks

DEFRAG returns a zero exit code only if it succeeded in defragmenting all given endpoints.


### SNAPSHOT RESTORE [options] \<filename\>

SNAPSHOT RESTORE creates an etcd data directory for an etcd cluster member from a backend database snapshot and a new cluster configuration. Restoring the snapshot into each member for a new cluster configuration will initialize a new etcd cluster preloaded by the snapshot data.

#### Options

The snapshot restore options closely resemble to those used in the `etcd` command for defining a cluster.

- data-dir -- Path to the data directory. Uses \<name\>.etcd if none given.

- wal-dir -- Path to the WAL directory. Uses data directory if none given.

- initial-cluster -- The initial cluster configuration for the restored etcd cluster.

- initial-cluster-token -- Initial cluster token for the restored etcd cluster.

- initial-advertise-peer-urls -- List of peer URLs for the member being restored.

- name -- Human-readable name for the etcd cluster member being restored.

- skip-hash-check -- Ignore snapshot integrity hash value (required if copied from data directory)

#### Output

A new etcd data directory initialized with the snapshot.

#### Example

Save a snapshot, restore into a new 3 node cluster, and start the cluster:
```
./etcdutl snapshot save snapshot.db
# restore members
bin/etcdutl snapshot restore snapshot.db --initial-cluster-token etcd-cluster-1 --initial-advertise-peer-urls http://127.0.0.1:12380 --name sshot1 --initial-cluster 'sshot1=http://127.0.0.1:12380,sshot2=http://127.0.0.1:22380,sshot3=http://127.0.0.1:32380'
bin/etcdutl snapshot restore snapshot.db --initial-cluster-token etcd-cluster-1 --initial-advertise-peer-urls http://127.0.0.1:22380 --name sshot2 --initial-cluster 'sshot1=http://127.0.0.1:12380,sshot2=http://127.0.0.1:22380,sshot3=http://127.0.0.1:32380'
bin/etcdutl snapshot restore snapshot.db --initial-cluster-token etcd-cluster-1 --initial-advertise-peer-urls http://127.0.0.1:32380 --name sshot3 --initial-cluster 'sshot1=http://127.0.0.1:12380,sshot2=http://127.0.0.1:22380,sshot3=http://127.0.0.1:32380'
# launch members
bin/etcd --name sshot1 --listen-client-urls http://127.0.0.1:2379 --advertise-client-urls http://127.0.0.1:2379 --listen-peer-urls http://127.0.0.1:12380 &
bin/etcd --name sshot2 --listen-client-urls http://127.0.0.1:22379 --advertise-client-urls http://127.0.0.1:22379 --listen-peer-urls http://127.0.0.1:22380 &
bin/etcd --name sshot3 --listen-client-urls http://127.0.0.1:32379 --advertise-client-urls http://127.0.0.1:32379 --listen-peer-urls http://127.0.0.1:32380 &
```

### SNAPSHOT STATUS \<filename\>

SNAPSHOT STATUS lists information about a given backend database snapshot file.

#### Output

##### Simple format

Prints a humanized table of the database hash, revision, total keys, and size.

##### JSON format

Prints a line of JSON encoding the database hash, revision, total keys, and size.

#### Examples
```bash
./etcdutl snapshot status file.db
# cf1550fb, 3, 3, 25 kB
```

```bash
./etcdutl --write-out=json snapshot status file.db
# {"hash":3474280699,"revision":3,"totalKey":3,"totalSize":24576}
```

```bash
./etcdutl --write-out=table snapshot status file.db
+----------+----------+------------+------------+
| HASH | REVISION | TOTAL KEYS | TOTAL SIZE |
+----------+----------+------------+------------+
| cf1550fb | 3 | 3 | 25 kB |
+----------+----------+------------+------------+
```

### VERSION

Prints the version of etcdutl.

#### Output

Prints etcd version and API version.

#### Examples

```bash
./etcdutl version
# etcdutl version: 3.1.0-alpha.0+git
# API version: 3.1
```

### VERSION

Prints the version of etcdctl.

#### Output

Prints etcd version and API version.

#### Examples

```bash
./etcdutl version
# etcdutl version: 3.5.0
# API version: 3.1
```


## Exit codes

For all commands, a successful execution returns a zero exit code. All failures will return non-zero exit codes.

## Output formats

All commands accept an output format by setting `-w` or `--write-out`. All commands default to the "simple" output format, which is meant to be human-readable. The simple format is listed in each command's `Output` description since it is customized for each command. If a command has a corresponding RPC, it will respect all output formats.

If a command fails, returning a non-zero exit code, an error string will be written to standard error regardless of output format.

### Simple

A format meant to be easy to parse and human-readable. Specific to each command.

### JSON

The JSON encoding of the command's [RPC response][etcdrpc]. Since etcd's RPCs use byte strings, the JSON output will encode keys and values in base64.

Some commands without an RPC also support JSON; see the command's `Output` description.

### Protobuf

The protobuf encoding of the command's [RPC response][etcdrpc]. If an RPC is streaming, the stream messages will be concatenated. If an RPC is not given for a command, the protobuf output is not defined.

### Fields

An output format similar to JSON but meant to parse with coreutils. For an integer field named `Field`, it writes a line in the format `"Field" : %d` where `%d` is go's integer formatting. For byte array fields, it writes `"Field" : %q` where `%q` is go's quoted string formatting (e.g., `[]byte{'a', '\n'}` is written as `"a\n"`).

## Compatibility Support

etcdutl is still in its early stage. We try out best to ensure fully compatible releases, however we might break compatibility to fix bugs or improve commands. If we intend to release a version of etcdutl with backward incompatibilities, we will provide notice prior to release and have instructions on how to upgrade.

### Input Compatibility

Input includes the command name, its flags, and its arguments. We ensure backward compatibility of the input of normal commands in non-interactive mode.

### Output Compatibility
Currently, we do not ensure backward compatibility of utility commands.

### TODO: compatibility with etcd server

[etcd]: https://github.com/coreos/etcd
[READMEv2]: READMEv2.md
[v2key]: ../store/node_extern.go#L28-L37
[v3key]: ../api/mvccpb/kv.proto#L12-L29
[etcdrpc]: ../api/etcdserverpb/rpc.proto
[storagerpc]: ../api/mvccpb/kv.proto
3 changes: 2 additions & 1 deletion scripts/build-binary
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ function package {
if [ "${GOOS}" == "windows" ]; then
ext=".exe"
fi
for bin in etcd etcdctl; do
for bin in etcd etcdctl etcdutl; do
cp "${srcdir}/${bin}" "${target}/${bin}${ext}"
done

cp etcd/README.md "${target}"/README.md
cp etcd/etcdctl/README.md "${target}"/README-etcdctl.md
cp etcd/etcdctl/READMEv2.md "${target}"/READMEv2-etcdctl.md
cp etcd/etcdutl/README.md "${target}"/README-etcdutl.md

cp -R etcd/Documentation "${target}"/Documentation
}
Expand Down

0 comments on commit 3f7a038

Please sign in to comment.