chord

package module
v0.0.0-...-1666c92 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 25, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlackholeTransport

type BlackholeTransport struct {
}

BlackholeTransport is used to provide an implemenation of the Transport that does not actually do anything. Any operation will result in an error.

func (*BlackholeTransport) ClearPredecessor

func (*BlackholeTransport) ClearPredecessor(target, self *Vnode) error

func (*BlackholeTransport) FindSuccessors

func (*BlackholeTransport) FindSuccessors(vn *Vnode, n int, key []byte) ([]*Vnode, error)

func (*BlackholeTransport) GetPredecessor

func (*BlackholeTransport) GetPredecessor(vn *Vnode) (*Vnode, error)

func (*BlackholeTransport) ListVnodes

func (*BlackholeTransport) ListVnodes(host string) ([]*Vnode, error)

func (*BlackholeTransport) Notify

func (*BlackholeTransport) Notify(vn, self *Vnode) ([]*Vnode, error)

func (*BlackholeTransport) Ping

func (*BlackholeTransport) Ping(vn *Vnode) (bool, error)

func (*BlackholeTransport) Register

func (*BlackholeTransport) Register(v *Vnode, o VnodeRPC)

func (*BlackholeTransport) SkipSuccessor

func (*BlackholeTransport) SkipSuccessor(target, self *Vnode) error

type Config

type Config struct {
	// Addr is the local address of this node.
	Addr string

	// NumVnodes is the number of virtual nodes (vnodes) per physical node.
	NumVnodes int

	// StabilizeMin in the minimum stabilization time
	StabilizeMin time.Duration

	// StabilizeMax is the stabilization time
	StabilizeMax time.Duration

	// NumSuccessors is the number of successors in the ring to maintain.
	NumSuccessors int

	// Delegate is invoked to handle ring events.
	Delegate Delegate

	HashFunc func() hash.Hash
}

func DefaultConfig

func DefaultConfig(addr string) *Config

func (Config) HashSize

func (c Config) HashSize() int

HashSize returns the number of bits in the identifier produced by the config hash function.

type Delegate

type Delegate interface {
	NewPredecessor(local, remoteNew, remotePrev *Vnode)
	Leaving(local, pred, succ *Vnode)
	PredecessorLeaving(local, remote *Vnode)
	SuccessorLeaving(local, remote *Vnode)
	Shutdown()
}

Delegate to notify on ring events

type LocalTransport

type LocalTransport struct {
	// contains filtered or unexported fields
}

LocalTransport is used to provides fast routing to Vnodes running locally using direct method calls. For any non-local vnodes, the request is passed on to another transport.

func (*LocalTransport) ClearPredecessor

func (lt *LocalTransport) ClearPredecessor(target, self *Vnode) error

func (*LocalTransport) Deregister

func (lt *LocalTransport) Deregister(v *Vnode)

func (*LocalTransport) FindSuccessors

func (lt *LocalTransport) FindSuccessors(vn *Vnode, n int, key []byte) ([]*Vnode, error)

func (*LocalTransport) GetPredecessor

func (lt *LocalTransport) GetPredecessor(vn *Vnode) (*Vnode, error)

func (*LocalTransport) ListVnodes

func (lt *LocalTransport) ListVnodes(host string) ([]*Vnode, error)

func (*LocalTransport) Notify

func (lt *LocalTransport) Notify(vn, self *Vnode) ([]*Vnode, error)

func (*LocalTransport) Ping

func (lt *LocalTransport) Ping(vn *Vnode) (bool, error)

func (*LocalTransport) Register

func (lt *LocalTransport) Register(v *Vnode, o VnodeRPC)

func (*LocalTransport) SkipSuccessor

func (lt *LocalTransport) SkipSuccessor(target, self *Vnode) error

type Ring

type Ring struct {
	// contains filtered or unexported fields
}

Stores the state required for a Chord ring

func Create

func Create(conf *Config, trans Transport) (*Ring, error)

Creates a new Chord ring given the config and transport

func Join

func Join(conf *Config, trans Transport, existing string) (*Ring, error)

Joins an existing Chord ring

func (*Ring) Leave

func (r *Ring) Leave() error

Leaves a given Chord ring and shuts down the local vnodes

func (*Ring) Len

func (r *Ring) Len() int

Len is the number of vnodes

func (*Ring) Less

func (r *Ring) Less(i, j int) bool

Less returns whether the vnode with index i should sort before the vnode with index j.

func (*Ring) Lookup

func (r *Ring) Lookup(n int, key []byte) ([]*Vnode, error)

Does a key lookup for up to N successors of a key

func (*Ring) Shutdown

func (r *Ring) Shutdown()

Shutdown shuts down the local processes in a given Chord ring Blocks until all the vnodes terminate.

func (*Ring) Swap

func (r *Ring) Swap(i, j int)

Swap swaps the vnodes with indexes i and j.

type Transport

type Transport interface {
	// Gets a list of the vnodes on the box
	ListVnodes(string) ([]*Vnode, error)

	// Ping a Vnode, check for liveness
	Ping(*Vnode) (bool, error)

	// Request a nodes predecessor
	GetPredecessor(*Vnode) (*Vnode, error)

	// Notify our successor of ourselves
	Notify(target, self *Vnode) ([]*Vnode, error)

	// Find a successor
	FindSuccessors(*Vnode, int, []byte) ([]*Vnode, error)

	// Clears a predecessor if it matches a given vnode. Used to leave.
	ClearPredecessor(target, self *Vnode) error

	// Instructs a node to skip a given successor. Used to leave.
	SkipSuccessor(target, self *Vnode) error

	// Register for an RPC callbacks
	Register(*Vnode, VnodeRPC)
}

Implements the methods needed for a Chord ring

func InitLocalTransport

func InitLocalTransport(remote Transport) Transport

Creates a local transport to wrap a remote transport

type Vnode

type Vnode struct {
	ID   []byte
	Addr string
}

func (*Vnode) String

func (vn *Vnode) String() string

Converts the ID to string

type VnodeRPC

type VnodeRPC interface {
	GetPredecessor() (*Vnode, error)
	Notify(*Vnode) ([]*Vnode, error)
	FindSuccessors(int, []byte) ([]*Vnode, error)
	ClearPredecessor(*Vnode) error
	SkipSuccessor(*Vnode) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL