anchor.diff:  %%--------------------------------------------------------------------
   %% @doc
   %% Get nodes that are responsible for the data labeled with given term.
  -%% @end
  -%%--------------------------------------------------------------------
  --spec get_nodes(term(), non_neg_integer()) -> [node()].
  -get_nodes(Label, NodesNum) ->
  -    case get_chash_ring() of
  -        undefined ->
  -            error(chash_ring_not_initialized);
  -        #ring{type = single_node, chash = Node} ->
  -            [Node];
  -        #ring{type = multi_node, chash = CHash} ->
  -            Index = chash:key_of(Label),
  -            lists:map(fun({_, Node}) -> Node end, chash:successors(Index, CHash, NodesNum));
  -        #ring{type = broken, chash = CHash, broken_nodes = BrokenNodes} ->
  -            Index = chash:key_of(Label),
  -            lists:map(fun({_, Node}) ->
  -                case lists:member(Node, BrokenNodes) of
  -                    true -> throw(broken_node);
  -                    false -> Node
  -                end
  -            end, chash:successors(Index, CHash, NodesNum))
  -    end.
  -
  -%%--------------------------------------------------------------------
  -%% @doc
  -%% Get nodes that are responsible for the data labeled with given term.
   %% Returns two lists: alvie and broken nodes.
   %% @end
   %%--------------------------------------------------------------------
  --spec get_alive_and_broken_nodes(term(), non_neg_integer()) -> {AliveNodes :: [node()], BrokenNodes :: [node()]}.
  -get_alive_and_broken_nodes(Label, NodesNum) ->
  +-spec get_nodes(term(), non_neg_integer() | all) ->
  +    {KeyConnectedNodes :: [node()], OtherRequestedNodes :: [node()], BrokenNodes :: [node()]}.
  +get_nodes(Label, RequestedNodesNum) ->
       case get_chash_ring() of
           undefined ->
               error(chash_ring_not_initialized);
           #ring{type = single_node, chash = Node} ->
               {[Node], []};
  -        #ring{type = multi_node, chash = CHash} ->
  -            Index = chash:key_of(Label),
  -            Nodes = lists:map(fun({_, Node}) -> Node end, chash:successors(Index, CHash, NodesNum)),
  -            {Nodes, []};
  -        #ring{type = broken, chash = CHash, broken_nodes = BrokenNodes} ->
  -            Index = chash:key_of(Label),
  -            Nodes = chash:successors(Index, CHash, NodesNum),
  -            filter_nodes(Nodes, BrokenNodes)
  +        #ring{type = multi_node, chash = CHash, key_connected_nodes = KeyConnectedNodesNum} ->
  +            Index = chash:key_of(Label),
  +            Nodes = case RequestedNodesNum of
  +                all -> get_all_nodes();
  +                _ -> lists:map(fun({_, Node}) -> Node end,
  +                    chash:successors(Index, CHash, max(KeyConnectedNodesNum, RequestedNodesNum)))
  +            end,
  +            {KeyConnectedNodes, OtherRequestedNodes} = lists:split(min(KeyConnectedNodesNum, length(Nodes)), Nodes),
  +            {KeyConnectedNodes, OtherRequestedNodes, []};
  +        #ring{type = broken, chash = CHash, broken_nodes = BrokenNodes,
  +            key_connected_nodes = KeyConnectedNodesNum} ->
  +            Index = chash:key_of(Label),
  +            Nodes = case RequestedNodesNum of
  +                all -> get_all_nodes();
  +                _ -> chash:successors(Index, CHash, max(KeyConnectedNodesNum, RequestedNodesNum))
  +            end,
  +            {KeyConnectedNodes, OtherRequestedNodes} = lists:split(min(KeyConnectedNodesNum, length(Nodes)), Nodes),
  +            {AliveKeyConnectedNodes, BrokenKeyConnectedNodes} = filter_nodes(KeyConnectedNodes, BrokenNodes),
  +            {AliveOtherRequestedNodes, BrokenOtherRequestedNodes} = filter_nodes(OtherRequestedNodes, BrokenNodes),
  +            {AliveKeyConnectedNodes, AliveOtherRequestedNodes, BrokenKeyConnectedNodes ++ BrokenOtherRequestedNodes}
       end.
   
   %%--------------------------------------------------------------------
  
positive.code: %% @doc
  %% Initialize chash ring
  %% @end
  %%--------------------------------------------------------------------
  -spec init([node()]) -> ok.
  init([Node]) ->
      set_chash_ring(#ring{type = single_node, chash = Node});
  
negative.code: -record(ring, {
      type :: single_node | multi_node | broken,
      chash :: chash:chash() | node(),
      broken_nodes = [] :: [node()],
      key_connected_nodes = 1 :: pos_integer()
  }).
  
  -type ring() :: #ring{}.
  
  %% API
  -export([init/1, cleanup/0, get_chash_ring/0, set_chash_ring/1,
      set_broken_node/1, set_fixed_node/1, set_key_connected_nodes/1,
      get_node/1, get_nodes/2, get_all_nodes/0]).
  
  %%%===================================================================
  %%% API
  