wal

package
v0.0.0-...-d5f0689 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MetadataType int64 = iota + 1
	EntryType
	StateType
	SnapshotType
	CrcType
)

Variables

View Source
var (
	SegmentSizeBytes int64 = 64 * 1000 * 1000 // 64MB
)

Functions

func FileName

func FileName(seq, index uint64) string

Types

type FileWAL

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

func NewFileWAL

func NewFileWAL(dir string) (*FileWAL, error)

func NewReadOnlyFileWal

func NewReadOnlyFileWal(dir string) *FileWAL

func (*FileWAL) Close

func (f *FileWAL) Close() error

func (*FileWAL) Read

func (f *FileWAL) Read(s *raftpb.Snapshot) (h raftpb.HardState, ents []raftpb.Entry, err error)

func (*FileWAL) SaveLog

func (f *FileWAL) SaveLog(h raftpb.HardState, ents []raftpb.Entry) error

func (*FileWAL) SaveSnapshot

func (f *FileWAL) SaveSnapshot(s *raftpb.Snapshot) error

func (*FileWAL) Start

func (f *FileWAL) Start() error

type LogFileLCM

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

LogFileLCM is responsible for log file life cycle manage

func NewLogFileLCM

func NewLogFileLCM(dir string, fileSize int64) (*LogFileLCM, error)

func (*LogFileLCM) Cut

func (llcm *LogFileLCM) Cut(preCut func() error, initNew func(file *os.File) error, postCut func(file *os.File) error, index uint64) error

Cut will Cut the file as it reach to the pre-defined size limit

func (*LogFileLCM) SetTail

func (llcm *LogFileLCM) SetTail(file *os.File)

func (*LogFileLCM) Stop

func (llcm *LogFileLCM) Stop() error

type LogFileReader

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

func NewLogFileReader

func NewLogFileReader(dir string, snapshot raftpb.SnapshotMetadata) (*LogFileReader, error)

func (*LogFileReader) Close

func (lr *LogFileReader) Close() error

func (*LogFileReader) Read

func (lr *LogFileReader) Read(rec *walpb.Record) error

func (*LogFileReader) Tail

func (lr *LogFileReader) Tail() *os.File

func (*LogFileReader) TailOffset

func (lr *LogFileReader) TailOffset() int64

type LogFileWriter

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

func NewLogFileWriter

func NewLogFileWriter(f *os.File, offset int64) (*LogFileWriter, error)

func (*LogFileWriter) Close

func (lw *LogFileWriter) Close() error

func (*LogFileWriter) CurOffset

func (lw *LogFileWriter) CurOffset() (int64, error)

func (*LogFileWriter) Flush

func (lw *LogFileWriter) Flush() error

func (*LogFileWriter) Sync

func (lw *LogFileWriter) Sync() error

func (*LogFileWriter) Write

func (lw *LogFileWriter) Write(record *walpb.Record) error

type PageWriter

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

PageWriter implements the io.Writer interface so that writes will either be in page chunks or from flushing.

func NewPageWriter

func NewPageWriter(w io.Writer, pageBytes, pageOffset int) *PageWriter

NewPageWriter creates a new PageWriter. pageBytes is the number of bytes to write per page. pageOffset is the starting offset of io.Writer.

func (*PageWriter) Flush

func (pw *PageWriter) Flush() error

Flush flushes buffered data.

func (*PageWriter) Write

func (pw *PageWriter) Write(p []byte) (n int, err error)

type WAL

type WAL interface {
	SaveLog(h raftpb.HardState, entries []raftpb.Entry) error
	SaveSnapshot(s *raftpb.Snapshot) error
	// Read will read all the data that walpb contains, it will overwrite itself if conflict
	Read(s *raftpb.Snapshot) (h raftpb.HardState, e []raftpb.Entry, err error)
	Start() error
	Close() error
}

WAL has two purposes: - first is to write data to the log file. - second is to read out all the log records to help the raft node upon restart/start

Jump to

Keyboard shortcuts

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