Add binary format for counters #563

Merged
merged 4 commits into from May 24, 2013

Projects

None yet

2 participants

Contributor

May not be optimal, but adds Tag and Vsn fields to make upgrade / downgrade simpler in future.

@jrwest jrwest and 1 other commented on an outdated diff May 24, 2013
src/riak_kv_counter.erl
+from_binary(<<?TAG:8/integer,?V1_VERS:8/integer,CounterBin/binary>>) ->
+ riak_kv_pncounter:from_binary(CounterBin).
+
+%% ===================================================================
+%% EUnit tests
+%% ===================================================================
+-ifdef(TEST).
+
+roundtrip_bin_test() ->
+ PN = riak_kv_pncounter:new(),
+ PN1 = riak_kv_pncounter:update({increment, 2}, <<"a1">>, PN),
+ PN2 = riak_kv_pncounter:update({decrement, 1000000000000000000000000}, douglas_Actor, PN1),
+ PN3 = riak_kv_pncounter:update(increment, [{very, ["Complex"], <<"actor">>}, honest], PN2),
+ PN4 = riak_kv_pncounter:update(decrement, "another_acotr", PN3),
+ Bin = to_binary(PN4),
+ ?debugFmt("Bin ~p t2b ~p", [byte_size(Bin),
jrwest
jrwest May 24, 2013 Contributor

missed a debug print. although i found it kind of useful to quickly verify the size difference.

russelldb
russelldb May 24, 2013 Contributor

oops, actually, that test does nothing, except print that size diff

Wait, it tests it too, ignore me, it's late for me.

Contributor
jrwest commented May 24, 2013

riak_test/eqc/eunit tests still pass, booted it up and used the http api a bit, all looks good. A debug print (which I commented on) shows a few bytes of savings and having versioned binaries is always better. +1!

@russelldb russelldb merged commit 1e32b2a into rdb-kv-counter May 24, 2013
@seancribbs seancribbs deleted the rdb-kv-counter_bin branch Apr 1, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment