Permalink
Browse files

Factor general filter code into Core

Factor out the repair filter code shared by Search & KV into Core.
  • Loading branch information...
rzezeski committed Jun 11, 2012
1 parent c33d935 commit d4a610896f36df447a09ec028f91cc5cc631dff9
Showing with 29 additions and 1 deletion.
  1. +29 −1 src/riak_core_repair.erl
View
@@ -19,7 +19,8 @@
%% -------------------------------------------------------------------
-module(riak_core_repair).
--export([gen_range/3,
+-export([gen_filter/5,
+ gen_range/3,
gen_range_fun/2,
gen_range_map/3]).
@@ -35,6 +36,33 @@
%% Public API
%% ===================================================================
+%% @doc Generate a `Filter' fun to use during partition repair.
+%%
+%% `Target' - Partition under repair.
+%%
+%% `Ring' - The ring to use for repair.
+%%
+%% `NValMap' - A map from bucket to `n_val', only custom buckets
+%% have entries, everything else uses default.
+%%
+%% `DefaultN' - The default `n_val'.
+%%
+%% `InfoFun' - A function which returns information about the key
+%% used to determine if it should be repaired or not.
+gen_filter(Target, Ring, NValMap, DefaultN, InfoFun) ->
+ RangeMap = riak_core_repair:gen_range_map(Target, Ring, NValMap),
+ Default = riak_core_repair:gen_range(Target, Ring, DefaultN),
+ RangeFun = riak_core_repair:gen_range_fun(RangeMap, Default),
+ fun(BKey) ->
+ {Bucket, Hash} = InfoFun(BKey),
+ case RangeFun(Bucket) of
+ {nowrap, GTE, LTE} ->
+ Hash >= GTE andalso Hash =< LTE;
+ {wrap, GTE, LTE} ->
+ Hash >= GTE orelse Hash =< LTE
+ end
+ end.
+
%% @doc Generate the hash `Range' for a given `Target' partition and
%% `NVal'.
%%

0 comments on commit d4a6108

Please sign in to comment.