log

package
v0.0.0-...-649a10f Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Segment struct {
		MaxStoreBytes uint64
		MaxIndexBytes uint64
		InitialOffset uint64
	}
}

Config provides configuration of a log, such as the max size of a segment's store and index.

type Log

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

The log consists of a list of segments and a pointer to the active segment to append writes to. The directory stores segments.

func NewLog

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

Set config defaults if the caller didn't specify, create a log instance and set up the instance.

func (*Log) Append

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

Appends a record to the log. Append the record to the active segment. Make a new active segment if the segment is at its max size (per the max size configuration).

func (*Log) Close

func (l *Log) Close() error

Iterate over the segments and closes them.

func (*Log) HighestOffset

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

func (*Log) LowestOffset

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

func (*Log) Read

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

Reads the record stored at the given offset.

func (*Log) Reader

func (l *Log) Reader() io.Reader

Returns a reader to read the whole log. This is used to concatenate the segments' stores. The originReader type is needed to ensure we begin reading from the origin of the store and read the entire file.

func (*Log) Remove

func (l *Log) Remove() error

Closes the log and remove its data.

func (*Log) Reset

func (l *Log) Reset() error

Removes the log and creates a new log to replace it.

func (*Log) Truncate

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

Removes all segments whose highest offset is lower than lowest. We don't have infinite disk space so we call truncate periodically to remove old segments whose data has hopefully been procssed by then and don't need anymore.

Jump to

Keyboard shortcuts

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