-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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
etcdctl: fix mk command with PrevNoExist #3685
Conversation
yichen says:
Will change it to use |
938abeb
to
865c9c5
Compare
Yes, in my local machine, I ran the following command:
And use
I changed the commit message to be more clearer. Please let me know if we need more tests. |
865c9c5
to
7fe6bdb
Compare
// By passing client.PrevNoExist the Set method checks if | ||
// the key had existed previously, and returns error when | ||
// it tries to overwrite the key, which is how mk command | ||
// is supposed to work. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need to mention PrevIgnore
here because we don't use PrevIgnore
here.
It would be better if you could make the second sentence more concrete.
7fe6bdb
to
0acc025
Compare
I agree. I made some changes on comments. Please let me know if you have any other feedback. |
0acc025
to
e0ac8e6
Compare
@@ -51,7 +51,9 @@ func mkCommandFunc(c *cli.Context, ki client.KeysAPI) { | |||
ttl := c.Int("ttl") | |||
|
|||
ctx, cancel := contextWithTotalTimeout(c) | |||
resp, err := ki.Set(ctx, key, value, &client.SetOptions{TTL: time.Duration(ttl) * time.Second, PrevExist: client.PrevIgnore}) | |||
// PrevNoExist means that the Node must not exist. | |||
// Set method returns error if the key already exists. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set method returns error if the key already exists.
This sentence is not true if Set method doesn't use PrevNoExist.
Also the comments miss the part that why you explain how Set returns error here.
e0ac8e6
to
af8f4c7
Compare
@yichengq Sorry. I should have made it clear that the Set method in this case. Is it clear now?
|
@@ -51,7 +51,9 @@ func mkCommandFunc(c *cli.Context, ki client.KeysAPI) { | |||
ttl := c.Int("ttl") | |||
|
|||
ctx, cancel := contextWithTotalTimeout(c) | |||
resp, err := ki.Set(ctx, key, value, &client.SetOptions{TTL: time.Duration(ttl) * time.Second, PrevExist: client.PrevIgnore}) | |||
// Since PrevNoExist means that the Node must not exist, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
must not exist previously
af8f4c7
to
c3cf294
Compare
This attempts to fix etcd-io#3676. `PrevNoExist` checks if the key previously exists and if so, it returns an error, which is how `mk` command is supposed to work. The previous code ignores the previous key and overwrites with the later value. /cc @yichengq
c3cf294
to
1dab7e8
Compare
This is the reason I think one would need use |
The comment is a little verbosal IMO, but it is good enough. 👍 LGTM. Thanks for fixing it! |
etcdctl: fix mk command with PrevNoExist
Thanks! |
This attempts to fix #3676.
PrevNoExist
checks if the key previously exists and if so, it returns an error, which is howmk
command is supposed to work. The previous code ignores the previous key and overwrites with the later value./cc @yichengq