From 48b821004407c04ed5c825c55e202a1efb79b542 Mon Sep 17 00:00:00 2001 From: Benjamin Wang Date: Mon, 21 Nov 2022 08:38:50 +0800 Subject: [PATCH 1/5] etcdctl: display HashRevision for 127.0.0.1:2379, 1084519789 command Signed-off-by: Benjamin Wang --- etcdctl/ctlv3/command/printer.go | 3 ++- etcdctl/ctlv3/command/printer_fields.go | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/etcdctl/ctlv3/command/printer.go b/etcdctl/ctlv3/command/printer.go index 7f5e38c22..97aef54f8 100644 --- a/etcdctl/ctlv3/command/printer.go +++ b/etcdctl/ctlv3/command/printer.go @@ -233,11 +233,12 @@ func makeEndpointStatusTable(statusList []epStatus) (hdr []string, rows [][]stri } func makeEndpointHashKVTable(hashList []epHashKV) (hdr []string, rows [][]string) { - hdr = []string{"endpoint", "hash"} + hdr = []string{"endpoint", "hash", "revision"} for _, h := range hashList { rows = append(rows, []string{ h.Ep, fmt.Sprint(h.Resp.Hash), + fmt.Sprint(h.Resp.HashRevision), }) } return hdr, rows diff --git a/etcdctl/ctlv3/command/printer_fields.go b/etcdctl/ctlv3/command/printer_fields.go index df181f7e0..5e7d92584 100644 --- a/etcdctl/ctlv3/command/printer_fields.go +++ b/etcdctl/ctlv3/command/printer_fields.go @@ -212,6 +212,7 @@ func (p *fieldsPrinter) EndpointHashKV(hs []epHashKV) { p.hdr(h.Resp.Header) fmt.Printf("\"Endpoint\" : %q\n", h.Ep) fmt.Println(`"Hash" :`, h.Resp.Hash) + fmt.Println(`"HashRevision" :`, h.Resp.HashRevision) fmt.Println() } } From 3b50c60dd7202e74780d72442aed1a27c86be191 Mon Sep 17 00:00:00 2001 From: Benjamin Wang Date: Mon, 21 Nov 2022 08:41:55 +0800 Subject: [PATCH 2/5] changelog: cover the change of adding `HashRevision` into HashKVResponse Two chanages: 1. Add field `HashRevision` into `HashKVResponse`; 2. Display the new field when executing `etcdctl endpoint hash`. Signed-off-by: Benjamin Wang --- CHANGELOG/CHANGELOG-3.6.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG/CHANGELOG-3.6.md b/CHANGELOG/CHANGELOG-3.6.md index 4f52e9054..f74b41fe5 100644 --- a/CHANGELOG/CHANGELOG-3.6.md +++ b/CHANGELOG/CHANGELOG-3.6.md @@ -32,6 +32,7 @@ See [code changes](https://github.com/etcd-io/etcd/compare/v3.5.0...v3.6.0). - [Always print the raft_term in decimal](https://github.com/etcd-io/etcd/pull/13711) when displaying member list in json. - [Add one more field `storageVersion`](https://github.com/etcd-io/etcd/pull/13773) into the response of command `etcdctl endpoint status`. - Add [`--max-txn-ops`](https://github.com/etcd-io/etcd/pull/14340) flag to make-mirror command. +- Display [field `hash_revision`](https://github.com/etcd-io/etcd/pull/14812) for `etcdctl endpoint hash` command. ### etcdutl v3 @@ -64,6 +65,7 @@ See [code changes](https://github.com/etcd-io/etcd/compare/v3.5.0...v3.6.0). - Add [`etcd --experimental-compact-hash-check-enabled --experimental-compact-hash-check-time`](https://github.com/etcd-io/etcd/issues/14039) flags to support enabling reliable corruption detection on compacted revisions. - Add [Protection on maintenance request when auth is enabled](https://github.com/etcd-io/etcd/pull/14663). - Graduated [`--experimental-warning-unary-request-duration` to `--warning-unary-request-duration`](https://github.com/etcd-io/etcd/pull/14414). Note the experimental flag is deprecated and will be decommissioned in v3.7. +- Add [field `hash_revision` into `HashKVResponse`](https://github.com/etcd-io/etcd/pull/14537). ### etcd grpc-proxy From cd15507c65702acdc9dee5325e913a503d3e32a3 Mon Sep 17 00:00:00 2001 From: Benjamin Wang Date: Mon, 21 Nov 2022 09:21:31 +0800 Subject: [PATCH 3/5] test: enhance case TestEndpointHashKV to check both hash and hashRevision Signed-off-by: Benjamin Wang --- tests/common/endpoint_test.go | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/tests/common/endpoint_test.go b/tests/common/endpoint_test.go index 2d60e722e..d1dcb29d9 100644 --- a/tests/common/endpoint_test.go +++ b/tests/common/endpoint_test.go @@ -16,9 +16,12 @@ package common import ( "context" + "fmt" "testing" "time" + "github.com/stretchr/testify/require" + "go.etcd.io/etcd/tests/v3/framework/config" "go.etcd.io/etcd/tests/v3/framework/testutils" ) @@ -44,12 +47,30 @@ func TestEndpointHashKV(t *testing.T) { clus := testRunner.NewCluster(ctx, t) defer clus.Close() cc := testutils.MustClient(clus.Client()) - testutils.ExecuteUntil(ctx, t, func() { - _, err := cc.HashKV(ctx, 0) - if err != nil { - t.Fatalf("get endpoint hashkv error: %v", err) + + t.Log("Add some entries") + for i := 0; i < 10; i++ { + key := fmt.Sprintf("key-%d", i) + value := fmt.Sprintf("value-%d", i) + if err := cc.Put(ctx, key, value, config.PutOptions{}); err != nil { + t.Fatalf("count not put key %q, err: %s", key, err) } - }) + } + + t.Log("Check all members' Hash and HashRevision") + require.Eventually(t, func() bool { + resp, err := cc.HashKV(ctx, 0) + require.NoError(t, err, "failed to get endpoint hashkv: %v", err) + + require.Equal(t, 3, len(resp)) + if resp[0].HashRevision == resp[1].HashRevision && resp[0].HashRevision == resp[2].HashRevision { + require.Equal(t, resp[0].Hash, resp[1].Hash) + require.Equal(t, resp[0].Hash, resp[2].Hash) + return true + } + t.Logf("HashRevisions are not equal: [%d, %d, %d], retry...", resp[0].HashRevision, resp[1].HashRevision, resp[2].HashRevision) + return false + }, 5*time.Second, 200*time.Millisecond) } func TestEndpointHealth(t *testing.T) { From f2d765d247a6589cf1fe82aee2e28f69ebdc528d Mon Sep 17 00:00:00 2001 From: Benjamin Wang Date: Tue, 22 Nov 2022 06:10:00 +0800 Subject: [PATCH 4/5] etcdctl: update the examples for endpoint hashkv command in readme Signed-off-by: Benjamin Wang --- etcdctl/README.md | 69 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 57 insertions(+), 12 deletions(-) diff --git a/etcdctl/README.md b/etcdctl/README.md index 1a5a75da5..754a6d4fb 100644 --- a/etcdctl/README.md +++ b/etcdctl/README.md @@ -837,28 +837,73 @@ Prints a line of JSON encoding each endpoint URL and KV history hash. Get the hash for the default endpoint: ```bash -./etcdctl endpoint hashkv -# 127.0.0.1:2379, 1084519789 +./etcdctl endpoint hashkv --cluster +http://127.0.0.1:2379, 2064120424, 13 +http://127.0.0.1:22379, 2064120424, 13 +http://127.0.0.1:32379, 2064120424, 13 ``` Get the status for the default endpoint as JSON: ```bash -./etcdctl -w json endpoint hashkv -# [{"Endpoint":"127.0.0.1:2379","Hash":{"header":{"cluster_id":14841639068965178418,"member_id":10276657743932975437,"revision":1,"raft_term":3},"hash":1084519789,"compact_revision":-1}}] +./etcdctl endpoint hash --cluster -w json | jq +[ + { + "Endpoint": "http://127.0.0.1:2379", + "HashKV": { + "header": { + "cluster_id": 17237436991929494000, + "member_id": 9372538179322590000, + "revision": 13, + "raft_term": 2 + }, + "hash": 2064120424, + "compact_revision": -1, + "hash_revision": 13 + } + }, + { + "Endpoint": "http://127.0.0.1:22379", + "HashKV": { + "header": { + "cluster_id": 17237436991929494000, + "member_id": 10501334649042878000, + "revision": 13, + "raft_term": 2 + }, + "hash": 2064120424, + "compact_revision": -1, + "hash_revision": 13 + } + }, + { + "Endpoint": "http://127.0.0.1:32379", + "HashKV": { + "header": { + "cluster_id": 17237436991929494000, + "member_id": 18249187646912140000, + "revision": 13, + "raft_term": 2 + }, + "hash": 2064120424, + "compact_revision": -1, + "hash_revision": 13 + } + } +] ``` Get the status for all endpoints in the cluster associated with the default endpoint: ```bash -./etcdctl -w table endpoint --cluster hashkv -+------------------------+------------+ -| ENDPOINT | HASH | -+------------------------+------------+ -| http://127.0.0.1:2379 | 1084519789 | -| http://127.0.0.1:22379 | 1084519789 | -| http://127.0.0.1:32379 | 1084519789 | -+------------------------+------------+ +$ ./etcdctl endpoint hash --cluster -w table ++------------------------+------------+----------+ +| ENDPOINT | HASH | REVISION | ++------------------------+------------+----------+ +| http://127.0.0.1:2379 | 2064120424 | 13 | +| http://127.0.0.1:22379 | 2064120424 | 13 | +| http://127.0.0.1:32379 | 2064120424 | 13 | ++------------------------+------------+----------+ ``` ### ALARM \ From 9a7f9609d6cae6abd966ab171bbb0ae02b4c4df5 Mon Sep 17 00:00:00 2001 From: Benjamin Wang Date: Fri, 25 Nov 2022 18:59:49 +0800 Subject: [PATCH 5/5] etcdctl: changed 'revision' to 'hash_revision' in hashkv table output Signed-off-by: Benjamin Wang --- etcdctl/README.md | 14 +++++++------- etcdctl/ctlv3/command/printer.go | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/etcdctl/README.md b/etcdctl/README.md index 754a6d4fb..39a5c56bc 100644 --- a/etcdctl/README.md +++ b/etcdctl/README.md @@ -897,13 +897,13 @@ Get the status for all endpoints in the cluster associated with the default endp ```bash $ ./etcdctl endpoint hash --cluster -w table -+------------------------+------------+----------+ -| ENDPOINT | HASH | REVISION | -+------------------------+------------+----------+ -| http://127.0.0.1:2379 | 2064120424 | 13 | -| http://127.0.0.1:22379 | 2064120424 | 13 | -| http://127.0.0.1:32379 | 2064120424 | 13 | -+------------------------+------------+----------+ ++------------------------+-----------+---------------+ +| ENDPOINT | HASH | HASH REVISION | ++------------------------+-----------+---------------+ +| http://127.0.0.1:2379 | 784522900 | 16 | +| http://127.0.0.1:22379 | 784522900 | 16 | +| http://127.0.0.1:32379 | 784522900 | 16 | ++------------------------+-----------+---------------+ ``` ### ALARM \ diff --git a/etcdctl/ctlv3/command/printer.go b/etcdctl/ctlv3/command/printer.go index 97aef54f8..7cc1b887b 100644 --- a/etcdctl/ctlv3/command/printer.go +++ b/etcdctl/ctlv3/command/printer.go @@ -233,7 +233,7 @@ func makeEndpointStatusTable(statusList []epStatus) (hdr []string, rows [][]stri } func makeEndpointHashKVTable(hashList []epHashKV) (hdr []string, rows [][]string) { - hdr = []string{"endpoint", "hash", "revision"} + hdr = []string{"endpoint", "hash", "hash_revision"} for _, h := range hashList { rows = append(rows, []string{ h.Ep,