2016-02-12 18:02:16 +00:00
|
|
|
package raft
|
|
|
|
|
|
|
|
// LogType describes various types of log entries.
|
|
|
|
type LogType uint8
|
|
|
|
|
|
|
|
const (
|
|
|
|
// LogCommand is applied to a user FSM.
|
|
|
|
LogCommand LogType = iota
|
|
|
|
|
|
|
|
// LogNoop is used to assert leadership.
|
|
|
|
LogNoop
|
|
|
|
|
2017-02-02 21:19:08 +00:00
|
|
|
// LogAddPeer is used to add a new peer. This should only be used with
|
|
|
|
// older protocol versions designed to be compatible with unversioned
|
|
|
|
// Raft servers. See comments in config.go for details.
|
|
|
|
LogAddPeerDeprecated
|
2016-02-12 18:02:16 +00:00
|
|
|
|
2017-02-02 21:19:08 +00:00
|
|
|
// LogRemovePeer is used to remove an existing peer. This should only be
|
|
|
|
// used with older protocol versions designed to be compatible with
|
|
|
|
// unversioned Raft servers. See comments in config.go for details.
|
|
|
|
LogRemovePeerDeprecated
|
2016-02-12 18:02:16 +00:00
|
|
|
|
|
|
|
// LogBarrier is used to ensure all preceding operations have been
|
|
|
|
// applied to the FSM. It is similar to LogNoop, but instead of returning
|
|
|
|
// once committed, it only returns once the FSM manager acks it. Otherwise
|
|
|
|
// it is possible there are operations committed but not yet applied to
|
|
|
|
// the FSM.
|
|
|
|
LogBarrier
|
2017-02-02 21:19:08 +00:00
|
|
|
|
|
|
|
// LogConfiguration establishes a membership change configuration. It is
|
|
|
|
// created when a server is added, removed, promoted, etc. Only used
|
|
|
|
// when protocol version 1 or greater is in use.
|
|
|
|
LogConfiguration
|
2016-02-12 18:02:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Log entries are replicated to all members of the Raft cluster
|
|
|
|
// and form the heart of the replicated state machine.
|
|
|
|
type Log struct {
|
2017-02-02 21:19:08 +00:00
|
|
|
// Index holds the index of the log entry.
|
2016-02-12 18:02:16 +00:00
|
|
|
Index uint64
|
|
|
|
|
2017-02-02 21:19:08 +00:00
|
|
|
// Term holds the election term of the log entry.
|
|
|
|
Term uint64
|
|
|
|
|
|
|
|
// Type holds the type of the log entry.
|
|
|
|
Type LogType
|
|
|
|
|
|
|
|
// Data holds the log entry's type-specific data.
|
|
|
|
Data []byte
|
2016-02-12 18:02:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// LogStore is used to provide an interface for storing
|
|
|
|
// and retrieving logs in a durable fashion.
|
|
|
|
type LogStore interface {
|
2017-02-02 21:19:08 +00:00
|
|
|
// FirstIndex returns the first index written. 0 for no entries.
|
2016-02-12 18:02:16 +00:00
|
|
|
FirstIndex() (uint64, error)
|
|
|
|
|
2017-02-02 21:19:08 +00:00
|
|
|
// LastIndex returns the last index written. 0 for no entries.
|
2016-02-12 18:02:16 +00:00
|
|
|
LastIndex() (uint64, error)
|
|
|
|
|
2017-02-02 21:19:08 +00:00
|
|
|
// GetLog gets a log entry at a given index.
|
2016-02-12 18:02:16 +00:00
|
|
|
GetLog(index uint64, log *Log) error
|
|
|
|
|
2017-02-02 21:19:08 +00:00
|
|
|
// StoreLog stores a log entry.
|
2016-02-12 18:02:16 +00:00
|
|
|
StoreLog(log *Log) error
|
|
|
|
|
2017-02-02 21:19:08 +00:00
|
|
|
// StoreLogs stores multiple log entries.
|
2016-02-12 18:02:16 +00:00
|
|
|
StoreLogs(logs []*Log) error
|
|
|
|
|
2017-02-02 21:19:08 +00:00
|
|
|
// DeleteRange deletes a range of log entries. The range is inclusive.
|
2016-02-12 18:02:16 +00:00
|
|
|
DeleteRange(min, max uint64) error
|
|
|
|
}
|