Skip to content

Commit

Permalink
Merge 7101e9d into 0733f18
Browse files Browse the repository at this point in the history
  • Loading branch information
Tronso committed Nov 24, 2020
2 parents 0733f18 + 7101e9d commit 7db590f
Show file tree
Hide file tree
Showing 21 changed files with 2,003 additions and 125 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ rebar3.crashdump
.rebar3/
core_vnode_eqc.log
.idea
.vscode/
*.iml
**/*.coverdata
1 change: 1 addition & 0 deletions docs/Diagrams.drawio

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/chash.erl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

-module(chash).


-export([contains_name/2, fresh/2, lookup/2, key_of/1,
members/1, merge_rings/2, next_index/2, nodes/1,
predecessors/2, predecessors/3, ring_increment/1,
Expand Down
27 changes: 18 additions & 9 deletions src/chashbin.erl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
%% -------------------------------------------------------------------
-module(chashbin).


-export([create/1, to_chash/1, to_list/1,
to_list_filter/2, responsible_index/2,
responsible_position/2, index_owner/2,
Expand Down Expand Up @@ -164,6 +165,16 @@ iterator(HashKey, CHBin) ->
Pos = responsible_position(HashKey, CHBin),
#iterator{pos = Pos, start = Pos, chbin = CHBin}.

%% @doc Return iterator pointing to the given index
-spec exact_iterator(Index :: index() | <<_:160>>,
CHBin :: chashbin()) -> iterator().

exact_iterator(<<Idx:160/integer>>, CHBin) ->
exact_iterator(Idx, CHBin);
exact_iterator(Idx, CHBin) ->
Pos = index_position(Idx, CHBin),
#iterator{pos = Pos, start = Pos, chbin = CHBin}.

%% @doc Return the `{Index, Owner}' pair pointed to by the iterator
-spec itr_value(iterator()) -> {index(), node()}.

Expand Down Expand Up @@ -231,7 +242,8 @@ itr_next_while(Pred, Itr) ->
%% Internal functions
%% ===================================================================

%% Convert list of {Index, Owner} pairs into `chashbin' binary representation
%% @private
%% @doc Convert list of {Index, Owner} pairs into `chashbin' binary representation
-spec create_bin([{index(), node()}],
[{node(), pos_integer()}], binary()) -> owners_bin().

Expand All @@ -241,15 +253,12 @@ create_bin([{Idx, Owner} | Owners], Nodes, Bin) ->
Bin2 = <<Bin/binary, Idx:160/integer, Id:16/integer>>,
create_bin(Owners, Nodes, Bin2).

%% Convert ring index into ring position
%% @private
%% @doc Convert ring index into ring position
-spec index_position(Index :: index() | <<_:160>>,
CHBin :: chashbin()) -> integer().

index_position(<<Idx:160/integer>>, CHBin) ->
index_position(Idx, CHBin);
index_position(Idx, #chashbin{size = Size}) ->
Inc = chash:ring_increment(Size), Idx div Inc rem Size.

%% Return iterator pointing to the given index
exact_iterator(<<Idx:160/integer>>, CHBin) ->
exact_iterator(Idx, CHBin);
exact_iterator(Idx, CHBin) ->
Pos = index_position(Idx, CHBin),
#iterator{pos = Pos, start = Pos, chbin = CHBin}.
13 changes: 6 additions & 7 deletions src/gen_nb_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,12 @@
{stop, Reason :: term(),
NewState :: term()}.

%% @spec start_link(Module, IpAddr, Port, InitParams) -> Result
%% Module = atom()
%% IpAddr = string()
%% Port = integer()
%% InitParams = [any()]
%% Result = {ok, pid()} | {error, any()}
%% @doc Start server listening on IpAddr:Port
%% @doc Start server listening on `IpAddr:Port'.
-spec start_link(Module :: atom(), IpAddr :: string(),
Port :: integer(), INitParams :: [any()]) -> {ok,
pid()} |
{error, any()}.

start_link(Module, IpAddr, Port, InitParams) ->
gen_server:start_link(?MODULE,
[Module, IpAddr, Port, InitParams], []).
Expand Down
Loading

0 comments on commit 7db590f

Please sign in to comment.