Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update previous hash during event tick + general refactoring #311

Merged
merged 3 commits into from
Feb 19, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Welcome to CPP ;)


%% 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