huton

package
v0.0.0-...-987ed72 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2019 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoName is an error used when and instance name is not provided
	ErrNoName = errors.New("no instance name provided")
)
View Source
var ErrUnsupportedMessageType = errors.New("unsupported message type")

ErrUnsupportedMessageType is an error for when an RPC is of an unexpected type.

View Source
var (
	// ErrWrongBatchType is an error used when the provided implementation of Batch is unexpected.
	ErrWrongBatchType = errors.New("wrong batch implementation type")
)

Functions

This section is empty.

Types

type Cache

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

Cache is an in-memory key-value store.

func (*Cache) Delete

func (c *Cache) Delete(key []byte) error

Delete deletes the value for the given key. An error is returned if the value could not be deleted.

func (*Cache) Get

func (c *Cache) Get(key []byte) ([]byte, error)

Get retrieves the value for the given key. An error is returned if something goes wrong while retrieving the value. A value of nil means that the key was not found.

func (*Cache) Name

func (c *Cache) Name() string

Name returns the name of the cache.

func (*Cache) Set

func (c *Cache) Set(key []byte, val []byte) error

Set sets the value for the given key. An error is returned if the value could not be set.

type Config

type Config struct {
	// BindHost is the host that the cluster will bind to.
	BindHost string
	// BindPort is the base port that the cluster will bind to.
	// This port will be binded by the serf cluster in particular,
	// while BindPort+1 will be bound to by the raft cluster, and
	// BindPort+2 will be bound to by the RPC server.
	BindPort int
	// Bootstrap is used to force the cluster to bootstrap the node.
	// This is useful if you wish to create a single node server for testing.
	// It is not recommended to enable this in production.
	Bootstrap bool
	// Expect is the expected number of initial nodes in the cluster. The cluster
	// will wait for this number of nodes to be available before the cluster is
	// started and usable. This must be at least 3. Bootstrap will override this setting.
	// The default is 3.
	Expect int
	// LogOutput is an io.Writer used for logging. This defaults to stdout.
	LogOutput io.Writer
	// Replication is the configuration used for Raft replication.
	Replication RaftConfig
	// SerfEncryptionKey is an optional symmetric key used to encrypt Serf traffic between nodes.
	// If no key is provided, encryption will be disabled.
	SerfEncryptionKey []byte
}

Config is a structure used to configure a hunton.Instance.

type Instance

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

Instance is an interface for the Huton instance.

func NewInstance

func NewInstance(name string, config Config) (*Instance, error)

NewInstance creates a new Huton instance and initializes it and all of its sub-components, such as Serf, Raft, and GRPC server, with the provided configuration.

If this function returns successfully, the instance should be considered started and ready for use.

func (*Instance) Apply

func (i *Instance) Apply(l *raft.Log) interface{}

Apply applies a raft log received from the leader.

func (*Instance) Cache

func (i *Instance) Cache(name string) (*Cache, error)

Cache returns the cache with the given name. If no cache exists with the provided name, a new, empty cache with that name will be created.

func (*Instance) IsLeader

func (i *Instance) IsLeader() bool

IsLeader returns true if this instance is the cluster leader.

func (*Instance) Join

func (i *Instance) Join(addrs []string) (int, error)

Join joins and existing cluster.

func (*Instance) Leave

func (i *Instance) Leave() error

Leave gracefully leaves the cluster.

func (*Instance) Local

func (i *Instance) Local() *Peer

Local returns the local peer.

func (*Instance) Peers

func (i *Instance) Peers() []*Peer

Peers returns the current list of cluster peers. The list includes the local peer.

func (*Instance) Restore

func (i *Instance) Restore(rc io.ReadCloser) error

Restore restores the instance's state from an snapshot. If the state cannot be restored, an error is returned.

func (*Instance) Shutdown

func (i *Instance) Shutdown() error

Shutdown forcefully shuts down the instance.

func (*Instance) Snapshot

func (i *Instance) Snapshot() (raft.FSMSnapshot, error)

Snapshot returns a snapshot of the current instance state. If a snapshot cannot be created, an error is returned as well.

func (*Instance) WaitForReady

func (i *Instance) WaitForReady()

WaitForReady blocks until the cluster becomes ready and leadership is established.

type Peer

type Peer struct {
	Name      string
	SerfAddr  *net.TCPAddr
	RaftAddr  *net.TCPAddr
	RPCAddr   *net.TCPAddr
	Expect    int
	Bootstrap bool
}

Peer contains information about a cluster member.

func (*Peer) String

func (p *Peer) String() string

type RaftConfig

type RaftConfig struct {
	// BaseDir is the root directory for the Raft db and snapshot directory.
	// This directory must be write accessible by the huton process. The default
	// is the current working directory.
	BaseDir string
	// ApplicationTimeout is an optional timeout for applying Raft logs. If this
	// timeout is reached, the log is rejected by that node and if enough nodes
	// reject a log, that log will not be committed and rolled back. The default is
	// no timeout.
	ApplicationTimeout time.Duration
	// TransportTimeout is a timeout used for communications between raft clients.
	// The default is no timeout.
	TransportTimeout time.Duration
	// RetainSnapshotCount is the maximum number of Raft snapshots to retain on disk
	// before old snapshots are deleted. The default is 2.
	RetainSnapshotCount int
	// TLSConfig is an optional TLS configuration for Raft communications. If no TLS
	// config is provided, the communications will be unencrypted.
	TLSConfig *tls.Config
}

RaftConfig is a structure used to configure a huton.Instance's internal Raft cluster.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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