Skip to content

Commit

Permalink
Merge pull request #311 from basho/bugfix/rz/full-check
Browse files Browse the repository at this point in the history
Update previous hash during event tick + general refactoring
  • Loading branch information
rzezeski committed Feb 19, 2014
2 parents 6b31d32 + aba0fc4 commit f4b4595
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
10 changes: 10 additions & 0 deletions include/yokozuna.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@

-define(DATA_DIR, application:get_env(riak_core, platform_data_dir)).


-define(MAYBE(Check, Expression, Default),
case Check of
true -> Expression;
false -> Default
end).

-define(MAYBE(Check, Expression),
?MAYBE(Check, Expression, ok)).

%% Core security requires `{BucketType, Bucket}'. Technically, these
%% arent so strict, and so we refer to them as `{Resource,
%% SubResource}' where `Resource' is a resource like index or schema
Expand Down
34 changes: 15 additions & 19 deletions src/yz_events.erl
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@
terminate/2]).
-include("yokozuna.hrl").

-define(NUM_TICKS_START, 1).

-record(state, {
%% The number of ticks since the last time this value was
%% reset to 0. This value along with
%% reset to 1. This value along with
%% `get_full_check_after/0' is used to determine when a
%% "full check" should be performed. This is to prevent
%% expensive checks occurring on every tick.
num_ticks = 0 :: non_neg_integer(),
num_ticks = ?NUM_TICKS_START :: non_neg_integer(),

%% The hash of the index cluster meta last time it was
%% checked.
Expand Down Expand Up @@ -74,27 +76,21 @@ handle_info(tick, S) ->
PrevHash = S#state.prev_index_hash,
CurrHash = riak_core_metadata:prefix_hash(?YZ_META_INDEXES),
NumTicks = S#state.num_ticks,
FullCheck = NumTicks == 0,

case yz_solr:is_up() of
true ->
case FullCheck orelse (PrevHash /= CurrHash) of
true -> ok = sync_indexes();
false -> ok
end;
false ->
ok
end,
IsFullCheck = (NumTicks == ?NUM_TICKS_START),
DidHashChange = PrevHash /= CurrHash,

case FullCheck of
true -> ok = remove_non_owned_data(yz_cover:get_ring_used());
false -> ok
end,
ok = ?MAYBE(yz_solr:is_up() andalso (IsFullCheck orelse DidHashChange),
sync_indexes()),

ok = ?MAYBE(IsFullCheck,
remove_non_owned_data(yz_cover:get_ring_used())),

ok = set_tick(),

NumTicks2 = incr_or_wrap(NumTicks, get_full_check_after()),
{noreply, S#state{num_ticks=NumTicks2}}.
S2 = S#state{num_ticks=NumTicks2,
prev_index_hash=CurrHash},
{noreply, S2}.

handle_call(Req, _, S) ->
?WARN("unexpected request ~p", [Req]),
Expand Down Expand Up @@ -155,7 +151,7 @@ get_tick_interval() ->
-spec incr_or_wrap(non_neg_integer(), non_neg_integer()) -> non_neg_integer().
incr_or_wrap(N, M) ->
case N == M of
true -> 0;
true -> ?NUM_TICKS_START;
false -> N + 1
end.

Expand Down

0 comments on commit f4b4595

Please sign in to comment.