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

Txn compare with version value is not functioning correctly. #10113

Closed
sanamsarath opened this issue Sep 21, 2018 · 7 comments
Closed

Txn compare with version value is not functioning correctly. #10113

sanamsarath opened this issue Sep 21, 2018 · 7 comments

Comments

@sanamsarath
Copy link

sanamsarath commented Sep 21, 2018

etcd version 3.3.2

I have added and modified a key "foo" couple of times, current version value is 3

[root@db-etcd-5f6775c7c8-r2gts bin]# ./etcdctl get foo -w json
{"header":{"cluster_id":7283584411907800223,"member_id":7633025399990538973,"revision":17683,"raft_term":2},"kvs":[{"key":"Zm9v","create_revision":11291,"mod_revision":13112,"version":3,"value":"YmFy"}],"count":1}
[root@db-etcd-5f6775c7c8-r2gts bin]# 

then I tried txn request with curl command to get the details of foo and compare failed (base64 of 3 = Mw==)

[root@db-etcd-5f6775c7c8-r2gts bin]# curl -L http://127.0.0.1:2379/v3beta/kv/txn -X POST -d '{"compare":[{"target":"VERSION","result":"EQUAL","key":"Zm9v","value":"Mw=="}],"success":[{"requestRange":{"key":"Zm9v"}}]}'
{"header":{"cluster_id":"7283584411907800223","member_id":"7633025399990538973","revision":"17693","raft_term":"2"}}[root@db-etcd-5f6775c7c8-r2gts bin]# 

and the same compare is working when I tried version != 3:

[root@db-etcd-5f6775c7c8-r2gts bin]# curl -L http://127.0.0.1:2379/v3beta/kv/txn -X POST -d '{"compare":[{"target":"VERSION","result":"NOT_EQUAL","key":"Zm9v","value":"Mw=="}],"success":[{"requestRange":{"key":"Zm9v"}}]}'
{"header":{"cluster_id":"7283584411907800223","member_id":"7633025399990538973","revision":"17701","raft_term":"2"},"succeeded":true,"responses":[{"response_range":{"header":{"revision":"17701"},"kvs":[{"key":"Zm9v","create_revision":"11291","mod_revision":"13112","version":"3","value":"YmFy"}],"count":"1"}}]}[root@db-etcd-5f6775c7c8-r2gts bin]#
@sanamsarath
Copy link
Author

@mangoslicer this looks similar to grpc-gateway: txn marshaling broken #7889 , do you have any idea??

@hexfusion
Copy link
Contributor

@sanamsarath version has a little different syntax:

curl -L http://127.0.0.1:2379/v3beta/kv/txn -X POST -d '{"compare":[{"version":3,"result":"EQUAL","target":"VERSION","key":"Zm9v"}],"success":[{"requestRange":{"key":"Zm9v"}}]}'
{"header":{"cluster_id":"14841639068965178418","member_id":"10276657743932975437","revision":"4","raft_term":"3"},"succeeded":true,"responses":[{"response_range":{"header":{"revision":"4"},"kvs":[{"key":"Zm9v","create_revision":"2","mod_revision":"4","version":"3","value":"Mw=="}],"count":"1"}}]}

@sanamsarath
Copy link
Author

@hexfusion I have tried first the way you mentioned but it is throwing an error.

[root@db-etcd-54876f9ddc-gmtmm bin]# curl -L http://127.0.0.1:2379/v3beta/kv/txn -X POST -d '{"compare":[{"target":"VERSION","result":"EQUAL","key":"Zm9v","value":1}],"success":[{"requestRange":{"key":"Zm9v"}}]}'
{"error":"json: cannot unmarshal number into Go value of type []uint8","code":3}[root@db-etcd-54876f9ddc-gmtmm bin]# 
[root@db-etcd-54876f9ddc-gmtmm bin]# 

@hexfusion
Copy link
Contributor

@sanamsarath s/value/version

@sanamsarath
Copy link
Author

[root@db-etcd-54876f9ddc-gmtmm bin]# ./etcd -version
etcd Version: 3.3.2+git
Git SHA: GitNotFound
Go Version: go1.10.3
Go OS/Arch: linux/amd64

@hexfusion
Copy link
Contributor

sorry I was not clear

You need to change "value":1 to "version":1 as I have in my example.

@sanamsarath
Copy link
Author

@hexfusion Thanks, it helped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants