Git Product home page Git Product logo

dht_ring's Introduction

An implementation of consistent hashing ring for distributed hash tables as
a gen_server.

Here is an informal explanation of the technique:
  http://www.spiteful.com/2008/03/17/programmers-toolbox-part-3-consistent-hashing/

Exports:

start_link(Peers) -> ServerRef
start_link(ServerName, Peers) -> ServerRef
  Types:
    Peers = [{Node, Opaque, Weight}]
    Node = term()
    Opaque = term()
    Weight = int(), >= 1

  Create a ring according to peer configuration Peers. Opaque is an opaque
  data associated with the node. Greater weight makes the node own bigger
  portion of the ring.

  The ring creation time is N^2 where N is the sum of the nodes' weights.


add(ServerRef, Peers) -> ok | {error, already_there, [Node]}

  Add Peers to the ring. If any of the nodes being added is already in the
  ring (the check is done by comparing node *names*), error is returned and
  the ring remains intact.


add(ServerRef, {Node, Opaque, Weight})

  Equivalent to add(ServerRef, [{Node, Opaque, Weight}]).


delete(ServerRef, [Node]) -> ok | {error, unknown_nodes, [Node]}

  Removes nodes from the ring by their names. If any of the names doesn't
  reference an existing node in the ring, an error is returned and the ring
  remains intact.


delete(ServerRef, Node)

  Equivalent to delete(ServerRef, [Node]).


get_config(ServerRef) -> Peers

  Returns the current configuration of the ring. The order of nodes within
  the returned list is not specified.


lookup(ServerRef, Key) -> [{Node, Opaque}]

  Types:
    Key = term()

  Look up the Ring for a list of nodes corresponding to Key. The returned
  list is guaranteed to contain no duplicates.

  The lookup time is log(N), where N is the sum of the nodes' weights.


nodes(ServerRef) -> [{Node, Opaque}]

  Return the list of nodes in the ring. The order of nodes in the returned
  list is not specified, but it is guaranteed that the list contains no
  duplicates.

  This operation execution time is constant.

dht_ring's People

Contributors

lukyanov avatar zaa avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.