Documentation
¶
Index ¶
Constants ¶
View Source
const ( // OffsetOldest represents the smallest offset still available // Use it to consume all messages, starting at the first available OffsetOldest = message.OffsetOldest // OffsetNewest represents the offset that will be used for the next produce // Use it to consume only new messages OffsetNewest = message.OffsetNewest // OffsetInvalid is the offset returned when error is detected OffsetInvalid = message.OffsetInvalid )
Variables ¶
View Source
var ErrInvalidOffset = message.ErrInvalidOffset
View Source
var ErrNoIndex = errors.New("no index")
View Source
var ErrNotFound = message.ErrNotFound
View Source
var ErrReadonly = errors.New("log opened in readonly mode")
View Source
var InvalidMessage = message.Invalid
Functions ¶
Types ¶
type Log ¶
type Log interface {
// Publish appends messages to the log.
// It returns the offset of the next message to be appended.
// The offset of the message is ignored, set to the actual offset.
// If the time of the message is 0, it set to the current UTC time.
Publish(messages []Message) (nextOffset int64, err error)
// NextOffset returns the offset of the next message to be published.
NextOffset() (nextOffset int64, err error)
// Consume retrieves messages from the log, starting at the offset.
// It returns offset, which can be used to retrieve for the next consume.
// If offset == OffsetOldest, the first message will be the oldest
// message still available on the log. If the log is empty,
// it will return no error, nextOffset will be 0
// If offset == OffsetNewest, no actual messages will be returned,
// but nextOffset will be set to the offset that will be used
// for the next Publish call
// If offset is before the first available on the log, or is after
// NextOffset, it returns ErrInvalidOffset
// If the exact offset is already deleted, it will start consuming
// from the next available offset.
// Consume is allowed to return no messages, but with increasing nextOffset
// in case messages between offset and nextOffset have been deleted.
// NextOffset is always bigger then offset, unless we are caught up
// to the head of the log in which case they are equal.
Consume(offset int64, maxCount int64) (nextOffset int64, messages []Message, err error)
// Get retrieves a single message, by its offset
// If offset == OffsetOldest, it returns the first message on the log
// If offset == OffsetNewest, it returns the last message on the log
// If offset is before the first available on the log, or is after
// NextOffset, it returns ErrInvalidOffset
// If log is empty, it returns ErrInvalidOffset
// If the exact offset have been deleted, it returns ErrNotFound
Get(offset int64) (message Message, err error)
// GetByKey retrieves the last message in the log for this key
// If no such message is found, it returns ErrNotFound
GetByKey(key []byte) (message Message, err error)
// OffsetByKey retrieves the last message offset in the log for this key
// If no such message is found, it returns ErrNotFound
OffsetByKey(key []byte) (offset int64, err error)
// GetByTime retrieves the first message after start time
// If start time is after all messages in the log, it returns ErrNotFound
GetByTime(start time.Time) (message Message, err error)
// OffsetByTime retrieves the first message offset and its time after start time
// If start time is after all messages in the log, it returns ErrNotFound
OffsetByTime(start time.Time) (offset int64, messageTime time.Time, err error)
// Delete tries to delete a set of messages by their offset
// from the log and returns the amount of storage deleted
// It does not guarantee that it will delete all messages,
// it returns the set of actually deleted offsets.
Delete(offsets map[int64]struct{}) (deletedOffsets map[int64]struct{}, deletedSize int64, err error)
// Size returns the amount of storage associated with a message
Size(m Message) int64
// Stat returns log stats like disk space, number of messages
Stat() (Stats, error)
// Backup takes a backup snapshot of this log to another location
Backup(dir string) error
// Sync forces persisting data to the disk
Sync() error
// Close closes the log
Close() error
}
type Options ¶
type Options struct {
// When set will try to create all directories
CreateDirs bool
// Open the store in readonly mode
Readonly bool
// Index message keys, enabling GetByKey and OffsetByKey
KeyIndex bool
// Index message times, enabling GetByTime and OffsetByTime
TimeIndex bool
// Force filesystem sync after each Publish
AutoSync bool
// At what segment size it will rollover to a new segment. Defaults to 1mb.
Rollover int64
// Check the head segment for integrity, before opening it for reading/writing.
Check bool
}
Click to show internal directories.
Click to hide internal directories.