-
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
*: combine Watch, WatchPrefix with variadic function #4602
Conversation
rev int64 | ||
|
||
// for watch | ||
prefix string |
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.
I think this should use end
instead of having a separate prefix field; watch can check the op for if end == nil || deepEqual(end, expectedPrefix)
and throw an error if it's something else.
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.
Oh ok. Will fix. Thanks!
93aa1e6
to
e95295d
Compare
/cc @heyitsanthony @xiang90 PTAL.
Thanks! |
func opWatch(key string, opts ...OpOption) Op { | ||
ret := Op{t: tRange, key: []byte(key)} | ||
ret.applyOpts(opts) | ||
switch { |
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.
can you pull getPrefix([]byte) []byte
out of WithPrefix()
so this can check
case ret.end != nil && reflect.DeepEqual(end, getPrefix(ret.key)): panic("only supports single keys or prefixes")
?
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.
Sure. Will add that. Thanks.
lgtm aside from the missing prefix checking, thanks! |
@heyitsanthony Just added that function and check. Thanks! Will merge after green lights. |
test failed. will take a look. |
ret.applyOpts(opts) | ||
switch { | ||
case ret.end != nil && !reflect.DeepEqual(ret.end, getPrefix(ret.key)): | ||
panic("only supports single keys or prefixes") |
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.
@heyitsanthony Could you check this part? ret.end != nil && !reflect.DeepEqual(ret.end, getPrefix(ret.key))
?
So if someone specifies WithPrefix
in Watch
api, end
will be non nil
. And it should be equal to getPrefix(ret.key)
. So I think it should be !reflect.DeepEqual(ret.end, getPrefix(ret.key))
, not reflect.DeepEqual(ret.end, getPrefix(ret.key))
. Test failed with case ret.end != nil && reflect.DeepEqual(end, getPrefix(ret.key))
.
Thanks.
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.
Yes, you're right. I accidentally dropped the !
.
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.
Thanks! Merging since tests passed.
*: combine Watch, WatchPrefix with variadic function
For #4598.