log

package
v0.0.0-...-3f89aaf Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
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

type Log struct {
	Dir    string
	Config Config
	// contains filtered or unexported fields
}

Log is an abstraction to manage the list of segments.

func NewLog

func NewLog(dir string, c Config) (*Log, error)

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

func (l *Log) Append(record *api.Record) (uint64, error)

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) Close

func (l *Log) Close() error

Close closes the log by closing all its segments.

func (*Log) HighestOffset

func (l *Log) HighestOffset() (uint64, error)

HighestOffset returns the higher bound of the offset range stored in the log.

func (*Log) LowestOffset

func (l *Log) LowestOffset() (uint64, error)

LowestOffset returns the lower bound of the offset range stored in the log.

func (*Log) Read

func (l *Log) Read(off uint64) (*api.Record, error)

Read reads the record stored at the given offset.

func (*Log) Reader

func (l *Log) Reader() io.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.

func (*Log) Remove

func (l *Log) Remove() error

Remove closes the log and removes its data.

func (*Log) Reset

func (l *Log) Reset() error

Reset removes the log and then creates a new log to replace it.

func (*Log) Truncate

func (l *Log) Truncate(lowest uint64) error

Trucante removes all segments whose highest offset is lower than lowest, it is used to remove old segments whose data has already been processed.

type RequestType

type RequestType uint8
const (
	AppendRequestType RequestType = 0
)

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.

Jump to

Keyboard shortcuts

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