Skip to content

Commit 1728625

Browse files
authored
Merge pull request #19 from OpenRiak/nhse-o32-orkv.i29-asyncfun
Add support for {F, async} as a data_size option
2 parents da13c45 + b727b3e commit 1728625

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

include/riak_core_handoff.hrl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
-type mod_src_tgt() :: {module(), index(), index()} | {undefined, undefined, undefined}.
2424
-type mod_partition() :: {module(), index()}.
2525

26+
-type db_dynamic_size_fun()
27+
:: fun(() -> db_size()).
28+
-type db_size_result() :: {non_neg_integer(), bytes | objects}.
29+
-type db_size()
30+
:: {db_dynamic_size_fun(), dynamic} | db_size_result().
31+
2632
-record(handoff_status,
2733
{ mod_src_tgt :: mod_src_tgt(),
2834
src_node :: node(),
@@ -38,7 +44,7 @@
3844
type = undefined :: ho_type() | undefined,
3945
req_origin :: node(),
4046
filter_mod_fun :: {module(), atom()} | undefined,
41-
size = {0, objects} :: {function(), dynamic} | {non_neg_integer(), bytes | objects}
47+
size = {0, objects} :: db_size() | undefined
4248
}).
4349
-type handoff_status() :: #handoff_status{}.
4450

src/riak_core_handoff_manager.erl

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -404,17 +404,23 @@ calc_stats(#handoff_status{stats=Stats,timestamp=StartTS,size=Size}) ->
404404
{pct_done_decimal, Done}]
405405
end.
406406

407+
-spec get_size(db_size()|undefined) -> db_size_result()|undefined.
407408
get_size({F, dynamic}) ->
408409
F();
409410
get_size(S) ->
410411
S.
411412

412-
calc_pct_done(_, _, undefined) ->
413-
undefined;
414-
calc_pct_done(Objs, _, {Size, objects}) ->
413+
-spec calc_pct_done(
414+
non_neg_integer(),
415+
non_neg_integer(),
416+
db_size_result() | undefined) -> float() | undefined.
417+
calc_pct_done(Objs, _, {Size, objects}) when is_integer(Size), Size > 0 ->
415418
Objs / Size;
416-
calc_pct_done(_, Bytes, {Size, bytes}) ->
417-
Bytes / Size.
419+
calc_pct_done(_, Bytes, {Size, bytes}) when is_integer(Size), Size > 0 ->
420+
Bytes / Size;
421+
calc_pct_done(_, _, _) ->
422+
% Will normally expect in this case that db_size_result is undefined
423+
undefined.
418424

419425
filter(none) ->
420426
fun(_) -> true end;
@@ -588,12 +594,17 @@ update_stats(StatsUpdate, Stats) ->
588594
Stats3 = dict:update_counter(bytes, Bytes, Stats2),
589595
dict:store(last_update, LU, Stats3).
590596

591-
validate_size(Size={N, U}) when is_number(N) andalso
592-
N > 0 andalso
593-
(U =:= bytes orelse U =:= objects) ->
597+
598+
-spec validate_size(
599+
db_size()|{db_dynamic_size_fun(), async}) -> db_size()|undefined.
600+
validate_size(Size={N, U})
601+
when
602+
is_number(N), N > 0, (U =:= bytes orelse U =:= objects) ->
594603
Size;
595-
validate_size(Size={F, dynamic}) when is_function(F) ->
604+
validate_size(Size={F, dynamic}) when is_function(F, 0) ->
596605
Size;
606+
validate_size({F, async}) when is_function(F, 0) ->
607+
validate_size(F());
597608
validate_size(_) ->
598609
undefined.
599610

0 commit comments

Comments
 (0)