stvp / dht

Golang implementation of a distributed hash table using Consul and rendezvous hashing

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

dht

dht is a distributed hash table implementation that uses Consul and rendezvous hashing to distribute keys among distributed nodes. Because it uses rendezvous hashing to determine key placement, removing a node from the hash table is minimally disruptive in terms of key re-assignment.

Local hash table state is refreshed in a background goroutine using blocking Consul API queries with the default consistency mode. Errors encountered in the background goroutine are logged using the log package in the following format:

[dht <name> <id>] error: <error message>

dht requires a locally-running Consul agent (version 0.5.2 or newer) with its HTTP API listening on 127.0.0.1:8500. dht nodes run a simple HTTP server on an available ephemeral port to allow Consul to periodically check that the node is still alive.

Example

node1, err := dht.Join("worker", "worker-1")
node2, err := dht.Join("worker", "worker-2")

node1.Member("some_key") // true
node2.Member("some_key") // false

err = node1.Leave()
err = node2.Leave()

About

Golang implementation of a distributed hash table using Consul and rendezvous hashing

License:MIT License


Languages

Language:Go 100.0%