Address review comments

More efficient traversal of list to score.
This commit is contained in:
Martin Sumner 2020-03-29 20:02:21 +01:00
parent 28c88ef8b8
commit 9838e255d2
2 changed files with 17 additions and 11 deletions

View file

@ -188,7 +188,7 @@ merge(SrcLevel, Manifest, RootPath, OptsSST) ->
end,
SelectMethod =
case leveled_rand:uniform(100) of
R when R < ?GROOMING_PERC ->
R when R =< ?GROOMING_PERC ->
{grooming, fun grooming_scorer/1};
_ ->
random
@ -297,18 +297,23 @@ do_merge(KL1, KL2, SinkLevel, SinkB, RP, NewSQN, MaxSQN, OptsSST, Additions) ->
end.
-spec grooming_scorer(list(manifest_entry())) -> manifest_entry().
grooming_scorer(Sample) ->
ScoringFun =
fun(ME) ->
TombCount = leveled_sst:sst_gettombcount(ME#manifest_entry.owner),
{TombCount, ME}
end,
ScoredSample =
lists:reverse(lists:ukeysort(1, lists:map(ScoringFun, Sample))),
[{HighestTC, BestME}|_Rest] = ScoredSample,
grooming_scorer([ME | MEs]) ->
InitTombCount = leveled_sst:sst_gettombcount(ME#manifest_entry.owner),
{HighestTC, BestME} = grooming_scorer(InitTombCount, ME, MEs),
leveled_log:log("PC024", [HighestTC]),
BestME.
grooming_scorer(HighestTC, BestME, []) ->
{HighestTC, BestME};
grooming_scorer(HighestTC, BestME, [ME | MEs]) ->
TombCount = leveled_sst:sst_gettombcount(ME#manifest_entry.owner),
case TombCount > HighestTC of
true ->
grooming_scorer(TombCount, ME, MEs);
false ->
grooming_scorer(HighestTC, BestME, MEs)
end.
return_deletions(ManifestSQN, PendingDeletionD) ->
% The returning of deletions had been seperated out as a failure to fetch
% here had caased crashes of the clerk. The root cause of the failure to

View file

@ -464,7 +464,8 @@ mergefile_selector(Manifest, LevelIdx, {grooming, ScoringFun}) ->
Sample =
lists:usort(lists:foldl(SelectorFun, [], lists:seq(1, ?GROOM_SAMPLE))),
% Note that Entries may be less than GROOM_SAMPLE, if same one picked
% multiple times
% multiple times. Level cannot be empty, as otherwise a merge would not
% have been chosen at this level
ScoringFun(Sample).