raft

package module
v0.0.0-...-ed38972 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2018 License: MIT Imports: 16 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

raft

GoDoc simplified, drop-in raft package

Documentation

Index

Constants

View Source
const (

	// RPCHeaderOffset is the min header byte free to
	// be used for a custom protocol
	RPCHeaderOffset = rpcJoinCluster + 1
)

Variables

This section is empty.

Functions

func Init

func Init(customProtocol MessageProtocol) (string, error)

Init creates a new localNode which seeds a new cluster of raft nodes; each consecutive raft node needs the token to connect to this node

func Join

func Join(customProtocol MessageProtocol, addr, token string) error

Join creates a new localNode and tries to connect it to an existing cluster of raft nodes

Types

type LocalNode

type LocalNode interface {
	RemoteNode

	AppendLogMessage([]byte, time.Duration) error
	RemoteProcedureCall(RemoteNode, uint8, interface{}, interface{}) error
	GetRemoteNodes() ([]RemoteNode, error)
	GetAuthToken() string
}

LocalNode is a raft node which is the local node.

type LocalNodeSetter

type LocalNodeSetter interface {
	SetLocalNode(LocalNode)
}

LocalNodeSetter represents a protocol interface which receives a reference to a LocalNode once a cluster has been joined / created.

type MessageProtocol

MessageProtocol is a message oriented protocol sharing a common state over all nodes of the "overlay" network

type MessagePtrFactory

type MessagePtrFactory func() interface{}

MessagePtrFactory emits a new request struct ptr

type MessageReceiveEventHandler

type MessageReceiveEventHandler interface {

	// OnMessageReceive is called when a message was recieved and has been
	// properly decoded; return either an error or an struct ptr; both will
	// be sent back to the requesting client
	OnMessageReceive(uint8, interface{}) (interface{}, error)
}

MessageReceiveEventHandler represents a protocol interface which is notified about incoming messages, properly decoded into the interface{} with the rpc type

type MessageTypeTranslator

type MessageTypeTranslator map[uint8]MessagePtrFactory

MessageTypeTranslator is a map associating rpc types (uint8) to MessagePtrFactorys

type MessageTypeTranslatorGetter

type MessageTypeTranslatorGetter interface {

	// GetTypeTranslator returns the protocol's
	// type translator
	GetTypeTranslator() MessageTypeTranslator
}

MessageTypeTranslatorGetter implements GetTypeTranslator() func

type RemoteNode

type RemoteNode interface {
	GetID() string
	GetAddress() string
}

RemoteNode is a raft node which is not the local node. This is supposed to only be a reference to this node.

type SharedState

type SharedState interface {

	// AppendLogMessage decodes the log message
	// and applies the represented change to the
	// local state
	AppendLogMessage([]byte)

	// Encode encodes the current state into
	// the writer
	Encode(io.Writer) error

	// Decode decodes a state from the reader
	// into the local state
	Decode(io.Reader) error
}

SharedState is a interface representing a log / transaction based state which can be shared over multiple nodes. The raft protocol ensures that the state is equalized on all nodes

type SharedStateGetter

type SharedStateGetter interface {

	// GetSharedState returns the SharedState
	GetSharedState() SharedState
}

SharedStateGetter implements the GetSharedState() func

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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