From 9dae99f1e9ab564aefa08a4956ddf6d63e7e1b7d Mon Sep 17 00:00:00 2001 From: Yosuke Hara Date: Thu, 8 May 2014 11:41:38 +0900 Subject: [PATCH] Fix leo-project/leofs/issues/182 --- src/leo_storage_api.erl | 61 +++++++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 21 deletions(-) diff --git a/src/leo_storage_api.erl b/src/leo_storage_api.erl index 702c2a4..633c0a9 100644 --- a/src/leo_storage_api.erl +++ b/src/leo_storage_api.erl @@ -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().