Documentation ¶
Index ¶
- Constants
- Variables
- func Create(file *os.File, filename string, config common.Config) (common.WriteAheadLog, error)
- func NewIndexRecordDecoder(reader io.Reader) common.IndexRecordDecoder
- func NewIndexRecordEncoder(writer io.Writer) common.IndexRecordEncoder
- func NewLogRecordDecoder(maxSize int, reader io.Reader) common.LogRecordDecoder
- func NewLogRecordEncoder(maxSize int, writer io.Writer) (common.LogRecordEncoder, error)
- func VersionOneIndexFactory(file *os.File, version uint8, flags uint32, expiration int64) (common.LogIndex, error)
- type RawIndexRecord
- type RawLogRecord
- type VersionOneIndexFile
Constants ¶
const ( // VersionOne is an integer denoting the first version VersionOne = 1 // IndexHeaderSize is the size of the index file header. IndexHeaderSize = 16 // IndexRecordSize is the size of the index records. IndexRecordSize = 24 // LogHeaderSize is the header size of version 1 log files LogHeaderSize = 16 // LogRecordHeaderSize is the size of the log record headers. LogRecordHeaderSize = 16 // MaxRecordSize is the maximum size a record can be for version 1 MaxRecordSize = 0xffffffff )
Variables ¶
var DefaultConfig common.Config = common.Config{ FileMode: 0600, MaxRecordSize: common.DefaultMaxRecordSize, Flags: common.DefaultRecordFlags, Version: VersionOne, Truncate: false, TimeToLive: 0, Strategy: m3.NoSyncOnWrite, }
DefaultConfig can be used for sensible default log configuration.
Functions ¶
func NewIndexRecordDecoder ¶
func NewIndexRecordDecoder(reader io.Reader) common.IndexRecordDecoder
NewIndexRecordDecoder creates an `IndexRecord` decoder which decodes byte arrays and returns the IndexRecord. An `ErrInvalidRecordSize` is returned if the record cannot be read.
func NewIndexRecordEncoder ¶
func NewIndexRecordEncoder(writer io.Writer) common.IndexRecordEncoder
NewIndexRecordEncoder writes an `IndexRecord` into a byte array.
func NewLogRecordDecoder ¶
func NewLogRecordDecoder(maxSize int, reader io.Reader) common.LogRecordDecoder
func NewLogRecordEncoder ¶
NewLogRecordEncoder creates a new LogRecordFactory which validates records are smaller than the given maxSize.
func VersionOneIndexFactory ¶
func VersionOneIndexFactory(file *os.File, version uint8, flags uint32, expiration int64) (common.LogIndex, error)
VersionOneLogHeader starts with a 3-byte string, "IDX", followed by an 8-bit version. After the version, a uint32 represents the boolean flags. The records start immediately following the bit flags.
Types ¶
type RawIndexRecord ¶
type RawIndexRecord struct {
// contains filtered or unexported fields
}
RawIndexRecord implements the bare IndexRecord interface.
func (RawIndexRecord) Index ¶
func (i RawIndexRecord) Index() uint64
Index is a record's numerical id.
func (RawIndexRecord) IsExpired ¶
func (i RawIndexRecord) IsExpired(now, ttl int64) bool
IsExpired is a helper function for the index record which returns `true` if the given time is beyond the expiration time. The expiration time is calculated as written time + TTL.
func (RawIndexRecord) Offset ¶
func (i RawIndexRecord) Offset() int64
Offset is the distance the data record is from the start of the data file.
func (RawIndexRecord) Time ¶
func (i RawIndexRecord) Time() int64
Time returns when the record was written to the data file.
type RawLogRecord ¶
type RawLogRecord struct {
// contains filtered or unexported fields
}
RawLogRecord implements the bare LogRecord interface.
func (*RawLogRecord) Flags ¶
func (i *RawLogRecord) Flags() uint32
Flags returns the boolean flags for the record
func (*RawLogRecord) IsExpired ¶
func (i *RawLogRecord) IsExpired(now, ttl int64) bool
IsExpired is a helper function for the index record which returns `true` if the given time is beyond the expiration time. The expiration time is calculated as written time + TTL.
func (*RawLogRecord) Size ¶
func (i *RawLogRecord) Size() uint32
Size returns the length of the record payload
func (*RawLogRecord) Time ¶
func (i *RawLogRecord) Time() int64
Time is the record nanoseconds from epoch
type VersionOneIndexFile ¶
type VersionOneIndexFile struct {
// contains filtered or unexported fields
}
VersionOneIndexFile implements the IndexFile interface and is created by VersionOneIndexFactory.
func (*VersionOneIndexFile) Close ¶
func (i *VersionOneIndexFile) Close() error
Close flushed the index with permanant storage and closes the index.
func (VersionOneIndexFile) Header ¶
func (i VersionOneIndexFile) Header() common.FileHeader
Header returns the file header which describes the index file.
func (*VersionOneIndexFile) Size ¶
func (i *VersionOneIndexFile) Size() uint64
Size is the number of elements in the index. Which should coorespond with the number of records in the data file.