Anonymous committed 51189a8

is_empty/1, drop/1, and fold/3 for riak_multi_backend

Comments (0)

Files changed (1)


 %% @doc riak_gb_trees_backend is a Riak storage backend using Erlang gb_trees.
 -module (riak_multi_backend).
--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]).
 list_bucket(State, Bucket) ->
     {_Name, Module, SubState} = get_backend(Bucket, State),
     Module:list_bucket(SubState, Bucket).
+is_empty(State) ->
+    F = fun({_, Module, SubState}, Acc) ->
+                [Module:is_empty(SubState)|Acc]
+        end,
+    lists:all(fun(I) -> I end, lists:foldl(F, [], State#state.backends)).
+drop(State) ->
+    F = fun({_, Module, SubState}, Acc) ->
+                [Module:drop(SubState)|Acc]
+        end,
+    lists:foldl(F, [], State#state.backends),
+    ok.
+fold(State, Fun0, Acc) ->    
+    F = fun({_, Module, SubState}, AccIn) ->
+                [Module:fold(SubState, Fun0, AccIn)|AccIn]
+        end,
+    lists:flatten(lists:foldl(F, Acc, State#state.backends)).
 % Given a Bucket name and the State, return the
 % backend definition. (ie: {Name, Module, SubState})
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
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.