v1

package
v0.0.0-...-eaf2392 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 12, 2015 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
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 Create

func Create(file *os.File, filename string, config common.Config) (common.WriteAheadLog, error)

###### *Implementation*

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

func NewLogRecordEncoder(maxSize int, writer io.Writer) (common.LogRecordEncoder, error)

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) Data

func (i *RawLogRecord) Data() []byte

Data is the record payload

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

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.

func (*VersionOneIndexFile) Write

func (i *VersionOneIndexFile) Write(record []byte) (n int, err error)

Append adds an index record to the end of the index file. V1 index records have a time, an index and an offset in the data file.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL