Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Factor general filter code into Core

Factor out the repair filter code shared by Search & KV into Core.
  • Loading branch information...
commit afba31eae3410a0dd7e7b6b27fd047c14013ff26 1 parent eebc69e
Ryan Zezeski authored June 11, 2012

Showing 1 changed file with 25 additions and 26 deletions. Show diff stats Hide diff stats

  1. 51  src/riak_search_vnode.erl
51  src/riak_search_vnode.erl
... ...
@@ -1,6 +1,6 @@
1 1
 %% -------------------------------------------------------------------
2 2
 %%
3  
-%% Copyright (c) 2007-2010 Basho Technologies, Inc.  All Rights Reserved.
  3
+%% Copyright (c) 2007-2012 Basho Technologies, Inc.  All Rights Reserved.
4 4
 %%
5 5
 %% -------------------------------------------------------------------
6 6
 
@@ -97,13 +97,25 @@ sync_command(IndexNode, Msg) ->
97 97
 %% @doc Repair the index at the given `Partition'.
98 98
 -spec repair(partition()) ->
99 99
                     {ok, Pairs::[{partition(), node()}]} |
100  
-                    {down, Down::[{partition(), node()}]}.
  100
+                    {down, Down::[{partition(), node()}]} |
  101
+                    ownership_change_in_progress.
101 102
 repair(Partition) ->
102 103
     Service = riak_search,
103 104
     MP = {?MODULE, Partition},
104 105
     FilterModFun = {?MODULE, repair_filter},
105 106
     riak_core_vnode_manager:repair(Service, MP, FilterModFun).
106 107
 
  108
+%% @doc Given a `Target' partition generate a `Filter' fun to use
  109
+%%      during partition repair.
  110
+-spec repair_filter(partition()) -> Filter::function().
  111
+repair_filter(Target) ->
  112
+    {ok, Ring} = riak_core_ring_manager:get_my_ring(),
  113
+    riak_core_repair:gen_filter(Target,
  114
+                                Ring,
  115
+                                schema_nval_map(),
  116
+                                default_object_nval(),
  117
+                                fun object_info/1).
  118
+
107 119
 %% @doc Get the status of the repair process for the given `Partition'.
108 120
 -spec repair_status(partition()) -> no_repair | repair_in_progress.
109 121
 repair_status(Partition) ->
@@ -222,27 +234,14 @@ bmod_response({reply, Reply, NewBState}, VState) ->
222 234
     {reply, Reply, VState#vstate{bstate=NewBState}}.
223 235
 
224 236
 %% @private
225  
-%%
226  
-%% @doc Given a `Target' partition, a `Ring' generate a `Filter' fun
227  
-%%      to use during partition repair.  The `NValMap' is a map from
228  
-%%      index name to n_val and is needed to determine which hash
229  
-%%      range a key must fall into to be included.  Only non-default
230  
-%%      schemas will be included in the map.
231  
--spec repair_filter(partition()) -> Filter::function().
232  
-repair_filter(Target) ->
233  
-    {ok, Ring} = riak_core_ring_manager:get_my_ring(),
234  
-    NValMap = [{S:name(), S:n_val()} ||
235  
-                  S <- riak_search_config:get_all_schemas()],
236  
-    RangeMap = riak_core_repair:gen_range_map(Target, Ring, NValMap),
237  
-    DefaultN = riak_core_bucket:n_val(riak_core_config:default_bucket_props()),
238  
-    Default = riak_core_repair:gen_range(Target, Ring, DefaultN),
239  
-    RangeFun = riak_core_repair:gen_range_fun(RangeMap, Default),
240  
-    fun({I, {F, T}}) ->
241  
-            Hash = riak_search_ring_utils:calc_partition(I, F, T),
242  
-            case RangeFun(I) of
243  
-                {nowrap, GTE, LTE} ->
244  
-                    Hash >= GTE andalso Hash =< LTE;
245  
-                {wrap, GTE, LTE} ->
246  
-                    Hash >= GTE orelse Hash =< LTE
247  
-            end
248  
-    end.
  237
+default_object_nval() ->
  238
+    riak_core_bucket:n_val(riak_core_config:default_bucket_props()).
  239
+
  240
+%% @private
  241
+object_info({I, {F, T}}) ->
  242
+    Hash = riak_search_ring_utils:calc_partition(I, F, T),
  243
+    {I, Hash}.
  244
+
  245
+%% @private
  246
+schema_nval_map() ->
  247
+    [{S:name(), S:n_val()} || S <- riak_search_config:get_all_schemas()].

0 notes on commit afba31e

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