1. Justin Sheehy
  2. riak

Commits

Bryan Fink  committed b7a6ef6

dets and osmos backends using {Bucket,Key} instead of Storekey now

  • Participants
  • Parent commits 566afcf
  • Branches default

Comments (0)

Files changed (2)

File src/riak_dets_backend.erl

View file
 -module(riak_dets_backend).
 
 -include_lib("eunit/include/eunit.hrl").
--export([start/1,stop/1,get/2,put/4,list/1,list_bucket/2,delete/2]).
+-export([start/1,stop/1,get/2,put/3,list/1,list_bucket/2,delete/2]).
 
 % @type state() = term().
 -record(state, {table}).
 % get(state(), Key :: binary()) ->
 %   {ok, Val :: binary()} | {error, Reason :: term()}
 % key must be 160b
-get(#state{table=T}, Key) ->
-    case dets:lookup(T, Key) of
+get(#state{table=T}, BKey) ->
+    case dets:lookup(T, BKey) of
         [] -> {error, notfound};
-        [{Key,{_,_,Val}}] -> {ok, Val};
+        [{BKey,Val}] -> {ok, Val};
         {error, Err} -> {error, Err}
     end.
 
 % put(state(), Key :: binary(), Val :: binary()) ->
 %   ok | {error, Reason :: term()}
 % key must be 160b
-put(#state{table=T},{B,K},Key,Val) -> dets:insert(T, {Key,{B,K,Val}}).
+put(#state{table=T},BKey,Val) -> dets:insert(T, {BKey,Val}).
 
 % delete(state(), Key :: binary()) ->
 %   ok | {error, Reason :: term()}
 % key must be 160b
-delete(#state{table=T}, Key) -> dets:delete(T, Key).
+delete(#state{table=T}, BKey) -> dets:delete(T, BKey).
 
 % list(state()) -> [Key :: binary()]
 list(#state{table=T}) ->
 list([[K]|Rest],Acc) -> list(Rest,[K|Acc]).
 
 list_bucket(#state{table=T}, Bucket) ->
-    MList = dets:match(T,{'_',{Bucket,'$1','_'}}),
+    MList = dets:match(T,{{Bucket,'$1'},'_'}),
     list(MList,[]).

File src/riak_osmos_backend.erl

View file
 %%    under riak_osmos_backend_root.
 -module(riak_osmos_backend).
 
--export([start/1,stop/1,get/2,put/4,list/1,list_bucket/2,delete/2]).
+-export([start/1,stop/1,get/2,put/3,list/1,list_bucket/2,delete/2]).
 -record(state, {table}).
 
 %% @spec start(Partition :: integer()) ->
 %% get(state(), Key :: binary()) ->
 %%   {ok, Val :: binary()} | {error, Reason :: term()}
 %% key must be 160b
-get(#state{table=Table}, Key) ->
-    case osmos:read(Table, Key) of
+get(#state{table=Table}, BKey) ->
+    case osmos:read(Table, term_to_binary(BKey)) of
         {ok, <<>>}  -> {error, notfound}; %% sentinal for delete
-        {ok, Value} ->
-            {_,_,RVal} = binary_to_term(Value),
-            {ok, RVal};
+        {ok, Value} -> {ok, Value};
         not_found   -> {error, notfound}
     end.
 
 %% put(state(), Key :: binary(), Val :: binary()) ->
 %%   ok | {error, Reason :: term()}
 %% key must be 160b
-put(#state{table=Table},{B,K},Key,Val) ->       
-    osmos:write(Table, Key, term_to_binary({B,K,Val})).
+put(#state{table=Table},BKey,Val) ->       
+    osmos:write(Table, term_to_binary(BKey), Val).
 
 %% delete(state(), Key :: binary()) ->
 %%   ok | {error, Reason :: term()}
 %% key must be 160b
-delete(#state{table=Table}, Key) ->
-    osmos:write(Table, Key, <<>>). %% sentinal for delete
+delete(#state{table=Table}, BKey) ->
+    osmos:write(Table, term_to_binary(BKey), <<>>). %% sentinal for delete
 
 -define(SELECT_CHUNK, 1000).
 
 %% list(state()) -> [Key :: binary()]
 list(#state{table=Table}) ->
-    accum(Table, fun(K,_) -> {true, K} end).
+    accum(Table, fun(K,_) -> {true, binary_to_term(K)} end).
 
 %% list_bucket(state(), Bucket :: atom()) -> [Key :: binary()]
 list_bucket(#state{table=Table}, Bucket) ->
     accum(Table,
-          fun(_,V) ->
-                  case binary_to_term(V) of
-                      {Bucket, Key, _} -> {true, Key};
-                      _                -> false
+          fun(K,_) ->
+                  case binary_to_term(K) of
+                      {Bucket, Key} -> {true, Key};
+                      _             -> false
                   end
           end).