Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: Add etcdutl snapshot hashkv command #15965

Merged
merged 1 commit into from
Jun 3, 2024
Merged

Conversation

cenkalti
Copy link
Member

@cenkalti cenkalti commented May 26, 2023

Fixes #15061

% bin/etcdctl endpoint hashkv -w json | jq
[
  {
    "Endpoint": "127.0.0.1:2379",
    "HashKV": {
      "header": {
        "cluster_id": 14841639068965180000,
        "member_id": 10276657743932975000,
        "revision": 214,
        "raft_term": 17
      },
      "hash": 902327963,
      "compact_revision": 150,
      "hash_revision": 214
    }
  }
]
% bin/etcdutl snapshot hashkv default.etcd/member/snap/db -w json | jq
{
  "hash": 902327963,
  "hashRevision": 214,
  "compactRevision": 150
}

@cenkalti cenkalti requested review from ptabor and ahrtr May 26, 2023 19:58
@cenkalti cenkalti requested a review from chaochn47 May 26, 2023 19:59
@cenkalti cenkalti force-pushed the hashkv branch 2 times, most recently from 5eb6ff6 to 2b5fffb Compare May 26, 2023 20:06
Copy link
Member

@jmhbnz jmhbnz left a comment

Choose a reason for hiding this comment

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

Nice work @cenkalti.

Should we also add a quick segment of documentation to the README.md at https://github.com/etcd-io/etcd/tree/main/etcdutl?

@cenkalti
Copy link
Member Author

@jmhbnz Added.

Copy link
Member

@jmhbnz jmhbnz left a comment

Choose a reason for hiding this comment

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

LGTM - Thanks @cenkalti.

Note at some point I think we need to take some of the README.md content and put together some overall human friendly documentation for etcdutl on the website. Something similar to https://etcd.io/docs/v3.5/dev-guide/interacting_v3. Perhaps named Interacting with etcd data files. A separate issue than this pr though.

etcdutl/etcdutl/printer.go Outdated Show resolved Hide resolved
etcdutl/etcdutl/snapshot_command.go Outdated Show resolved Hide resolved
etcdutl/etcdutl/snapshot_command.go Outdated Show resolved Hide resolved
etcdutl/etcdutl/snapshot_command.go Outdated Show resolved Hide resolved
Copy link
Member

@ahrtr ahrtr left a comment

Choose a reason for hiding this comment

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

Please resolve the review comments.

@@ -48,6 +49,7 @@ func NewSnapshotCommand() *cobra.Command {
}
cmd.AddCommand(NewSnapshotRestoreCommand())
cmd.AddCommand(newSnapshotStatusCommand())
cmd.AddCommand(newSnapshotHashKVCommand())
Copy link
Member

Choose a reason for hiding this comment

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

Probably it makes more sense to add a separate command something like etcdutl hashkv <filename> [flags], because it isn't necessary related to a snapshot.

@stale
Copy link

stale bot commented Sep 17, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 21 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Sep 17, 2023
@stale stale bot removed the stale label Jan 16, 2024
@cenkalti
Copy link
Member Author

/retest

@jmhbnz
Copy link
Member

jmhbnz commented Mar 28, 2024

Hey @cenkalti - We highlighted this older pr during the sig-etcd triage meeting today. It would be great to get this tidied up and merged given we already had partial maintainer approval.

Can you please rebase and address the remaining comments? Thanks! 🙏🏻

@cenkalti
Copy link
Member Author

I'll do it this weekend.

@cenkalti cenkalti force-pushed the hashkv branch 3 times, most recently from 2de11cb to 608d191 Compare March 30, 2024 14:32
@cenkalti
Copy link
Member Author

Rebased. Ready to merge.

@jmhbnz jmhbnz requested a review from ahrtr March 30, 2024 19:59
Comment on lines 44 to 46
if len(args) != 1 {
err := fmt.Errorf("hashkv requires exactly one argument")
cobrautl.ExitWithError(cobrautl.ExitBadArgs, err)
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated.

@ahrtr
Copy link
Member

ahrtr commented May 23, 2024

We also need to add a changelog item, but it's OK to add it in a separate PR.

cc @jmhbnz @ivanvc @ArkaSaha30 to take a second look.

Copy link
Member

@ivanvc ivanvc left a comment

Choose a reason for hiding this comment

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

This PR is looking good. I left two minor comments.

@@ -111,7 +111,7 @@ type hashStorage struct {
lg *zap.Logger
}

func newHashStorage(lg *zap.Logger, s *store) *hashStorage {
func NewHashStorage(lg *zap.Logger, s *store) *hashStorage {
Copy link
Member

Choose a reason for hiding this comment

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

This (now) exported function returns an unexported struct. According to golangci-lint (and a linter rule we still need to enable), this is not a good practice. Refer to golang/lint#210.

However, HashStorage is already defined as the interface. So, addressing this may require renaming either the interface or the struct 🤔. This may open a discussion rather than an immediate action item.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated to return the interface.

CompactRevision int64 `json:"compactRevision"`
}

func calculateHashKV(dbPath string, rev int64) (ds HashKV, err error) {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: I don't think this function benefits from defining named return values. ds is not used, and err is defined in line 70.

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed return var names.

Signed-off-by: Cenk Alti <cenkalti@gmail.com>

Apply suggestions from code review

Co-authored-by: Benjamin Wang <benjamin.wang@broadcom.com>
Copy link
Member

@ahrtr ahrtr left a comment

Choose a reason for hiding this comment

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

LGTM

Thanks. Please also add a changelog item for 3.6 in a separate PR.

Copy link
Member

@ivanvc ivanvc left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks, @cenkalti.

@ahrtr ahrtr merged commit dc8510c into etcd-io:main Jun 3, 2024
46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

Enhance etcdutl to calculate hash of the data up to a given rev
6 participants