Skip to content

Commit

Permalink
change the put_range method to take a file object instead of a name
Browse files Browse the repository at this point in the history
  • Loading branch information
Cliff Moon committed May 26, 2010
1 parent d4a5a8c commit 541f914
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
13 changes: 5 additions & 8 deletions apps/luwak/src/luwak_io.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,19 @@

-export([put_range/4, get_range/4, truncate/3]).

put_range(Riak, Name, Start, Data) ->
case luwak_obj:get(Riak, Name) of
{ok, File} -> internal_put_range(Riak, File, Start, Data);
Err -> Err
end.
put_range(Riak, File, Start, Data) ->
internal_put_range(Riak, File, Start, Data).

get_range(Riak, Name, Start, Length) ->
get_range(Riak, File, Start, Length) ->
ok.

truncate(Riak, Name, Start) ->
truncate(Riak, File, Start) ->
ok.


%%==============================================
%% internal api
%%==============================================

internal_put_range(Riak, File, Start, Data) ->
BlockSize = luwak_obj:get_property(File, block_size),
BlockAlignedStart = Start - (Start rem BlockSize),
Expand Down
2 changes: 1 addition & 1 deletion apps/luwak/src/luwak_obj.erl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
-include_lib("luwak/include/luwak.hrl").

%% @spec create(Riak :: riak(), Name :: binary(), Attributes :: dict())
%% -> {ok, }
%% -> {ok, File :: file()} | {error, Reason}
create(Riak, Name, Attributes) when is_binary(Name) ->
BlockSize = case dict:find(block_size, Attributes) of
{ok, V} -> V;
Expand Down
2 changes: 1 addition & 1 deletion apps/luwak/test/luwak_io_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
simple_put_range_test() ->
test_helper:riak_test(fun(Riak) ->
{ok, File} = luwak_obj:create(Riak, <<"file1">>, dict:store(block_size, 5, dict:new())),
{ok, Written, _} = luwak_io:put_range(Riak, <<"file1">>, 0, <<"fuckyourcouch">>),
{ok, Written, _} = luwak_io:put_range(Riak, File, 0, <<"fuckyourcouch">>),
Hash1 = <<"4622b193a65e6f2a7873b6bef7e3b0cf18867f687e48f40fd9eabf840d5f0ebbd65bfff586e5c38ba50e473516e8f270b6687a1f271586baf648a38aa489dd91">>,
Hash2 = <<"08d5f211d13a9fb1e9b6902771b80459fedbb9e138b96d7a6dc3b92ad87997d24b65cc1a8594cc14b226cd511acf03eb3f4b24c7b67d270665d5bf5cb43f8fa6">>,
Hash3 = <<"6f01ab53f4498ccfa5de27d9fa1fd1aa3c088958588db410bc35055012e6ed2795c39d8abe454402062436434b15acc78baddb016c370cd445579401562ea316">>,
Expand Down
16 changes: 8 additions & 8 deletions apps/luwak/test/luwak_tree_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ create_simple_tree_test() ->
{ok, File} = luwak_obj:create(Riak, <<"file1">>,
dict:store(tree_order, 4,
dict:store(block_size, 5, dict:new()))),
{ok, Written, File2} = luwak_io:put_range(Riak, <<"file1">>, 0, <<"fuckyourcouch">>),
{ok, Written, File2} = luwak_io:put_range(Riak, File, 0, <<"fuckyourcouch">>),
BHash1 = <<"4622b193a65e6f2a7873b6bef7e3b0cf18867f687e48f40fd9eabf840d5f0ebbd65bfff586e5c38ba50e473516e8f270b6687a1f271586baf648a38aa489dd91">>,
BHash2 = <<"08d5f211d13a9fb1e9b6902771b80459fedbb9e138b96d7a6dc3b92ad87997d24b65cc1a8594cc14b226cd511acf03eb3f4b24c7b67d270665d5bf5cb43f8fa6">>,
BHash3 = <<"6f01ab53f4498ccfa5de27d9fa1fd1aa3c088958588db410bc35055012e6ed2795c39d8abe454402062436434b15acc78baddb016c370cd445579401562ea316">>,
Expand All @@ -25,11 +25,11 @@ create_and_overwrite_middle_tree_test() ->
{ok, File} = luwak_obj:create(Riak, <<"file1">>,
dict:store(tree_order, 4,
dict:store(block_size, 5, dict:new()))),
{ok, Written1, File2} = luwak_io:put_range(Riak, <<"file1">>, 0, <<"fuckyourcouch">>),
{ok, Written1, File2} = luwak_io:put_range(Riak, File, 0, <<"fuckyourcouch">>),
BHash1 = <<"4622b193a65e6f2a7873b6bef7e3b0cf18867f687e48f40fd9eabf840d5f0ebbd65bfff586e5c38ba50e473516e8f270b6687a1f271586baf648a38aa489dd91">>,
BHash2 = <<"08d5f211d13a9fb1e9b6902771b80459fedbb9e138b96d7a6dc3b92ad87997d24b65cc1a8594cc14b226cd511acf03eb3f4b24c7b67d270665d5bf5cb43f8fa6">>,
BHash3 = <<"6f01ab53f4498ccfa5de27d9fa1fd1aa3c088958588db410bc35055012e6ed2795c39d8abe454402062436434b15acc78baddb016c370cd445579401562ea316">>,
{ok, Written2, File3} = luwak_io:put_range(Riak, <<"file1">>, 1, <<"ballstoyou">>),
{ok, Written2, File3} = luwak_io:put_range(Riak, File2, 1, <<"ballstoyou">>),
BHash1_2 = <<"3717fd47d84a96cb99791d1c24d652a712e2841f2a3d0a282d22f9a477453bb7c394a1989115acf882fb867483cc2ba429f2280c1014cd82cc95aa8f1e8a1e4c">>,
BHash2_2 = <<"16c46831340abea94de6a5369466c0e8f710c15e2eec684067b89b27ca48856d7833933d28a1213cff5887bc57e5fdbb1d5e19bff7c6bb1f412a5db74612314b">>,
RootHash2 = <<"53bfd159bbc194ff331dbdcd19f9ab98480b554f88708a342ac2eb1f94229d0444a47a9d5fa5d8b14d1a6264d3df0dde3225f4c21536ed5874fbb0adfabc28eb">>,
Expand All @@ -45,7 +45,7 @@ create_multilevel_tree_test() ->
{ok, File} = luwak_obj:create(Riak, <<"file1">>,
dict:store(tree_order, 5,
dict:store(block_size, 1, dict:new()))),
{ok, Written1, File2} = luwak_io:put_range(Riak, <<"file1">>, 0, <<"fuckyourcouch">>),
{ok, Written1, File2} = luwak_io:put_range(Riak, File, 0, <<"fuckyourcouch">>),
Blocks = [ {skerl:hexhash(512, list_to_binary([C])), 1} || C <- binary_to_list(<<"fuckyourcouch">>) ],
{FirstNodeChildren, Tail1} = lists:split(5, Blocks),
{SecondNodeChildren, ThirdNodeChildren} = lists:split(5, Tail1),
Expand All @@ -70,9 +70,9 @@ create_and_overwrite_multilevel_tree_test() ->
{ok, File} = luwak_obj:create(Riak, <<"file1">>,
dict:store(tree_order, 5,
dict:store(block_size, 1, dict:new()))),
{ok, Written1, File2} = luwak_io:put_range(Riak, <<"file1">>, 0, <<"fuckyourcouch">>),
{ok, Written1, File2} = luwak_io:put_range(Riak, File, 0, <<"fuckyourcouch">>),
% ok = file:write_file("/Users/cliff/tree1.dot", luwak_tree:visualize_tree(Riak, luwak_obj:get_property(File2, root))),
{ok, Written2, File3} = luwak_io:put_range(Riak, <<"file1">>, 1, <<"ballstoyou">>),
{ok, Written2, File3} = luwak_io:put_range(Riak, File2, 1, <<"ballstoyou">>),
Blocks = [ {skerl:hexhash(512, list_to_binary([C])), 1} || C <- binary_to_list(<<"fballstoyouch">>) ],
{FirstNodeChildren, Tail1} = lists:split(5, Blocks),
{SecondNodeChildren, ThirdNodeChildren} = lists:split(5, Tail1),
Expand All @@ -99,8 +99,8 @@ create_and_append_test() ->
{ok, File} = luwak_obj:create(Riak, <<"file1">>,
dict:store(tree_order, 3,
dict:store(block_size, 2, dict:new()))),
{ok, Written1, File2} = luwak_io:put_range(Riak, <<"file1">>, 0, <<"wontyouplease">>),
{ok, Written2, File3} = luwak_io:put_range(Riak, <<"file1">>, 13, <<"touchmymonkey">>),
{ok, Written1, File2} = luwak_io:put_range(Riak, File, 0, <<"wontyouplease">>),
{ok, Written2, File3} = luwak_io:put_range(Riak, File2, 13, <<"touchmymonkey">>),
Blocks = [ {skerl:hexhash(512, X), 2} || <<X:2/binary>> <= <<"wontyoupleasetouchmymonkey">> ],
ok = file:write_file("/Users/cliff/tree3.dot", luwak_tree:visualize_tree(Riak, luwak_obj:get_property(File3, root)))
end).

0 comments on commit 541f914

Please sign in to comment.