Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
yosukehara committed May 8, 2014
1 parent 489d10a commit 9dae99f
Showing 1 changed file with 40 additions and 21 deletions.
61 changes: 40 additions & 21 deletions src/leo_storage_api.erl
Original file line number Diff line number Diff line change
Expand Up @@ -222,33 +222,52 @@ synchronize(Key, ErrorType) ->
%%
-spec(compact(atom(), 'all' | integer(), integer()) -> ok | {error, any()}).
compact(start, NumOfTargets, MaxProc) ->
TargetPids1 =
case leo_compaction_manager_fsm:status() of
{ok, #compaction_stats{status = Status,
pending_targets = PendingTargets}} when Status == ?COMPACTION_STATUS_SUSPEND;
Status == ?COMPACTION_STATUS_IDLE ->
PendingTargets;
_ ->
[]
end,
case leo_redundant_manager_api:get_member_by_node(erlang:node()) of
{ok, #member{state = ?STATE_RUNNING}} ->
TargetPids1 =
case leo_compaction_manager_fsm:status() of
{ok, #compaction_stats{status = Status,
pending_targets = PendingTargets}}
when Status == ?COMPACTION_STATUS_SUSPEND;
Status == ?COMPACTION_STATUS_IDLE ->
PendingTargets;
_ ->
[]
end,

case TargetPids1 of
[] ->
{error, "Not exists compaction-targets"};
case TargetPids1 of
[] ->
{error, "Not exists compaction-targets"};
_ ->
TargetPids2 =
case NumOfTargets of
'all' ->
TargetPids1;
_Other ->
lists:sublist(TargetPids1, NumOfTargets)
end,
leo_compaction_manager_fsm:start(
TargetPids2, MaxProc,
fun leo_redundant_manager_api:has_charge_of_node/2)
end;
_ ->
TargetPids2 = case NumOfTargets of
'all' -> TargetPids1;
_Other -> lists:sublist(TargetPids1, NumOfTargets)
end,
leo_compaction_manager_fsm:start(
TargetPids2, MaxProc, fun leo_redundant_manager_api:has_charge_of_node/2)
{error,'not_running'}
end.

compact(suspend) ->
compact(Method) ->
case leo_redundant_manager_api:get_member_by_node(erlang:node()) of
{ok, #member{state = ?STATE_RUNNING}} ->
compact_1(Method);
_ ->
{error,'not_running'}
end.

%% @private
compact_1(suspend) ->
leo_compaction_manager_fsm:suspend();
compact(resume) ->
compact_1(resume) ->
leo_compaction_manager_fsm:resume();
compact(status) ->
compact_1(status) ->
leo_compaction_manager_fsm:status().


Expand Down

0 comments on commit 9dae99f

Please sign in to comment.