Documentation ¶
Overview ¶
Package commitlog provides an implementation for a file-backed write-ahead log.
Index ¶
- Variables
- func Hash(b []byte) uint64
- func NewMessageSetFromProto(baseOffset, basePos int64, msgs []*proto.Message) (MessageSet, []Entry, error)
- type Cleaner
- type CommitLog
- func (l *CommitLog) Append(msgs []*proto.Message) ([]int64, error)
- func (l *CommitLog) AppendMessageSet(ms []byte) ([]int64, error)
- func (l *CommitLog) Close() error
- func (l *CommitLog) Delete() error
- func (l *CommitLog) HighWatermark() int64
- func (l *CommitLog) NewReaderCommitted(ctx context.Context, offset int64) (io.Reader, error)
- func (l *CommitLog) NewReaderUncommitted(ctx context.Context, offset int64) (io.Reader, error)
- func (l *CommitLog) NewestOffset() int64
- func (l *CommitLog) OldestOffset() int64
- func (l *CommitLog) Segments() []*Segment
- func (l *CommitLog) SetHighWatermark(hw int64)
- func (l *CommitLog) Truncate(offset int64) error
- type CommittedReader
- type CompactCleaner
- type DeleteCleaner
- type Entry
- type Index
- func (idx *Index) Close() (err error)
- func (idx *Index) InitializePosition() (*Entry, error)
- func (idx *Index) Name() string
- func (idx *Index) ReadAt(p []byte, offset int64) (n int, err error)
- func (idx *Index) ReadEntryAtFileOffset(e *Entry, fileOffset int64) (err error)
- func (idx *Index) ReadEntryAtLogOffset(e *Entry, logOffset int64) error
- func (idx *Index) Sync() error
- func (idx *Index) TruncateEntries(number int) error
- func (idx *Index) WriteAt(p []byte, offset int64) (n int)
- func (idx *Index) WriteEntries(entries []Entry) (err error)
- type IndexScanner
- type Message
- type MessageSet
- type Options
- type Segment
- func (s *Segment) Cleaner() (*Segment, error)
- func (s *Segment) Close() error
- func (s *Segment) Delete() error
- func (s *Segment) IsFull() bool
- func (s *Segment) NextOffset() int64
- func (s *Segment) Position() int64
- func (s *Segment) ReadAt(p []byte, off int64) (n int, err error)
- func (s *Segment) Replace(old *Segment) (err error)
- func (s *Segment) SetupIndex() (err error)
- func (s *Segment) Write(p []byte, numMsgs int) (n int, err error)
- func (s *Segment) WriteMessageSet(ms []byte, entries []Entry) error
- type SegmentScanner
- type UncommittedReader
Constants ¶
This section is empty.
Variables ¶
var (
ErrIndexCorrupt = errors.New("corrupt index file")
)
var (
ErrSegmentNotFound = errors.New("segment not found")
)
Functions ¶
func NewMessageSetFromProto ¶
Types ¶
type CommitLog ¶
type CommitLog struct { Options // contains filtered or unexported fields }
CommitLog implements the server.CommitLog interface, which is a durable write-ahead log.
func New ¶
New creates a new CommitLog and starts a background goroutine which periodically checkpoints the high watermark to disk.
func (*CommitLog) Append ¶
Append writes the given batch of messages to the log and returns their corresponding offsets in the log.
func (*CommitLog) AppendMessageSet ¶
AppendMessageSet writes the given message set data to the log and returns the corresponding offsets in the log.
func (*CommitLog) Close ¶
Close closes each log segment file and stops the background goroutine checkpointing the high watermark to disk.
func (*CommitLog) Delete ¶
Delete closes the log and removes all data associated with it from the filesystem.
func (*CommitLog) HighWatermark ¶
HighWatermark returns the high watermark for the log.
func (*CommitLog) NewReaderCommitted ¶
NewReaderCommitted returns an io.Reader which reads only committed data from the log starting at the given offset.
func (*CommitLog) NewReaderUncommitted ¶
NewReaderUncommitted returns an io.Reader which reads data from the log starting at the given offset.
func (*CommitLog) NewestOffset ¶
NewestOffset returns the offset of the last message in the log.
func (*CommitLog) OldestOffset ¶
OldestOffset returns the offset of the first message in the log.
func (*CommitLog) SetHighWatermark ¶
SetHighWatermark sets the high watermark on the log. All messages up to and including the high watermark are considered committed.
type CommittedReader ¶
type CommittedReader struct {
// contains filtered or unexported fields
}
type CompactCleaner ¶
type CompactCleaner struct {
// contains filtered or unexported fields
}
func NewCompactCleaner ¶
func NewCompactCleaner() *CompactCleaner
type DeleteCleaner ¶
type DeleteCleaner struct { Retention struct { Bytes int64 } }
func NewDeleteCleaner ¶
func NewDeleteCleaner(bytes int64) *DeleteCleaner
type Entry ¶
func EntriesForMessageSet ¶
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
func (*Index) InitializePosition ¶
func (*Index) ReadEntryAtFileOffset ¶
ReadEntryAtFileOffset is used to read an Index entry at the given byte offset of the Index file. ReadEntryAtLogOffset is generally more useful for higher level use.
func (*Index) ReadEntryAtLogOffset ¶
ReadEntryAtLogOffset is used to read an Index entry at the given log offset of the Index file.
func (*Index) TruncateEntries ¶
func (*Index) WriteEntries ¶
type IndexScanner ¶
type IndexScanner struct {
// contains filtered or unexported fields
}
func NewIndexScanner ¶
func NewIndexScanner(idx *Index) *IndexScanner
func (*IndexScanner) Scan ¶
func (s *IndexScanner) Scan() (*Entry, error)
type MessageSet ¶
type MessageSet []byte
func (MessageSet) Message ¶
func (ms MessageSet) Message() Message
func (MessageSet) Offset ¶
func (ms MessageSet) Offset() int64
func (MessageSet) Size ¶
func (ms MessageSet) Size() int32
type Options ¶
type Options struct { Path string // MaxSegmentBytes is the max number of bytes a segment can contain, once the limit is hit a // new segment will be split off. MaxSegmentBytes int64 MaxLogBytes int64 Compact bool HWCheckpointInterval time.Duration Logger logger.Logger }
Options contains settings for configuring a CommitLog.
type Segment ¶
type Segment struct { Index *Index BaseOffset int64 sync.RWMutex // contains filtered or unexported fields }
func NewSegment ¶
func (*Segment) NextOffset ¶
func (*Segment) SetupIndex ¶
SetupIndex creates and initializes an Index. Initialization is: - Initialize Index position - Initialize Segment nextOffset
type SegmentScanner ¶
type SegmentScanner struct {
// contains filtered or unexported fields
}
func NewSegmentScanner ¶
func NewSegmentScanner(segment *Segment) *SegmentScanner
func (*SegmentScanner) Scan ¶
func (s *SegmentScanner) Scan() (ms MessageSet, err error)
Scan should be called repeatedly to iterate over the messages in the segment, it will return io.EOF when there are no more messages.
type UncommittedReader ¶
type UncommittedReader struct {
// contains filtered or unexported fields
}