Skip to content

Commit

Permalink
Fix leo-project/leofs/issues/365 more correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
yosukehara committed Jun 28, 2015
1 parent ddba714 commit 1ad28be
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions src/leo_storage_watchdog_sub.erl
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,13 @@ handle_notify(?WD_SUB_ID_1 = Id,_Alarm,_Unixtime) ->
handle_notify(?WD_SUB_ID_2, #watchdog_alarm{state = #watchdog_state{
level = Level,
props = Props}},_Unixtime) ->
%% Clear the current status
_ = elarm:clear('leo_storage_watchdog_fragment', ?WD_ITEM_ACTIVE_SIZE_RATIO),
%% Execution data-compacion or not
case (Level >= ?WD_LEVEL_ERROR) of
true ->
case can_start_compaction() of
true ->
%% Execute data-compaction
timer:sleep(?DEF_WAIT_TIME),
ThisTime = leo_date:now(),
AutoCompactionInterval = ?env_auto_compaction_interval(),
Expand Down Expand Up @@ -181,26 +183,21 @@ can_start_compaction() ->
N ->
N
end,
case get_candidates(Members, MaxNumOfNodes, []) of
{ok, Candidates} ->
lists:member(erlang:node(), Candidates);
not_found ->
false
end;
is_candidates(Members, MaxNumOfNodes, []);
_ ->
false
end.


%% @doc Retrieve candidate nodes of data-compaction
%% @private
get_candidates([],_,[]) ->
not_found;
get_candidates([],_,Acc) ->
{ok, lists:reverse(Acc)};
get_candidates(_, MaxNumOfNodes, Acc) when MaxNumOfNodes == erlang:length(Acc) ->
{ok, lists:reverse(Acc)};
get_candidates([#member{node = Node}|Rest], MaxNumOfNodes, Acc) ->
is_candidates([],_,[]) ->
false;
is_candidates([],_,Acc) ->
is_candidates_1(lists:reverse(Acc));
is_candidates(_, MaxNumOfNodes, Acc) when MaxNumOfNodes == erlang:length(Acc) ->
is_candidates_1(lists:reverse(Acc));
is_candidates([#member{node = Node}|Rest], MaxNumOfNodes, Acc) ->
Acc_1 = case rpc:call(Node, leo_object_storage_api, stats, [], ?DEF_REQ_TIMEOUT) of
{ok, []} ->
Acc;
Expand All @@ -219,16 +216,20 @@ get_candidates([#member{node = Node}|Rest], MaxNumOfNodes, Acc) ->

case (ActiveSizeRatio =< (ThresholdActiveSizeRatio + ActiveSizeRatioDiff)) of
true ->
[Node|Acc];
[{Node, ?ST_IDLING}|Acc];
false ->
case rpc:call(Node, leo_storage_api, compact, [status], ?DEF_REQ_TIMEOUT) of
{ok, #compaction_stats{status = ?ST_RUNNING}} ->
[Node|Acc];
[{Node, ?ST_RUNNING}|Acc];
_ ->
Acc
end
end;
_ ->
Acc
end,
get_candidates(Rest, MaxNumOfNodes, Acc_1).
is_candidates(Rest, MaxNumOfNodes, Acc_1).

%% @private
is_candidates_1(Candidates) ->
lists:member({erlang:node(), ?ST_IDLING}, Candidates).

0 comments on commit 1ad28be

Please sign in to comment.