test_and_set Operation : Status Fail -> Key changed

29 views
Skip to first unread message

Alexandre Beslic

unread,
Dec 17, 2014, 1:08:02 PM12/17/14
to scal...@googlegroups.com
Hi,

I'm a bit confused about the test_and_set operation.

I'm writing a Go binding to Scalaris but I fail to succeed at atomically incrementing a value doing a test_and_set operation.

For testing purpose using curl I first write the value inside a Transaction:

$ curl -H "Content-Type: application/json" -d '{"id":1,"method":"req_list","params":[[{"write":{"genId":{"type":"as_is","value":1}}},{"commit":""}]]}' http://192.168.42.100:8000/api/tx.yaws
{"result":{"tlog":"g2o=","results":[{"status":"ok"},{"status":"ok"}]},"id":1,"jsonrpc":"2.0"}

If I read the value back I get the right result:

$ curl -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"read","params":["genId"],"id":1}' http://192.168.42.100:8000/api/tx.yaws
{"result":{"status":"ok","value":{"type":"as_is","value":1}},"id":1,"jsonrpc":"2.0"}

But if I try to do a test_and_set operation inside a Transaction to increment the counter I get the key_changed error:

$ curl -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","id":1,"method":"req_list","params":[[{"test_and_set":{"key":"genId","old":{"type":"as_is","value":1},"new":{"type":"as_is","value":2}}},{"commit":""}]]}' http://192.168.42.100:8000/api/tx.yaws
{"result":{"tlog":"g2o=","results":[{"status":"fail","reason":"key_changed","value":{"type":"as_is","value":1}},{"status":"fail","reason":"abort","keys":["genId"]}]},"id":1,"jsonrpc":"2.0"}


I'm probably missing something obvious but I'm a bit confused about the error as the value I give to "old" is the same as the expected value inside the store at the given key.

Thank you.

Nico Kruber

unread,
Jan 15, 2015, 4:14:54 PM1/15/15
to scal...@googlegroups.com
Sorry for the long delay,
this was a bug on our side and is fixed by r7316. Apparently, there is no unit
test for this (yet) :(

How far is your Go binding going? We'd be happy to include it into the
official code base if you like.


Regards
Nico Kruber

On Wednesday 17 Dec 2014 10:08:02 Alexandre Beslic wrote:
> Hi,
>
> I'm a bit confused about the test_and_set operation.
>
> I'm writing a Go binding to Scalaris but I fail to succeed at atomically
> incrementing a value doing a *test_and_set* operation.
>
> For testing purpose using curl I first *write* the value inside a
> Transaction:
>
> *$* curl -H "Content-Type: application/json" -d
> '{"id":1,"method":"req_list","params":[[{"write":{"genId":{"type":"as_is","v
> alue":1}}},{"commit":""}]]}' http://192.168.42.100:8000/api/tx.yaws
> {"result":{"tlog":"g2o=","results":[{"status":"ok"},{"status":"ok"}]},"id":1
> ,"jsonrpc":"2.0"}
>
> If I *read* the value back I get the right result:
>
> *$* curl -H "Content-Type: application/json" -d
> '{"jsonrpc":"2.0","method":"read","params":["genId"],"id":1}'
> http://192.168.42.100:8000/api/tx.yaws
> {"result":{"status":"ok","value":{"type":"as_is","value":1}},"id":1,"jsonrpc
> ":"2.0"}
>
> But if I try to do a *test_and_set* operation inside a Transaction to
> increment the counter I get the *key_changed error*:
>
> *$* curl -H "Content-Type: application/json" -d
signature.asc
Reply all
Reply to author
Forward
0 new messages