Skip to content

Commit

Permalink
Export function to handle auto compaction triggers (#5881) (#5900)
Browse files Browse the repository at this point in the history
Use proper variable names
  • Loading branch information
harenson authored and k-anderson committed Jul 10, 2019
1 parent b06bc30 commit 110e346
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 6 additions & 4 deletions applications/tasks/src/kz_tasks_trigger.erl
Original file line number Diff line number Diff line change
Expand Up @@ -258,15 +258,17 @@ browse_dbs_for_triggers(Ref) ->
CallId = <<"cleanup_pass_", (kz_binary:rand_hex(4))/binary>>,
kz_util:put_callid(CallId),
lager:debug("starting cleanup pass of databases"),
lager:debug("getting databases list and sorting them by disk size"),
Sorted = kt_compactor:get_all_dbs_and_sort_by_disk(),
TotalSorted = length(Sorted),
lager:debug("finished listing and sorting databases (~p found)", [TotalSorted]),
'ok' = kt_compaction_reporter:start_tracking_job(self(), node(), CallId, Sorted),
F = fun({Db, _Sizes}, Ctr) ->
lager:debug("compacting ~p out of ~p dbs (~p remaining)",
[Ctr, TotalSorted, (TotalSorted - Ctr)]
F = fun({Db, _Sizes}, Counter) ->
lager:debug("compacting ~p ~p/~p (~p remaining)",
[Db, Counter, TotalSorted, (TotalSorted - Counter)]
),
cleanup_pass(Db),
Ctr + 1
Counter + 1
end,
_Counter = lists:foldl(F, 1, Sorted),
'ok' = kt_compaction_reporter:stop_tracking_job(CallId),
Expand Down
7 changes: 6 additions & 1 deletion applications/tasks/src/modules/kt_compactor.erl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

,compact_db/1
,compact_node/1

%% Used to handle auto_compaction triggers. Check init/0 for more info.
,do_compact_db/1
]).

%% Triggerables
Expand Down Expand Up @@ -71,7 +74,9 @@ init() ->
'false' -> lager:info("node ~s not configured to compact automatically", [node()]);
'true' ->
lager:info("node ~s configured to compact automatically", [node()]),
%% By default, `do_compact_db/1' sets `?HEUR_RATIO' as the Heuristic to use.
%% Need to use `do_compact_db/1' instead of `compact_db/1' because the
%% the former uses `?HEUR_RATIO' for heuristic and the latter ignores
%% heuristic and doesn't allow to improve auto compaction job exec time.
_ = tasks_bindings:bind(?TRIGGER_ALL_DBS, ?MODULE, 'do_compact_db')
end,

Expand Down

0 comments on commit 110e346

Please sign in to comment.