Skip to content

Instantly share code, notes, and snippets.

@Vagabond
Created May 10, 2011 21:00
Show Gist options
  • Save Vagabond/965376 to your computer and use it in GitHub Desktop.
Save Vagabond/965376 to your computer and use it in GitHub Desktop.
Riak delete bug bz://260
-module(delete_bug).
-compile([export_all]).
start(N) ->
{ok, C} = riak:local_client(),
C:set_bucket(<<"b">>, [{allow_mult, false}]),
loop(N, C).
start_pbc(N) ->
{ok, RC} = riakc_pb_socket:start_link("127.0.0.1", 8087),
loop_pbc(N, RC).
start_http(N) ->
inets:start(),
loop_http(N).
clean() ->
{ok, C} = riak:local_client(),
C:delete(<<"b">>, <<"k">>).
loop(0, _C) ->
ok;
loop(N, C) ->
Obj = riak_object:new(<<"b">>,<<"k">>,term_to_binary(N)),
_NObj = case C:get(<<"b">>,<<"k">>, [deletedvclock]) of
{error, {deleted, VC}} ->
io:format("putting with vclock~n"),
riak_object:set_vclock(Obj, VC);
{error, notfound} ->
Obj;
{ok, _, _} ->
Obj
end,
io:format("put~n"),
ok = C:put(_NObj),
io:format("get~n"),
{ok, _Obj1} = C:get(<<"b">>, <<"k">>),
%riak_object:get_metadata(Obj1),
%N = binary_to_term(riak_object:get_value(Obj1)),
io:format("delete~n"),
ok = C:delete(<<"b">>,<<"k">>),
loop(N-1, C).
loop_pbc(0, _RC) ->
ok;
loop_pbc(N, RC) ->
Obj = riakc_obj:new(<<"b">>,<<"k">>,term_to_binary(N)),
_NObj = case riakc_pb_socket:get(RC, <<"b">>,<<"k">>, [deletedvclock]) of
{error, notfound, VC} ->
io:format("putting with vclock~n"),
riakc_obj:set_vclock(Obj, VC);
{error, notfound} ->
%io:format("not putting with vclock~n"),
Obj;
{ok, _} ->
Obj
end,
io:format("put~n"),
ok = riakc_pb_socket:put(RC, _NObj),
io:format("get~n"),
{ok, _Obj1} = riakc_pb_socket:get(RC, <<"b">>, <<"k">>),
io:format("delete~n"),
ok = riakc_pb_socket:delete(RC, <<"b">>,<<"k">>),
loop_pbc(N-1, RC).
loop_http(0) ->
ok;
loop_http(N) ->
PutHeaders = case httpc:request(get, {"http://127.0.0.1:8098/riak/b/k", []}, [], []) of
{ok, {{_, 404, _}, Headers, _}} ->
case lists:keyfind("x-riak-vclock", 1, Headers) of
{_, VClock} ->
io:format("putting with vclock ~p~n", [VClock]),
[{"X-Riak-Vclock", VClock}];
false ->
%io:format("NOT putting with vclock~n", []),
[]
end
end,
io:format("put~n"),
{ok, {{_, 204, _}, _, _}} = httpc:request(post, {"http://127.0.0.1:8098/riak/b/k", PutHeaders, "text/plain", integer_to_list(N)}, [], []),
io:format("get~n"),
Body = integer_to_list(N),
{ok, {{_, 200, _}, _, Body}} = httpc:request(get, {"http://127.0.0.1:8098/riak/b/k", []}, [], []),
io:format("delete~n"),
{ok, {{_, 204, _}, _, _}} = httpc:request(delete, {"http://127.0.0.1:8098/riak/b/k", []}, [], []),
loop_http(N-1).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment