I'm looking for some clarification on the behavior clientv3.KV.Get() with regards to the order of OpOption arguments.
I noticed that the following queries return different results:.
// (1)
cli.Get(ctx, "/foo", etcd.WithFromKey(), etcd.WithPrefix())
// (2)
cli.Get(ctx, "/foo", etcd.WithPrefix(), etcd.WithFromKey())
More precisely, (1) correctly returns every key within the /foo prefix; whereas (2) doesn't respect the prefix, and returns every key after /foo.
If this is intentional, I think it could be documented a little better. If it's not intentional, let me know, and I can try to provide a more reproducible example.
Thanks!
i do not think this is intentional behavior. can you provide a reproduce? better if you can look into the code, and help us fix it.
https://github.com/etcd-io/etcd/blob/e8b940f268a80c14f7082589f60cbfd3de531d12/clientv3/op.go#L393-L395
https://github.com/etcd-io/etcd/blob/e8b940f268a80c14f7082589f60cbfd3de531d12/clientv3/op.go#L385-L391
These two opts would be independent of each other vs used together. Seems like you would use WithFromKey() or WithPrefix() along with say WithRev() or WithSerializable. But yeah maybe this should not be the case? I think we are just ranging the opts so you get the last one on the response?
withfrom key is probably not smart enough to pick up the value passed in by with prefix.
Yeah it seems these options are not meant to be used together, since both WithFromKey() and WithPrefix() both set the op.end value, so whichever is used last will be the one that takes effect.
etcdctl throws expected error that --prefix` and `--from-key` cannot be set at the same time, choose one
https://github.com/etcd-io/etcd/blob/master/etcdctl/ctlv3/command/get_command.go#L82
I am investigating but I guess we should provide a similar message when these two functions are called outside etcdctl as in this issue?
Most helpful comment
withfrom key is probably not smart enough to pick up the value passed in by with prefix.