Documentation ¶
Index ¶
- type AffinityGroup
- type AffinityGroupRPC
- type Client
- func (c *Client) Delete(key []byte, tuple TupleHost) error
- func (c *Client) Insert(key []byte, tuple TupleHost) error
- func (c *Client) Lookup(key []byte) ([]*kelipspb.Node, error)
- func (c *Client) LookupGroupNodes(key []byte) ([]*kelipspb.Node, error)
- func (c *Client) LookupNodes(key []byte, min int) ([]*kelipspb.Node, error)
- type Config
- type InmemTuples
- func (ft *InmemTuples) Count() int
- func (ft *InmemTuples) Delete(key []byte) error
- func (ft *InmemTuples) DeleteKeyHost(key []byte, h TupleHost) bool
- func (ft *InmemTuples) ExpireHost(tuple TupleHost) bool
- func (ft *InmemTuples) Get(key []byte) ([]TupleHost, error)
- func (ft *InmemTuples) Insert(key []byte, h TupleHost) error
- func (ft *InmemTuples) Iter(f func(key []byte, hosts []TupleHost) bool)
- type Kelips
- func (kelips *Kelips) AddNode(node *kelipspb.Node, force bool) error
- func (kelips *Kelips) Delete(key []byte, tuple TupleHost) (err error)
- func (kelips *Kelips) Insert(key []byte, tuple TupleHost) error
- func (kelips *Kelips) Join(peers []string) error
- func (kelips *Kelips) LocalNode() kelipspb.Node
- func (kelips *Kelips) Lookup(key []byte) ([]*kelipspb.Node, error)
- func (kelips *Kelips) LookupGroupNodes(key []byte) ([]*kelipspb.Node, error)
- func (kelips *Kelips) LookupNodes(key []byte, min int) ([]*kelipspb.Node, error)
- func (kelips *Kelips) PingNode(hostname string, coord *vivaldi.Coordinate, rtt time.Duration) error
- func (kelips *Kelips) RemoveNode(hostname string) error
- func (kelips *Kelips) Seed(snapshot *kelipspb.Snapshot) error
- func (kelips *Kelips) Snapshot() *kelipspb.Snapshot
- type Transport
- type TupleHost
- type TupleStore
- type UDPTransport
- func (trans *UDPTransport) Delete(host string, key []byte, tuple TupleHost, propogate bool) error
- func (trans *UDPTransport) Insert(host string, key []byte, tuple TupleHost, propogate bool) error
- func (trans *UDPTransport) Lookup(host string, key []byte) ([]*kelipspb.Node, error)
- func (trans *UDPTransport) LookupGroupNodes(host string, key []byte) ([]*kelipspb.Node, error)
- func (trans *UDPTransport) LookupNodes(host string, key []byte, min int) ([]*kelipspb.Node, error)
- func (trans *UDPTransport) Register(group AffinityGroupRPC)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AffinityGroup ¶
AffinityGroup is an interface used for group lookups. This is used to get nodes in a group
type AffinityGroupRPC ¶
type AffinityGroupRPC interface { // Lookup nodes returning the min amount LookupNodes(key []byte, min int) ([]*kelipspb.Node, error) // Return all nodes for key group LookupGroupNodes(key []byte) ([]*kelipspb.Node, error) // Lookup nodes from the local view Lookup(key []byte) ([]*kelipspb.Node, error) // Insert to local group Insert(key []byte, tuple TupleHost, propogate bool) error // Delete from local group Delete(key []byte, tuple TupleHost, propogate bool) error }
AffinityGroupRPC implements an interface for local rpc's used by the transport
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client implements a kelips client
func (*Client) LookupGroupNodes ¶
LookupGroupNodes requests group nodes for a key from a peer
type Config ¶
type Config struct { // AdvertiseHost used to compute the hash. This may be different from the // transport address AdvertiseHost string // Number of affinity groups K int // Setting this to true will cause writes to be propogated to all nodes in // in the group. The default is false relying on the underlying gossip // transport to provide propogation EnablePropogation bool // Hash function to use HashFunc func() hash.Hash // Tuple store. Defaults in an in-mem one if not specified TupleStore TupleStore Region string Sector string Zone string // Meta is serialized to binary and made part of the node object Meta map[string]string }
Config holds the kelips config to initialize the dht
func DefaultConfig ¶
DefaultConfig returns a minimum required config
type InmemTuples ¶
type InmemTuples struct {
// contains filtered or unexported fields
}
InmemTuples implements an in-memory TupleStore
func NewInmemTuples ¶
func NewInmemTuples() *InmemTuples
NewInmemTuples instantiates an in-memory tuple store
func (*InmemTuples) Count ¶
func (ft *InmemTuples) Count() int
Count returns the total number of keys in the store
func (*InmemTuples) Delete ¶
func (ft *InmemTuples) Delete(key []byte) error
Delete deletes a key removing all associated TupleHosts
func (*InmemTuples) DeleteKeyHost ¶
func (ft *InmemTuples) DeleteKeyHost(key []byte, h TupleHost) bool
DeleteKeyHost deletes a host associated to the name returning true if it was deleted
func (*InmemTuples) ExpireHost ¶
func (ft *InmemTuples) ExpireHost(tuple TupleHost) bool
ExpireHost removes a host from all keys referring to it
func (*InmemTuples) Get ¶
func (ft *InmemTuples) Get(key []byte) ([]TupleHost, error)
Get returns a list of hosts for a key. It returns nil if the name is not found
type Kelips ¶
type Kelips struct {
// contains filtered or unexported fields
}
Kelips is the core engine of the dht. It provides functions to operate against it. The gossip layer is not included as part of the implementation but rather methods have been provided such that they can be called from a gossip interface
func Create ¶
Create instantiates kelips and registers the local group to the transport. It inits an in-memory tuple store
func (*Kelips) AddNode ¶
AddNode adds a node to the DHT. It calculates the node id and adds it to the group it belongs to
func (*Kelips) Delete ¶
Delete deletes a key and all assoicated tuples. If the key belongs to a foreign group the delete is forwarded to a node in that group and its response is returned
func (*Kelips) Insert ¶
Insert inserts a key and associated tuple. If the key belongs to a foreign group, the insert is forwarded to a node in that group and its response is returned. If the TupleHost is not known it will not be returned in a lookup though will still be in the tuple store. Once the node is known/alive it will be returned in lookups
func (*Kelips) Lookup ¶
Lookup hashes the key and finds its affinity group. If the group is local it returns all local known nodes for the key otherwise it makes a Lookup call on the owning foreign group and returns its nodes
func (*Kelips) LookupGroupNodes ¶
LookupGroupNodes returns all nodes in a group for the key
func (*Kelips) LookupNodes ¶
LookupNodes returns a minimum of n nodes that a key maps to
func (*Kelips) PingNode ¶
PingNode sets the coords and rtt on a node and updates the heartbeat count
func (*Kelips) RemoveNode ¶
RemoveNode removes a node from the DHT. This will remove the node from the local nodes view as well as remove all references in the tuples
type Transport ¶
type Transport interface { LookupGroupNodes(host string, key []byte) ([]*kelipspb.Node, error) Lookup(host string, key []byte) ([]*kelipspb.Node, error) Insert(host string, key []byte, tuple TupleHost, propogate bool) error Delete(host string, key []byte, tuple TupleHost, propogate bool) error // Register a local affinity group Register(AffinityGroupRPC) }
Transport implements RPC's needed by kelips
type TupleHost ¶
type TupleHost []byte
TupleHost is the host port of a key tuple
func NewTupleFromIPPort ¶
NewTupleFromIPPort creates a new tuple with an ip an port
func NewTupleHost ¶
NewTupleHost creates a tuple from a host:port string
func NewTupleHostFromHostPort ¶
NewTupleHostFromHostPort creates a tuple from a ip string and port
type TupleStore ¶
type TupleStore interface { // Iter iterates over all the tuples. If the callback returns false, iteration // is terminated Iter(f func(key []byte, hosts []TupleHost) bool) // Count returns the total number of keys in the store Count() int // Insert adds a new host for a name if it does not already exist. It returns true // if the host was added Insert(key []byte, h TupleHost) error // Delete deletes a key removing all associated TupleHosts Delete(key []byte) error // Get returns a list of hosts for a key. It returns nil if the name is not // found Get(key []byte) ([]TupleHost, error) // DeleteKeyHost deletes a host associated to the name returning true if it was deleted DeleteKeyHost(key []byte, h TupleHost) bool // ExpireHost removes a host from all keys referring to it ExpireHost(tuple TupleHost) bool }
TupleStore is used to store and interact with tuples
type UDPTransport ¶
type UDPTransport struct {
// contains filtered or unexported fields
}
UDPTransport is a udp based transport for kelips. It is well suited due to the small message size and reliance on gossip. It only implements rpc's and not the fault-tolerance. This is primarily used for direct inserts, lookups and deletes
func NewUDPTransport ¶
func NewUDPTransport(ln *net.UDPConn) *UDPTransport
NewUDPTransport inits a new UDPTransport using the given server connection. Nil can be supplied if the transport is only used as a client and is not a cluster member
func (*UDPTransport) LookupGroupNodes ¶
LookupGroupNodes looksup the group nodes for a key on a remote host
func (*UDPTransport) LookupNodes ¶
LookupNodes performs a lookup request on a host returning at least min nodes
func (*UDPTransport) Register ¶
func (trans *UDPTransport) Register(group AffinityGroupRPC)
Register registers the local group to serve rpcs from and starts accepting connections