Documentation ¶
Index ¶
- Constants
- Variables
- type CommitLog
- func (c *CommitLog) Append(p []byte) (offset int64, err error)
- func (c *CommitLog) Close() error
- func (c *CommitLog) DeleteAll() error
- func (c *CommitLog) NewReader(offset int64) (io.Reader, error)
- func (c *CommitLog) NewestOffset() int64
- func (c *CommitLog) OldestOffset() int64
- func (c *CommitLog) Segments() []*Segment
- type Compactor
- type Log
- type LogEntry
- type Mode
- type OptionFunc
- type Reader
- type Segment
Constants ¶
const (
// LogNameFormat defines the filename structure for active segments.
LogNameFormat = "%020d.log"
)
Variables ¶
var ( // ErrEmptyPath will be returned if the provided path is an empty string ErrEmptyPath = errors.New("path is empty") // ErrSegmentNotFound is returned with no segment is found given the provided offset ErrSegmentNotFound = errors.New("segment not found") )
var ( // ErrOffsetNotFound is returned when the requested offset is not in the segment. ErrOffsetNotFound = errors.New("offset not found") )
Functions ¶
This section is empty.
Types ¶
type CommitLog ¶
type CommitLog struct {
// contains filtered or unexported fields
}
CommitLog is how the rest of the system will interact with the underlying log segments to persist and read messages.
func New ¶
func New(options ...OptionFunc) (*CommitLog, error)
New creates a new CommitLog for persisting and reading messages.
The caller can configure the CommitLog by passing configuration options to the func.
Example:
c, err := New( WithPath("path/to/dir"), WithMaxSegmentBytes(1024))
An error is also returned when some configuration option is invalid
func (*CommitLog) Append ¶
Append will convert the set the offset for the provided []byte and then persist it to the active segment.
func (*CommitLog) NewestOffset ¶
NewestOffset obtains the NextOffset of the current segment in use.
func (*CommitLog) OldestOffset ¶
OldestOffset obtains the BaseOffset from the oldest segment on disk.
type Compactor ¶
Compactor defines the necessary functions for performing compaction of log segments.
func NewNamespaceCompactor ¶
NewNamespaceCompactor creates a new Compactor to be used for tracking messages based on the namespace.
type Log ¶
type Log []byte
Log is a alias type for []byte.
func NewLogFromEntry ¶
NewLogFromEntry takes the LogEntry and builds the underlying []byte to be stored.
type LogEntry ¶
LogEntry represents the high level representation of the message portion of each entry in the commit log.
func (LogEntry) ModeOpToByte ¶
ModeOpToByte converts the Mode and Op values into a single byte by performing bitwise operations. Mode is stored in bits 0 - 1 Op is stored in bits 2 - 4 bits 5 - 7 are currently unused
type Mode ¶
type Mode int
Mode is a representation of where a in the process a reader is with respect to a given namespace.
type OptionFunc ¶
OptionFunc is a function that configures a CommitLog. It is used in New.
func WithMaxSegmentBytes ¶
func WithMaxSegmentBytes(max int64) OptionFunc
WithMaxSegmentBytes defines the maximum limit a log segment can reach before needing to create a new one.
func WithPath ¶
func WithPath(path string) OptionFunc
WithPath defines the directory where all data will be stored.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader implements io.Reader for use with reading from the commit log.
type Segment ¶
type Segment struct { BaseOffset int64 NextOffset int64 Position int64 sync.Mutex // contains filtered or unexported fields }
Segment handles reading and writing to the underlying files on disk.
func NewSegment ¶
NewSegment creates a new instance of Segment with the provided parameters and initializes its NextOffset and Position should the file be non-empty.
func (*Segment) FindOffsetPosition ¶
FindOffsetPosition attempts to find the provided offset position in the Segment.
func (*Segment) IsFull ¶
IsFull determines whether the current size of the segment is greater than or equal to the maxBytes configured.