Documentation
¶
Index ¶
Constants ¶
const ( // SyncOS policy defers the sync to the OS. SyncOS = 1 // SyncInterval policy syncs at an interval specfied in Options.SyncInterval. SyncInterval = 2 // SyncAlways policy syncs on every Append. SyncAlways = 3 )
const ( // DefaultSegmentSize 64 MiB DefaultSegmentSize = 67108864 // DefaultSyncPolicy SyncInterval DefaultSyncPolicy = SyncInterval // DefaultSyncInterval 1000ms DefaultSyncInterval = 1000 )
Variables ¶
var ErrCRCMismatch = errors.New("crc mismatch")
ErrCRCMismatch signifies the CRC included in the Record did not match the actual CRC reconstructed from the message.
var ErrLockTimeout = errors.New("lock timeout")
ErrLockTimeout signifies the lock failed to be acquire after the specified timeout.
var ErrSkipSegment = errors.New("skip this segment")
ErrSkipSegment signals the cleaner to stop & skip over the current segment.
Functions ¶
Types ¶
type AppendOptions ¶
type AppendOptions struct { // Minimum segment size before rolling into a new one. SegmentSize uint // Speficies which policy to use, one of the Sync* constants. SyncPolicy uint // Sync interval in ms, valid when sync policy is set to SyncInterval. SyncInterval uint }
AppendOptions represents the options for opening an Appender.
type Appender ¶
type Appender struct {
// contains filtered or unexported fields
}
Appender represents a stream writer in append-only mode. Appenders must be locked before use and unlocked when done as there can only be a single active appender at a time.
type CleanFn ¶
CleanFn represents the function signature that is passed to the Clean function. Returning true signals the cleaner to remove the record. Returning false signals to retain the record.
type Cleaner ¶
type Cleaner struct {
// contains filtered or unexported fields
}
Cleaner is responsible for cleaning the read-only portion of the stream. Policy for cleaning is based on the CleanFn passed to the Clean method.
func (*Cleaner) Clean ¶
Clean takes a CleanFn, iterates through every read-only segment file and invokes CleanFn against every log record: * Deleting the record when CleanFn returns true. * Retaining the record when CleanFn returns false. * Skipping the segment file if ErrSkipSegment is returned. * Stopping the cleaning if CleanFn returns any other error.
Cleaning works by rewriting the segment file with only the relevant log records. Requires a cleaning lock via Lock() which is an exclusive lock, blocking cursors.
type Cursor ¶
type Cursor struct {
// contains filtered or unexported fields
}
Cursor represents an iterator that traverses Records in log time order. Cursors can only move forward with the ability to Reset back to the front.
func (*Cursor) Next ¶
Next returns the next Record in the cursor. Handles rotating to the next segment file. A record of nil, with an error of nil represents the end of the cursor. Requires a read lock through Lock().
type MagicHeader ¶
MagicHeader represents the magic bytes and version of a segment file.
func (*MagicHeader) MarshalBinary ¶
func (h *MagicHeader) MarshalBinary() ([]byte, error)
MarshalBinary returns the magic header in BigEndian.
func (*MagicHeader) UnmarshalBinary ¶
func (h *MagicHeader) UnmarshalBinary(data []byte) error
MarshalBinary sets the magic header from data in BigEndian.
type Record ¶
Record represents a log entry.
func (*Record) MarshalBinary ¶
MarshalBinary encodes a Record in its binary form. Appends a CRC32 to the end of the message.
func (*Record) UnmarshalBinaryFromReader ¶
func (r *Record) UnmarshalBinaryFromReader(rdr RecordReader) error
UnmarshalBinaryFromReader decodes a Record from a RecordReader. Returns an error if the data could not be completely decoded. Returns ErrCRCMismatch if the checksum did not match the original appended in the Record.
type RecordReader ¶
type RecordReader interface { io.Reader io.ByteReader }
RecordReader is used for UnmarshalBinaryFromReader.
type Stream ¶
type Stream struct {
// contains filtered or unexported fields
}
Stream represents a data stream. Can be read in sequence using a Cursor. Can be appended to using an Appender. Can be cleaned using a Cleaner.
func NewStream ¶
func NewStream(path string, header *MagicHeader) *Stream
NewStream returns a Stream with a specified path and header to use.
func (*Stream) OpenAppender ¶
func (s *Stream) OpenAppender(options *AppendOptions) (*Appender, error)
OpenAppender opens an Appender object on the stream. Nil options will set default options.
func (*Stream) OpenCleaner ¶
OpenCleaner returns a Cleaner on the stream.
func (*Stream) OpenCursor ¶
OpenCursor returns a cursor for the current stream.