From 17a5780d0c8bbd07bf2bd654500f3ea831fd652c Mon Sep 17 00:00:00 2001 From: Bryan Fink Date: Thu, 8 Jul 2010 10:51:38 -0400 Subject: [PATCH] use the returnbody option of riak_client:put/5 instead of riak_object:apply_updates/1 --- include/luwak.hrl | 4 +++- src/luwak_block.erl | 2 +- src/luwak_file.erl | 19 +++++++------------ src/luwak_tree.erl | 2 +- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/include/luwak.hrl b/include/luwak.hrl index 187dad5..3275e3d 100644 --- a/include/luwak.hrl +++ b/include/luwak.hrl @@ -6,6 +6,8 @@ -define(BLOCK_DEFAULT, 1000000). -define(HASH_LEN, 512). +-define(TIMEOUT_DEFAULT, 60000). + -record(split, {head=[], midhead=[], middle=[], midtail=[], tail=[]}). -ifndef(EUNIT_HRL). @@ -18,4 +20,4 @@ -define(debugFmt(S, As), ok). -endif. --endif. \ No newline at end of file +-endif. diff --git a/src/luwak_block.erl b/src/luwak_block.erl index 58cd0e2..653c93c 100644 --- a/src/luwak_block.erl +++ b/src/luwak_block.erl @@ -13,7 +13,7 @@ create(Riak, Data) -> {type, block} ], Obj = riak_object:new(?N_BUCKET, skerl:hexhash(?HASH_LEN, Data), Value), - {Riak:put(Obj,2), Obj}. + Riak:put(Obj, 2, 2, ?TIMEOUT_DEFAULT, [{returnbody, true}]). data(Val) when is_list(Val) -> proplists:get_value(data, Val); diff --git a/src/luwak_file.erl b/src/luwak_file.erl index 058f825..332ad85 100644 --- a/src/luwak_file.erl +++ b/src/luwak_file.erl @@ -57,8 +57,7 @@ create(Riak, Name, Properties, Attributes) when is_binary(Name) -> {root, undefined} ], Obj = riak_object:new(?O_BUCKET, Name, Value), - ok = Riak:put(Obj, 2), - {ok, Obj}. + Riak:put(Obj, 2, 2, ?TIMEOUT_DEFAULT, [{returnbody, true}]). %% @spec set_attributes(Riak :: riak(), Obj :: luwak_file(), %% Attributes :: dict()) @@ -67,9 +66,8 @@ create(Riak, Name, Properties, Attributes) when is_binary(Name) -> set_attributes(Riak, Obj, Attributes) -> Value = lists:keyreplace(attributes, 1, riak_object:get_value(Obj), {attributes, Attributes}), - Obj2 = riak_object:apply_updates(riak_object:update_value(Obj, Value)), - ok = Riak:put(Obj2, 2), - {ok, Obj2}. + Obj2 = riak_object:update_value(Obj, Value), + Riak:put(Obj2, 2, 2, ?TIMEOUT_DEFAULT, [{returnbody, true}]). %% @spec get_attributes(Obj :: luwak_file()) -> dict() %% @doc Gets the attribute dictionary from the file handle. @@ -140,9 +138,8 @@ update_root(Riak, Obj, NewRoot) -> ObjVal2 = lists:keyreplace(ancestors, 1, ObjVal1, {ancestors, [OldRoot|Ancestors]}), ObjVal3 = lists:keyreplace(root, 1, ObjVal2, {root, NewRoot}), - Obj2 = riak_object:apply_updates(riak_object:update_value(Obj, ObjVal3)), - ok = Riak:put(Obj2, 2), - {ok, Obj2}. + Obj2 = riak_object:update_value(Obj, ObjVal3), + Riak:put(Obj2, 2, 2, ?TIMEOUT_DEFAULT, [{returnbody, true}]). %% @private update_checksum(Riak, Obj, ChecksumFun) -> @@ -151,10 +148,8 @@ update_checksum(Riak, Obj, ChecksumFun) -> ObjVal1 = riak_object:get_value(Obj), ObjVal2 = lists:keyreplace(checksum, 1, ObjVal1, {checksum, {sha1, ChecksumFun()}}), - Obj2 = riak_object:apply_updates(riak_object:update_value(Obj, - ObjVal2)), - ok = Riak:put(Obj2, 2), - {ok, Obj2}; + Obj2 = riak_object:update_value(Obj, ObjVal2), + Riak:put(Obj2, 2, 2, ?TIMEOUT_DEFAULT, [{retunbody, true}]); _ -> {ok, Obj} end. diff --git a/src/luwak_tree.erl b/src/luwak_tree.erl index 2590a8b..97b98ad 100644 --- a/src/luwak_tree.erl +++ b/src/luwak_tree.erl @@ -310,7 +310,7 @@ create_node(Riak, Children) -> N = #n{created=now(),children=Children}, Name = skerl:hexhash(?HASH_LEN, term_to_binary(Children)), Obj = riak_object:new(?N_BUCKET, Name, N), - {Riak:put(Obj, 2), Obj}. + Riak:put(Obj, 2, 2, ?TIMEOUT_DEFAULT, [{returnbody, true}]). truncate(List) when is_list(List) -> lists:map(fun({Data,Length}) -> {truncate(Data),Length} end, List);