Documentation
¶
Index ¶
- Variables
- type Cache
- type Config
- type Instance
- func (i *Instance) Apply(l *raft.Log) interface{}
- func (i *Instance) Cache(name string) (*Cache, error)
- func (i *Instance) IsLeader() bool
- func (i *Instance) Join(addrs []string) (int, error)
- func (i *Instance) Leave() error
- func (i *Instance) Local() *Peer
- func (i *Instance) Peers() []*Peer
- func (i *Instance) Restore(rc io.ReadCloser) error
- func (i *Instance) Shutdown() error
- func (i *Instance) Snapshot() (raft.FSMSnapshot, error)
- func (i *Instance) WaitForReady()
- type Peer
- type RaftConfig
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoName is an error used when and instance name is not provided ErrNoName = errors.New("no instance name provided") )
var ErrUnsupportedMessageType = errors.New("unsupported message type")
ErrUnsupportedMessageType is an error for when an RPC is of an unexpected type.
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 ¶
Delete deletes the value for the given key. An error is returned if the value could not be deleted.
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 ¶
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) Cache ¶
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) Peers ¶
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) 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.
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.