Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Centralize definition of binary and integer chash offset values.

  • Loading branch information...
commit 7663b75dd8dff4f8915875268fdfa46f201a0f32 1 parent ab7024b
@seancribbs seancribbs authored
View
2  include/riak_core_handoff.hrl
@@ -17,7 +17,7 @@
-type ho_type() :: ownership_handoff | hinted_handoff | repair | resize_transfer.
-type predicate() :: fun((any()) -> boolean()).
--type index() :: integer().
+-type index() :: chash:index_as_int().
-type mod_src_tgt() :: {module(), index(), index()} | {undefined, undefined, undefined}.
-type mod_partition() :: {module(), index()}.
View
2  include/riak_core_vnode.hrl
@@ -6,7 +6,7 @@
{fsm, undefined, pid()} | % special case in
% riak_kv_util:make_request/2.erl
ignore.
--type partition() :: non_neg_integer().
+-type partition() :: chash:index_as_int().
-type vnode_req() :: term().
-type keyspaces() :: [{partition(), [partition()]}].
View
6 src/chash.erl
@@ -50,7 +50,7 @@
successors/3,
update/3]).
--export_type([chash/0, index/0]).
+-export_type([chash/0, index/0, index_as_int/0]).
-define(RINGTOP, trunc(math:pow(2,160)-1)). % SHA-1 space
@@ -65,10 +65,10 @@
-type chash_node() :: term().
%% Indices into the ring, used as keys for object location, are binary
%% representations of 160-bit integers.
--type index() :: binary().
+-type index() :: <<_:160>>.
-type index_as_int() :: integer().
-type node_entry() :: {index_as_int(), chash_node()}.
--type num_partitions() :: integer().
+-type num_partitions() :: pos_integer().
%% ===================================================================
%% Public API
View
4 src/chashbin.erl
@@ -31,9 +31,9 @@
-define(ENTRY, binary-unit:?UNIT).
-type owners_bin() :: <<_:_*?UNIT>>.
--type index() :: non_neg_integer().
+-type index() :: chash:index_as_int().
-type pred_fun() :: fun(({index(), node()}) -> boolean()).
--type chash_key() :: <<_:160>> | non_neg_integer().
+-type chash_key() :: index() | chash:index().
-record(chashbin, {size :: pos_integer(),
owners :: owners_bin(),
View
2  src/riak_core_apl.erl
@@ -35,7 +35,7 @@
-include_lib("eunit/include/eunit.hrl").
-endif.
--type index() :: non_neg_integer().
+-type index() :: chash:index_as_int().
-type n_val() :: non_neg_integer().
-type ring() :: riak_core_ring:riak_core_ring().
-type preflist() :: [{index(), node()}].
View
2  src/riak_core_coverage_plan.erl
@@ -29,7 +29,7 @@
%% API
-export([create_plan/5]).
--type index() :: non_neg_integer().
+-type index() :: chash:index_as_int().
-type req_id() :: non_neg_integer().
-type coverage_vnodes() :: [{index(), node()}].
-type vnode_filters() :: [{node(), [{index(), [index()]}]}].
View
14 src/riak_core_ring.erl
@@ -273,7 +273,7 @@ nearly_equal(RingA, RingB) ->
%% @doc Determine if a given Index/Node `IdxNode' combination is a
%% primary.
--spec is_primary(chstate(), {integer(), node()}) -> boolean().
+-spec is_primary(chstate(), {chash:index_as_int(), node()}) -> boolean().
is_primary(Ring, IdxNode) ->
Owners = all_owners(Ring),
lists:member(IdxNode, Owners).
@@ -402,7 +402,7 @@ get_buckets(State) ->
end, [], Keys).
%% @doc Return the node that owns the given index.
--spec index_owner(State :: chstate(), Idx :: integer()) -> Node :: term().
+-spec index_owner(State :: chstate(), Idx :: chash:index_as_int()) -> Node :: term().
index_owner(State, Idx) ->
{Idx, Owner} = lists:keyfind(Idx, 1, all_owners(State)),
Owner.
@@ -410,12 +410,12 @@ index_owner(State, Idx) ->
%% @doc Return the node that will own this index after transtions have completed
%% this function will error if the ring is shrinking and Idx no longer exists
%% in it
--spec future_owner(chstate(), integer()) -> term().
+-spec future_owner(chstate(), chash:index_as_int()) -> term().
future_owner(State, Idx) ->
index_owner(future_ring(State), Idx).
%% @doc Return all partition indices owned by the node executing this function.
--spec my_indices(State :: chstate()) -> [integer()].
+-spec my_indices(State :: chstate()) -> [chash:index_as_int()].
my_indices(State) ->
[I || {I,Owner} <- ?MODULE:all_owners(State), Owner =:= node()].
@@ -439,7 +439,7 @@ owner_node(State) ->
%% @doc For a given object key, produce the ordered list of
%% {partition,node} pairs that could be responsible for that object.
-spec preflist(Key :: binary(), State :: chstate()) ->
- [{Index :: integer(), Node :: term()}].
+ [{Index :: chash:index_as_int(), Node :: term()}].
preflist(Key, State) -> chash:successors(Key, State?CHSTATE.chring).
%% @doc Return a randomly-chosen node from amongst the owners.
@@ -450,7 +450,7 @@ random_node(State) ->
%% @doc Return a partition index not owned by the node executing this function.
%% If this node owns all partitions, return any index.
--spec random_other_index(State :: chstate()) -> integer().
+-spec random_other_index(State :: chstate()) -> chash:index_as_int().
random_other_index(State) ->
L = [I || {I,Owner} <- ?MODULE:all_owners(State), Owner =/= node()],
case L of
@@ -458,7 +458,7 @@ random_other_index(State) ->
_ -> lists:nth(random:uniform(length(L)), L)
end.
--spec random_other_index(State :: chstate(), Exclude :: [term()]) -> integer() | no_indices.
+-spec random_other_index(State :: chstate(), Exclude :: [term()]) -> chash:index_as_int() | no_indices.
random_other_index(State, Exclude) when is_list(Exclude) ->
L = [I || {I, Owner} <- ?MODULE:all_owners(State),
Owner =/= node(),
Please sign in to comment.
Something went wrong with that request. Please try again.