Skip to content
Browse files

riak redis backend now working.

  • Loading branch information...
1 parent ecffd39 commit 5bb356bae7a98f0b537c80306c521c0d1f1424ee @cstar committed Dec 25, 2009
Showing with 41 additions and 45 deletions.
  1. +7 −7 riak-playground
  2. +0 −8 riak_bench
  3. +34 −30 riak_redis_backend.erl
View
14 riak-playground
@@ -6,7 +6,7 @@
main(_)->
{ok, C} = riak:client_connect(dev1@boulette.local),
step1(C),
- %step2(C),
+ step2(C),
%empty_bucket(C, <<"entries">>).
ok.
@@ -18,20 +18,20 @@ empty_bucket(C, Name)->
step2(C)->
Participant = make_rand_list_picker([<<"cstar">>, <<"martin">>, <<"sacha">>, <<"helene">>, <<"boulette">>]),
- Entry = make_rand_fun(100),
- Blog = make_rand_fun(20),
+ Entry = make_rand_fun(1000),
+ Blog = make_rand_fun(200),
statistics(wall_clock),
- fill(10, C, Participant, Entry, Blog),
- %{_, R1} = statistics(runtime),
+ fill(1000, C, Participant, Entry, Blog),
{_, W1} = statistics(wall_clock),
io:format("Fill time for adding 1000 entry: ~p seconds~n", [ W1/1000]),
count_chars_per_user(C),
{_, W2} = statistics(wall_clock),
io:format("MapRed time=~p seconds~n", [W2/1000]),
statistics(wall_clock),
count_chars_for_user(C, <<"boulette">>),
- {_, W2} = statistics(wall_clock),
- io:format("MapRed time=~p seconds~n", [W2/1000]).
+ {_, W3} = statistics(wall_clock),
+ io:format("MapRed time=~p seconds~n", [W3/1000]),
+ ok.
View
8 riak_bench
@@ -1,8 +0,0 @@
-#!/usr/bin/env escript
-%% -*- erlang -*-
-%%! -boot start_sasl -name tester -setcookie riak -pa . -pa ../erldis/ebin -pa ../riak/apps/riak/ebin
-
-main(_)->
- fprof:apply(riak_test_util,standard_backend_test, [riak_redis_backend]),
- fprof:profile(),
- fprof:analyse([no_callers, no_details, totals]).
View
64 riak_redis_backend.erl
@@ -25,66 +25,70 @@
-export([start/1,stop/1,get/2,put/3,list/1,list_bucket/2,delete/2]).
% @type state() = term().
--record(state, {pid}).
+-record(state, {pid, partition}).
% @spec start(Partition :: integer()) ->
% {ok, state()} | {{error, Reason :: term()}, state()}
-start(_Partition)->
- {ok, Pid} = erldis_sync_client:connect("localhost"),
- erldis:select(Pid, erlang:phash2(node(), 40)),
- {ok, #state{pid=Pid}}.
+start(Partition)->
+ {ok, Pid} = erldis_sync_client:connect(),
+ P=list_to_binary(integer_to_list(Partition)),
+ {ok, #state{pid=Pid, partition = P}}.
% @spec stop(state()) -> ok | {error, Reason :: term()}
stop(_State)->
ok.
% get(state(), Key :: binary()) ->
% {ok, Val :: binary()} | {error, Reason :: term()}
-get(#state{pid=Pid}, BK)->
- case erldis:get(Pid, k2l(BK)) of
+get(#state{partition=P, pid=Pid}, BK)->
+ case erldis:get(Pid, k2l(P,BK)) of
nil -> {error, notfound};
- Val -> {ok, binary_to_term(Val)}
+ Val ->
+ case catch binary_to_term(Val) of
+ {'EXIT', _}->
+ throw({badterm, BK, Val});
+ V ->
+ {ok, V}
+ end
end.
% put(state(), Key :: binary(), Val :: binary()) ->
% ok | {error, Reason :: term()}
-put(#state{pid=Pid}, {Bucket, Key}=BK, Value)->
- %riak_eventer:notify(riak_redis_backend, put, {{Bucket, Key}, Value}),
- erldis:sadd(Pid, <<"buckets">>,Bucket),
- case erldis:set(Pid, k2l(BK), term_to_binary(Value)) of
+put(#state{partition=P,pid=Pid}, {Bucket, Key}=BK, Value)->
+ erldis:sadd(Pid, <<"buckets:",P/binary>>,Bucket),
+ case erldis:set(Pid, k2l(P,BK), term_to_binary(Value)) of
ok ->
- erldis:sadd(Pid, Bucket, Key),
- erldis:sadd(Pid, <<"world">>, term_to_binary(BK)),
+ erldis:sadd(Pid, <<P/binary,Bucket/binary>>, Key),
+ erldis:sadd(Pid, <<"world:",P/binary>>, term_to_binary(BK)),
ok;
_ -> {error, unable_to_put}
end.
% delete(state(), Key :: binary()) ->
% ok | {error, Reason :: term()}
-delete(#state { pid=Pid }, {Bucket, Key}=BK) ->
- case erldis:del(Pid, k2l(BK)) of
+delete(#state {partition=P, pid=Pid }, {Bucket, Key}=BK) ->
+ erldis:srem(Pid, <<"buckets:",P/binary>>,Bucket),
+ case erldis:del(Pid, k2l(P,BK)) of
true ->
- erldis:srem(Pid, Bucket, Key),
- erldis:srem(Pid, <<"world">>, term_to_binary(BK)),
+ erldis:srem(Pid, <<P/binary,Bucket/binary>>, Key),
+ erldis:srem(Pid, <<"world:",P/binary>>, term_to_binary(BK)),
ok;
_ ->
{error, unable_to_delete}
end.
% list(state()) -> [Key :: binary()]
-list(#state { pid=Pid }) ->
+list(#state {partition=P, pid=Pid }) ->
lists:map(fun binary_to_term/1,
- erldis:smembers(Pid, <<"world">>)).
+ erldis:smembers(Pid, <<"world:",P/binary>>)).
-list_bucket(#state { pid=Pid }, '_')->
- erldis:smembers(Pid, <<"buckets">>);
+list_bucket(#state {partition=P, pid=Pid }, '_')->
+ erldis:smembers(Pid, <<"buckets:",P/binary>>);
-list_bucket(#state { pid=Pid }, {filter, Bucket, Fun})->
- lists:filter(Fun, erldis:smembers(Pid, Bucket));
-list_bucket(#state { pid=Pid }, Bucket) ->
- erldis:smembers(Pid, Bucket).
+list_bucket(#state {partition=P, pid=Pid }, {filter, Bucket, Fun})->
+ lists:filter(Fun, erldis:smembers(Pid, <<P/binary,Bucket/binary>>));
+list_bucket(#state {partition=P, pid=Pid }, Bucket) ->
+ erldis:smembers(Pid, <<P/binary,Bucket/binary>>).
-
-
-k2l({B, V})->
- <<B/binary,V/binary>>.
+k2l(P,{B, V})->
+ <<P/binary,B/binary,V/binary>>.

0 comments on commit 5bb356b

Please sign in to comment.
Something went wrong with that request. Please try again.