Documentation ¶
Index ¶
- Constants
- type Config
- type DistributedLog
- func (l *DistributedLog) Append(record *api.Record) (uint64, error)
- func (l *DistributedLog) Close() error
- func (l *DistributedLog) GetServers() ([]*api.Server, error)
- func (l *DistributedLog) Join(id, addr string) error
- func (l *DistributedLog) Leave(id string) error
- func (l *DistributedLog) Read(offset uint64) (*api.Record, error)
- func (l *DistributedLog) WaitForLeader(timeout time.Duration) error
- type Log
- func (l *Log) Append(record *api.Record) (uint64, error)
- func (l *Log) Close() error
- func (l *Log) HighestOffset() (uint64, error)
- func (l *Log) LowestOffset() (uint64, error)
- func (l *Log) Read(off uint64) (*api.Record, error)
- func (l *Log) Reader() io.Reader
- func (l *Log) Remove() error
- func (l *Log) Reset() error
- func (l *Log) Truncate(lowest uint64) error
- type RequestType
- type StreamLayer
Constants ¶
const RaftRPC = 1
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { Raft struct { raft.Config BindAddr string StreamLayer *StreamLayer Bootstrap bool } Segment struct { MaxStoreBytes uint64 MaxIndexBytes uint64 InitialOffset uint64 } }
Config centralised a log's configuration.
type DistributedLog ¶
type DistributedLog struct {
// contains filtered or unexported fields
}
DistributedLog defines a distributed log.
func NewDistributedLog ¶
func NewDistributedLog(dataDir string, config Config) ( *DistributedLog, error, )
NewDistributedLog instanciates a distributed log.
func (*DistributedLog) Append ¶
func (l *DistributedLog) Append(record *api.Record) (uint64, error)
Append appends the record to the distributed log system.
func (*DistributedLog) Close ¶
func (l *DistributedLog) Close() error
Close shuts down the Raft instance and closes the local log.
func (*DistributedLog) GetServers ¶
func (l *DistributedLog) GetServers() ([]*api.Server, error)
GetServers exposes Raft's server data.
func (*DistributedLog) Join ¶
func (l *DistributedLog) Join(id, addr string) error
Join adds the server to the Raft cluster, adding every server as a voter.
func (*DistributedLog) Leave ¶
func (l *DistributedLog) Leave(id string) error
Leave removes a server from the Raft cluster. Removing the leader will trigger a new election.
func (*DistributedLog) Read ¶
func (l *DistributedLog) Read(offset uint64) (*api.Record, error)
Read reads the record for the offset from the server's log.
func (*DistributedLog) WaitForLeader ¶
func (l *DistributedLog) WaitForLeader(timeout time.Duration) error
WaitForLeader blocks until the cluster has elected a leader or it times out.
type Log ¶
Log is an abstraction to manage the list of segments.
func NewLog ¶
NewLog instanciates a Log with the specifiad config that stores its files in the given dir. If no limits for index and store sizes are provided, 1024 is set by default.
func (*Log) Append ¶
Append adds a record to the log's active segment. If the segment is at its max size, then a new active segment is set.
func (*Log) HighestOffset ¶
HighestOffset returns the higher bound of the offset range stored in the log.
func (*Log) LowestOffset ¶
LowestOffset returns the lower bound of the offset range stored in the log.
func (*Log) Reader ¶
Readers returns an io.Reader to read the whole log. It is needed when implementing coordinate consensus and to support snapshots and log restoration.
type StreamLayer ¶
type StreamLayer struct {
// contains filtered or unexported fields
}
StreamLayer implements the raft.StreamLayer interface.
func NewStreamLayer ¶
func NewStreamLayer( ln net.Listener, serverTLSConfig, peerTLSConfig *tls.Config, ) *StreamLayer
NewStreamLayer instanciates a StreamLayer, and checks that it satisfies raft.StreamLayer interface.
func (*StreamLayer) Accept ¶
func (s *StreamLayer) Accept() (net.Conn, error)
Accept is the mirror of Dial, it accepts the incoming connection and reads the byte that identifies the connection and then creates a server side TLS connection.
func (*StreamLayer) Addr ¶
func (s *StreamLayer) Addr() net.Addr
Addr returns the listener's address.
func (*StreamLayer) Close ¶
func (s *StreamLayer) Close() error
Close implements the closing method for the raft.StreamLayer interface.
func (*StreamLayer) Dial ¶
func (s *StreamLayer) Dial( addr raft.ServerAddress, timeout time.Duration, ) (net.Conn, error)
Dial makes outgoing connections to other services in the Raft cluster.