Commits

Anonymous committed a0dd973

implement new backend API contract (is_empty, drop, fold) for riak_ets_backend)

Comments (0)

Files changed (1)

apps/riak/src/riak_ets_backend.erl

 -behaviour(gen_server).
 
 -include_lib("eunit/include/eunit.hrl").
--export([start/2,stop/1,get/2,put/3,list/1,list_bucket/2,delete/2]).
+-export([start/2,stop/1,get/2,put/3,list/1,list_bucket/2,delete/2,
+         is_empty/1, drop/1, fold/3]).
 
 -export([init/1, handle_call/3, handle_cast/2, handle_info/2,
 	 terminate/2, code_change/3]).
 handle_call({delete,BKey},_From,State) -> {reply, srv_delete(State,BKey),State};
 handle_call(list,_From,State) -> {reply, srv_list(State), State};
 handle_call({list_bucket,Bucket},_From,State) ->
-    {reply, srv_list_bucket(State, Bucket), State}.
+    {reply, srv_list_bucket(State, Bucket), State};
+handle_call(is_empty, _From, State) ->
+    {reply, ets:info(State#state.t) =:= 0, State};
+handle_call(drop, _From, State) -> 
+    ets:delete(State#state.t),
+    {reply, ok, State};
+handle_call({fold, Fun0, Acc}, _From, State) ->
+    Fun = fun({{B,K}, V}, AccIn) -> Fun0({B,K}, V, AccIn) end,
+    ets:foldl(Fun, Acc, State#state.t),
+    {reply, ok, State}.
+
 
 % @spec stop(state()) -> ok | {error, Reason :: term()}
 stop(SrvRef) -> gen_server:call(SrvRef,stop).
     MList = ets:match(State#state.t,MatchSpec),
     list(MList,[]).
 
+is_empty(SrvRef) -> gen_server:call(SrvRef, is_empty).
+
+drop(SrvRef) -> gen_server:call(SrvRef, drop).
+    
+fold(SrvRef, Fun, Acc0) -> gen_server:call(SrvRef, {fold, Fun, Acc0}).
+
 %% @private
 handle_info(_Msg, State) -> {noreply, State}.
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.