Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

78 - Documentation : First batch of modules #79

Merged
merged 21 commits into from
Nov 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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