diff --git a/src/riak_core_apl.erl b/src/riak_core_apl.erl index 791197858..a2e117d35 100644 --- a/src/riak_core_apl.erl +++ b/src/riak_core_apl.erl @@ -24,13 +24,16 @@ %% ------------------------------------------------------------------- -module(riak_core_apl). -export([active_owners/1, active_owners/2, - get_apl/3, get_apl/4, get_apl_ann/3, get_apl_ann/4, + get_apl/3, get_apl/4, + get_apl_ann/2, get_apl_ann/3, get_apl_ann/4, + get_apl_ann_with_pnum/1, get_primary_apl/3, get_primary_apl/4, get_primary_apl_chbin/4, first_up/2, offline_owners/1, offline_owners/2 ]). --export_type([preflist/0, preflist_ann/0]). +-export_type([preflist/0, preflist_ann/0, preflist_with_pnum_ann/0]). + -ifdef(TEST). -include_lib("eunit/include/eunit.hrl"). -endif. @@ -40,13 +43,18 @@ -type ring() :: riak_core_ring:riak_core_ring(). -type preflist() :: [{index(), node()}]. -type preflist_ann() :: [{{index(), node()}, primary|fallback}]. +%% @type preflist_with_pnum_ann - +%% Annoated preflist where the partition value is an id/number +%% (0 to ring_size-1) instead of a hash. +-type preflist_with_pnum_ann() :: [{{riak_core_ring:partition_id(), node()}, + primary|fallback}]. -type iterator() :: term(). -type chashbin() :: term(). -type docidx() :: chash:index(). -%% Return preflist of all active primary nodes (with no -%% substituion of fallbacks). Used to simulate a -%% preflist with N=ring_size +%% @doc Return preflist of all active primary nodes (with no +%% substituion of fallbacks). Used to simulate a +%% preflist with N=ring_size. -spec active_owners(atom()) -> preflist_ann(). active_owners(Service) -> {ok, Ring} = riak_core_ring_manager:get_my_ring(), @@ -59,62 +67,81 @@ active_owners(Ring, UpNodes) -> {Up, _Pangs} = check_up(Primaries, UpNodes1, [], []), Up. -%% Get the active preflist taking account of which nodes are up +%% @doc Get the active preflist taking account of which nodes are up. -spec get_apl(docidx(), n_val(), atom()) -> preflist(). get_apl(DocIdx, N, Service) -> {ok, CHBin} = riak_core_ring_manager:get_chash_bin(), get_apl_chbin(DocIdx, N, CHBin, riak_core_node_watcher:nodes(Service)). -%% Get the active preflist taking account of which nodes are up -%% for a given chash/upnodes list +%% @doc Get the active preflist taking account of which nodes are up +%% for a given chash/upnodes list. -spec get_apl_chbin(docidx(), n_val(), chashbin:chashbin(), [node()]) -> preflist(). get_apl_chbin(DocIdx, N, CHBin, UpNodes) -> [{Partition, Node} || {{Partition, Node}, _Type} <- get_apl_ann_chbin(DocIdx, N, CHBin, UpNodes)]. -%% Get the active preflist taking account of which nodes are up -%% for a given ring/upnodes list +%% @doc Get the active preflist taking account of which nodes are up +%% for a given ring/upnodes list. -spec get_apl(docidx(), n_val(), ring(), [node()]) -> preflist(). get_apl(DocIdx, N, Ring, UpNodes) -> - [{Partition, Node} || {{Partition, Node}, _Type} <- + [{Partition, Node} || {{Partition, Node}, _Type} <- get_apl_ann(DocIdx, N, Ring, UpNodes)]. -%% Get the active preflist taking account of which nodes are up -%% and annotate each node with type of primary/fallback +%% @doc Get the active preflist taking account of which nodes are up for a given +%% chash/upnodes list and annotate each node with type of primary/fallback. get_apl_ann(DocIdx, N, UpNodes) -> {ok, CHBin} = riak_core_ring_manager:get_chash_bin(), get_apl_ann_chbin(DocIdx, N, CHBin, UpNodes). -%% Get the active preflist taking account of which nodes are up -%% for a given chash/upnodes list and annotate each node with type of -%% primary/fallback --spec get_apl_ann_chbin(binary(), n_val(), chashbin(), [node()]) -> preflist_ann(). -get_apl_ann_chbin(DocIdx, N, CHBin, UpNodes) -> - UpNodes1 = UpNodes, - Itr = chashbin:iterator(DocIdx, CHBin), - {Primaries, Itr2} = chashbin:itr_pop(N, Itr), - {Up, Pangs} = check_up(Primaries, UpNodes1, [], []), - Up ++ find_fallbacks_chbin(Pangs, Itr2, UpNodes1, []). - -%% Get the active preflist taking account of which nodes are up -%% for a given ring/upnodes list and annotate each node with type of -%% primary/fallback +%% @doc Get the active preflist taking account of which nodes are up +%% for a given ring/upnodes list and annotate each node with type of +%% primary/fallback. -spec get_apl_ann(binary(), n_val(), ring(), [node()]) -> preflist_ann(). get_apl_ann(DocIdx, N, Ring, UpNodes) -> UpNodes1 = UpNodes, Preflist = riak_core_ring:preflist(DocIdx, Ring), - {Primaries, Fallbacks} = lists:split(N, Preflist), {Up, Pangs} = check_up(Primaries, UpNodes1, [], []), Up ++ find_fallbacks(Pangs, Fallbacks, UpNodes1, []). -%% Same as get_apl, but returns only the primaries. +%% @doc Get the active preflist for a given {bucket, key} and list of nodes +%% and annotate each node with type of primary/fallback. +-spec get_apl_ann(riak_core_bucket:bucket(), [node()]) -> preflist_ann(). +get_apl_ann({Bucket, Key}, UpNodes) -> + BucketProps = riak_core_bucket:get_bucket(Bucket), + NVal = proplists:get_value(n_val, BucketProps), + DocIdx = riak_core_util:chash_key({Bucket, Key}), + get_apl_ann(DocIdx, NVal, UpNodes). + +%% @doc Get the active preflist taking account of which nodes are up +%% for a given {bucket, key} and annotate each node with type of +%% primary/fallback +-spec get_apl_ann_with_pnum(riak_core_bucket:bucket()) -> preflist_with_pnum_ann(). +get_apl_ann_with_pnum(BKey) -> + {ok, Ring} = riak_core_ring_manager:get_my_ring(), + UpNodes = riak_core_ring:all_members(Ring), + Apl = get_apl_ann(BKey, UpNodes), + Size = riak_core_ring:num_partitions(Ring), + apl_with_partition_nums(Apl, Size). + +%% @doc Get the active preflist taking account of which nodes are up +%% for a given chash/upnodes list and annotate each node with type of +%% primary/fallback. +-spec get_apl_ann_chbin(binary(), n_val(), chashbin(), [node()]) -> preflist_ann(). +get_apl_ann_chbin(DocIdx, N, CHBin, UpNodes) -> + UpNodes1 = UpNodes, + Itr = chashbin:iterator(DocIdx, CHBin), + {Primaries, Itr2} = chashbin:itr_pop(N, Itr), + {Up, Pangs} = check_up(Primaries, UpNodes1, [], []), + Up ++ find_fallbacks_chbin(Pangs, Itr2, UpNodes1, []). + +%% @doc Same as get_apl, but returns only the primaries. -spec get_primary_apl(binary(), n_val(), atom()) -> preflist_ann(). get_primary_apl(DocIdx, N, Service) -> {ok, CHBin} = riak_core_ring_manager:get_chash_bin(), get_primary_apl_chbin(DocIdx, N, CHBin, riak_core_node_watcher:nodes(Service)). -%% Same as get_apl, but returns only the primaries. +%% @doc Same as get_apl, but returns only the primaries. -spec get_primary_apl_chbin(binary(), n_val(), chashbin(), [node()]) -> preflist_ann(). get_primary_apl_chbin(DocIdx, N, CHBin, UpNodes) -> UpNodes1 = UpNodes, @@ -123,7 +150,7 @@ get_primary_apl_chbin(DocIdx, N, CHBin, UpNodes) -> {Up, _} = check_up(Primaries, UpNodes1, [], []), Up. -%% Same as get_apl, but returns only the primaries. +%% @doc Same as get_apl, but returns only the primaries. -spec get_primary_apl(binary(), n_val(), ring(), [node()]) -> preflist_ann(). get_primary_apl(DocIdx, N, Ring, UpNodes) -> UpNodes1 = UpNodes, @@ -132,8 +159,8 @@ get_primary_apl(DocIdx, N, Ring, UpNodes) -> {Up, _} = check_up(Primaries, UpNodes1, [], []), Up. -%% Return the first entry that is up in the preflist for `DocIdx'. This -%% will crash if all owning nodes are offline. +%% @doc Return the first entry that is up in the preflist for `DocIdx'. This +%% will crash if all owning nodes are offline. first_up(DocIdx, Service) -> {ok, CHBin} = riak_core_ring_manager:get_chash_bin(), Itr = chashbin:iterator(DocIdx, CHBin), @@ -154,7 +181,7 @@ offline_owners(Service, CHBin) -> end, CHBin), DownVNodes. -%% Split a preference list into up and down lists +%% @doc Split a preference list into up and down lists. -spec check_up(preflist(), [node()], preflist_ann(), preflist()) -> {preflist_ann(), preflist()}. check_up([], _UpNodes, Up, Pangs) -> {lists:reverse(Up), lists:reverse(Pangs)}; @@ -166,7 +193,7 @@ check_up([{Partition,Node}|Rest], UpNodes, Up, Pangs) -> check_up(Rest, UpNodes, Up, [{Partition, Node} | Pangs]) end. -%% Find fallbacks for downed nodes in the preference list +%% @doc Find fallbacks for downed nodes in the preference list. -spec find_fallbacks(preflist(), preflist(), [node()], preflist_ann()) -> preflist_ann(). find_fallbacks(_Pangs, [], _UpNodes, Secondaries) -> lists:reverse(Secondaries); @@ -181,7 +208,7 @@ find_fallbacks([{Partition, _Node}|Rest]=Pangs, [{_,FN}|Fallbacks], UpNodes, Sec find_fallbacks(Pangs, Fallbacks, UpNodes, Secondaries) end. -%% Find fallbacks for downed nodes in the preference list +%% @doc Find fallbacks for downed nodes in the preference list. -spec find_fallbacks_chbin(preflist(), iterator(),[node()], preflist_ann()) -> preflist_ann(). find_fallbacks_chbin([], _Fallbacks, _UpNodes, Secondaries) -> lists:reverse(Secondaries); @@ -198,10 +225,17 @@ find_fallbacks_chbin([{Partition, _Node}|Rest]=Pangs, Itr, UpNodes, Secondaries) find_fallbacks_chbin(Pangs, Itr2, UpNodes, Secondaries) end. -%% Return true if a node is up +%% @doc Return true if a node is up. is_up(Node, UpNodes) -> lists:member(Node, UpNodes). +%% @doc Return annotated preflist with partition ids/nums instead of hashes. +-spec apl_with_partition_nums(preflist_ann(), riak_core_ring:ring_size()) -> + preflist_with_pnum_ann(). +apl_with_partition_nums(Apl, Size) -> + [{{riak_core_ring_util:hash_to_partition_id(Hash, Size), Node}, Ann} || + {{Hash, Node}, Ann} <- Apl]. + -ifdef(TEST). smallest_test() -> @@ -213,12 +247,12 @@ four_node_test() -> Ring = perfect_ring(8, Nodes), ?assertEqual([{0,nodea}, {182687704666362864775460604089535377456991567872,nodeb}, - {365375409332725729550921208179070754913983135744,nodec}], + {365375409332725729550921208179070754913983135744,nodec}], get_apl(last_in_ring(), 3, Ring, Nodes)), %% With a node down ?assertEqual([{182687704666362864775460604089535377456991567872,nodeb}, {365375409332725729550921208179070754913983135744,nodec}, - {0,noded}], + {0,noded}], get_apl(last_in_ring(), 3, Ring, [nodeb, nodec, noded])), %% With two nodes down ?assertEqual([{365375409332725729550921208179070754913983135744,nodec}, @@ -231,8 +265,7 @@ four_node_test() -> {365375409332725729550921208179070754913983135744,nodea}], get_apl(last_in_ring(), 3, Ring, [nodea, nodeb])). - -%% Create a perfect ring - RingSize must be a multiple of nodes +%% @doc Create a perfect ring - RingSize must be a multiple of nodes perfect_ring(RingSize, Nodes) when RingSize rem length(Nodes) =:= 0 -> Ring = riak_core_ring:fresh(RingSize,node()), Owners = riak_core_ring:all_owners(Ring), @@ -326,6 +359,116 @@ six_node_test() -> ok. +six_node_bucket_key_ann_test() -> + {ok, [Ring0]} = file:consult("../test/my_ring"), + Nodes = ['dev1@127.0.0.1', 'dev2@127.0.0.1', 'dev3@127.0.0.1', + 'dev4@127.0.0.1', 'dev5@127.0.0.1', 'dev6@127.0.0.1'], + Ring = riak_core_ring:upgrade(Ring0), + Bucket = <<"favorite">>, + Key = <<"jethrotull">>, + application:set_env(riak_core, default_bucket_props, + [{n_val, 3}, + {chash_keyfun,{riak_core_util,chash_std_keyfun}}]), + riak_core_ring_manager:setup_ets(test), + riak_core_ring_manager:set_ring_global(Ring), + Size = riak_core_ring:num_partitions(Ring), + ?assertEqual([{{34, + 'dev5@127.0.0.1'}, + primary}, + {{35, + 'dev6@127.0.0.1'}, + primary}, + {{36, + 'dev1@127.0.0.1'}, + primary}], + apl_with_partition_nums( + get_apl_ann({Bucket, Key}, Nodes), Size)), + ?assertEqual([{{35, + 'dev6@127.0.0.1'}, + primary}, + {{36, + 'dev1@127.0.0.1'}, + primary}, + {{34, + 'dev2@127.0.0.1'}, + fallback}], + apl_with_partition_nums( + get_apl_ann({Bucket, Key}, Nodes -- + ['dev5@127.0.0.1']), Size)), + ?assertEqual([{{36, + 'dev1@127.0.0.1'}, + primary}, + {{34, + 'dev2@127.0.0.1'}, + fallback}, + {{35, + 'dev3@127.0.0.1'}, + fallback}], + apl_with_partition_nums( + get_apl_ann({Bucket, Key}, Nodes -- + ['dev5@127.0.0.1', + 'dev6@127.0.0.1']), Size)), + ?assertEqual([{{34, + 'dev2@127.0.0.1'}, + fallback}, + {{35, + 'dev3@127.0.0.1'}, + fallback}, + {{36, + 'dev4@127.0.0.1'}, + fallback}], + apl_with_partition_nums( + get_apl_ann({Bucket, Key}, Nodes -- + ['dev5@127.0.0.1', + 'dev6@127.0.0.1', + 'dev1@127.0.0.1']), Size)), + ?assertEqual([{{34, + 'dev3@127.0.0.1'}, + fallback}, + {{35, + 'dev4@127.0.0.1'}, + fallback}, + {{36, + 'dev3@127.0.0.1'}, + fallback}], + apl_with_partition_nums( + get_apl_ann({Bucket, Key}, Nodes -- + ['dev5@127.0.0.1', + 'dev6@127.0.0.1', + 'dev1@127.0.0.1', + 'dev2@127.0.0.1']), Size)), + ?assertEqual([{{34, + 'dev4@127.0.0.1'}, + fallback}, + {{35, + 'dev4@127.0.0.1'}, + fallback}, + {{36, + 'dev4@127.0.0.1'}, + fallback}], + apl_with_partition_nums( + get_apl_ann({Bucket, Key}, Nodes -- + ['dev5@127.0.0.1', + 'dev6@127.0.0.1', + 'dev1@127.0.0.1', + 'dev2@127.0.0.1', + 'dev3@127.0.0.1']), Size)), + ?assertEqual([{{34, + 'dev5@127.0.0.1'}, + primary}, + {{35, + 'dev6@127.0.0.1'}, + primary}, + {{36, + 'dev3@127.0.0.1'}, + fallback}], + apl_with_partition_nums( + get_apl_ann({Bucket, Key}, Nodes -- + ['dev1@127.0.0.1', + 'dev2@127.0.0.1']), Size)), + riak_core_ring_manager:cleanup_ets(test), + ok. + chbin_test_() -> {timeout, 180, fun chbin_test_scenario/0}. diff --git a/src/riak_core_bucket.erl b/src/riak_core_bucket.erl index d103318a8..3e11741d7 100644 --- a/src/riak_core_bucket.erl +++ b/src/riak_core_bucket.erl @@ -38,12 +38,16 @@ name/1, n_val/1]). +-export_type([bucket/0]). + -ifdef(TEST). -include_lib("eunit/include/eunit.hrl"). -endif. -define(METADATA_PREFIX, {core, buckets}). +-type bucket() :: binary() | {riak_core_bucket_type:bucket_type(), binary()}. + %% @doc Add a list of defaults to global list of defaults for new %% buckets. If any item is in Items is already set in the %% current defaults list, the new setting is omitted, and the old @@ -55,7 +59,7 @@ append_bucket_defaults(Items) when is_list(Items) -> %% @doc Set the given BucketProps in Bucket or {BucketType, Bucket}. If BucketType does not %% exist, or is not active, {error, no_type} is returned. --spec set_bucket(binary() | {riak_core_bucket_type:bucket_type(), binary()}, [{atom(), any()}]) -> +-spec set_bucket(bucket(), [{atom(), any()}]) -> ok | {error, no_type | [{atom(), atom()}]}. set_bucket({<<"default">>, Name}, BucketProps) -> set_bucket(Name, BucketProps); diff --git a/src/riak_core_ring.erl b/src/riak_core_ring.erl index 2978bbaa1..ceae9293d 100644 --- a/src/riak_core_ring.erl +++ b/src/riak_core_ring.erl @@ -135,7 +135,7 @@ vnode_type/2, deletion_complete/3]). --export_type([riak_core_ring/0]). +-export_type([riak_core_ring/0, ring_size/0, partition_id/0]). -ifdef(TEST). -include_lib("eunit/include/eunit.hrl"). @@ -156,7 +156,7 @@ claimant :: term(), seen :: [{term(), vclock:vclock()}], rvsn :: vclock:vclock() -}). +}). %% Legacy chstate -record(chstate, { @@ -164,19 +164,19 @@ vclock, % for this chstate object, entries are {Node, Ctr} chring :: chash:chash(), % chash ring of {IndexAsInt, Node} mappings meta % dict of cluster-wide other data (primarily bucket N-value, etc) -}). +}). -type member_status() :: joining | valid | invalid | leaving | exiting | down. %% type meta_entry(). Record for each entry in #chstate.meta -record(meta_entry, { value, % The value stored under this entry - lastmod % The last modified time of this entry, + lastmod % The last modified time of this entry, % from calendar:datetime_to_gregorian_seconds( - % calendar:universal_time()), + % calendar:universal_time()), }). -%% riak_core_ring() is the opaque data type used for partition ownership +%% @type riak_core_ring() is the opaque data type used for partition ownership -type riak_core_ring() :: ?CHSTATE{}. -type chstate() :: riak_core_ring(). @@ -187,6 +187,11 @@ -type resize_transfer() :: {{integer(),term()}, ordsets:ordset(node()), awaiting | complete}. +-type ring_size() :: non_neg_integer(). +%% @type partition_id() (or partition number) - +%% This integer represents a value in the range [0, ring_size-1]. +-type partition_id() :: non_neg_integer(). + %% =================================================================== %% Public API %% =================================================================== @@ -345,7 +350,7 @@ fresh(NodeName) -> %% @doc Equivalent to fresh/1 but allows specification of the ring size. %% Called by fresh/1, and otherwise only intended for testing purposes. --spec fresh(RingSize :: integer(), NodeName :: term()) -> chstate(). +-spec fresh(ring_size(), NodeName :: term()) -> chstate(). fresh(RingSize, NodeName) -> VClock=vclock:increment(NodeName, vclock:fresh()), GossipVsn = riak_core_gossip:gossip_version(), @@ -363,7 +368,7 @@ fresh(RingSize, NodeName) -> %% @doc change the size of the ring to `NewRingSize'. If the ring %% is larger than the current ring any new indexes will be owned %% by a dummy host --spec resize(chstate(), pos_integer()) -> chstate(). +-spec resize(chstate(), ring_size()) -> chstate(). resize(State, NewRingSize) -> NewRing = lists:foldl(fun({Idx,Owner}, RingAcc) -> chash:update(Idx, Owner, RingAcc) @@ -373,9 +378,9 @@ resize(State, NewRingSize) -> set_chash(State, NewRing). % @doc Return a value from the cluster metadata dict --spec get_meta(Key :: term(), State :: chstate()) -> +-spec get_meta(Key :: term(), State :: chstate()) -> {ok, term()} | undefined. -get_meta(Key, State) -> +get_meta(Key, State) -> case dict:find(Key, State?CHSTATE.meta) of error -> undefined; {ok, '$removed'} -> undefined; @@ -495,7 +500,7 @@ reconcile(ExternState, MyState) -> check_tainted(ExternState, "Error: riak_core_ring/reconcile :: " "reconciling tainted external ring"), - check_tainted(MyState, + check_tainted(MyState, "Error: riak_core_ring/reconcile :: " "reconciling tainted internal ring"), case internal_reconcile(MyState, ExternState) of @@ -515,7 +520,7 @@ rename_node(State=?CHSTATE{chring=Ring, nodename=ThisNode, members=Members, chring=lists:foldl( fun({Idx, Owner}, AccIn) -> case Owner of - OldNode -> + OldNode -> chash:update(Idx, NewNode, AccIn); _ -> AccIn end @@ -639,7 +644,7 @@ update_meta(Key, Val, State) -> true end, if Change -> - M = #meta_entry { + M = #meta_entry { lastmod = calendar:datetime_to_gregorian_seconds( calendar:universal_time()), value = Val @@ -726,7 +731,7 @@ get_member_meta(State, Member, Key) -> Value end end. - + %% @doc Set a key in the member metadata orddict update_member_meta(Node, State, Member, Key, Val) -> VClock = vclock:increment(Node, State?CHSTATE.vclock), @@ -1241,7 +1246,7 @@ ring_ready_info(State0) -> and lists:member(Node, Members) end, Seen), Outdated. - + %% @doc Marks a pending transfer as completed. -spec handoff_complete(State :: chstate(), Idx :: integer(), Mod :: module()) -> chstate(). @@ -1363,7 +1368,7 @@ cancel_transfers(Ring) -> %% @doc Incorporate another node's state into our view of the Riak world. legacy_reconcile(ExternState, MyState) -> case vclock:equal(MyState#chstate.vclock, vclock:fresh()) of - true -> + true -> {new_ring, #chstate{nodename=MyState#chstate.nodename, vclock=ExternState#chstate.vclock, chring=ExternState#chstate.chring, @@ -1381,7 +1386,7 @@ legacy_reconcile(ExternState, MyState) -> meta=ExternState#chstate.meta}}; false -> {no_change, MyState} end; - [] -> + [] -> case legacy_equal_rings(ExternState,MyState) of true -> {no_change, MyState}; false -> {new_ring, @@ -1450,7 +1455,7 @@ pick_val(M1,M2) -> case M1#meta_entry.lastmod > M2#meta_entry.lastmod of true -> M1; false -> M2 - end. + end. %% @private internal_reconcile(State, OtherState) -> @@ -1852,7 +1857,7 @@ rename_test() -> ?assertEqual('new@new', owner_node(Ring)), ?assertEqual(['new@new'], all_members(Ring)). -exclusion_test() -> +exclusion_test() -> Ring0 = fresh(2, node()), Ring1 = transfer_node(0,x,Ring0), ?assertEqual(0, random_other_index(Ring1,[730750818665451459101842416358141509827966271488])), @@ -1877,7 +1882,7 @@ membership_test() -> RingA4 = remove_member(nodeA, RingA3, nodeC), ?assertEqual([nodeA, nodeB], all_members(RingA4)), - + %% Node should stay removed {_, RingA5} = reconcile(RingA3, RingA4), ?assertEqual([nodeA, nodeB], all_members(RingA5)), @@ -1926,7 +1931,7 @@ membership_test() -> end || {StatusA, _} <- Priority, {StatusB, _} <- Priority], ok. - + ring_version_test() -> Ring1 = fresh(nodeA), Ring2 = add_member(node(), Ring1, nodeA), diff --git a/src/riak_core_ring_util.erl b/src/riak_core_ring_util.erl index e7f01c1d5..5b27783e4 100644 --- a/src/riak_core_ring_util.erl +++ b/src/riak_core_ring_util.erl @@ -29,8 +29,6 @@ partition_id_to_hash/2, hash_is_partition_boundary/2]). --export_type([partition_id/0]). - -ifdef(TEST). -ifdef(EQC). -export([prop_ids_are_boundaries/0, prop_reverse/0, @@ -41,9 +39,6 @@ -include_lib("eunit/include/eunit.hrl"). -endif. --type partition_id() :: non_neg_integer(). -%% This integer represents a value in the range [0, ring_size) - %% @doc Forcibly assign a partition to a specific node assign(Partition, ToNode) -> F = fun(Ring, _) -> @@ -76,8 +71,8 @@ check_ring(Ring, Nval) -> end, [], Preflists). -spec hash_to_partition_id(chash:index() | chash:index_as_int(), - pos_integer()) -> - partition_id(). + riak_core_ring:ring_size()) -> + riak_core_ring:partition_id(). %% @doc Map a key hash (as binary or integer) to a partition ID [0, ring_size) hash_to_partition_id(CHashKey, RingSize) when is_binary(CHashKey) -> <> = CHashKey, @@ -85,7 +80,8 @@ hash_to_partition_id(CHashKey, RingSize) when is_binary(CHashKey) -> hash_to_partition_id(CHashInt, RingSize) -> CHashInt div chash:ring_increment(RingSize). --spec partition_id_to_hash(partition_id(), pos_integer()) -> chash:index_as_int(). +-spec partition_id_to_hash(riak_core_ring:partition_id(), pos_integer()) -> + chash:index_as_int(). %% @doc Identify the first key hash (integer form) in a partition ID [0, ring_size) partition_id_to_hash(Id, RingSize) -> Id * chash:ring_increment(RingSize).