Documentation ¶
Index ¶
- Variables
- type Batch
- type Log
- func (l *Log) ClearCache() error
- func (l *Log) Close() error
- func (l *Log) FirstIndex() (index uint64, err error)
- func (l *Log) IsClosed() bool
- func (l *Log) LastIndex() (index uint64, err error)
- func (l *Log) Len() (n uint64, err error)
- func (l *Log) Read(index uint64) (data []byte, err error)
- func (l *Log) Sync() error
- func (l *Log) TruncateBack(index uint64) error
- func (l *Log) TruncateFront(index uint64) error
- func (l *Log) Write(index uint64, data []byte) error
- func (l *Log) WriteBatch(b *Batch) (err error)
- func (l *Log) WriteCall(index uint64, data []byte, fn func() error) (lastIndex uint64, _ error)
- type LogOptions
Constants ¶
This section is empty.
Variables ¶
var ( // ErrCorruptLog is returns when the log is corrupt. ErrCorruptLog = errors.New("log corrupt") // ErrLogClosed is returned when an operation cannot be completed because // the log is closed. ErrLogClosed = errors.New("log closed") // ErrLogEntryNotFound is returned when an entry is not found. ErrLogEntryNotFound = errors.New("not found") // ErrLogIndexOutOfOrder is returned from Write() when the index is not equal to // LastIndex()+1. It's required that log monotonically grows by one and has // no gaps. Thus, the series 10,11,12,13,14 is valid, but 10,11,13,14 is // not because there's a gap between 11 and 13. Also, 10,12,11,13 is not // valid because 12 and 11 are out of order. ErrLogIndexOutOfOrder = errors.New("out of order") // ErrLogIndexOutOfRange is returned from TruncateFront() and TruncateBack() when // the index not in the range of the log's first and last index. Or, this // may be returned when the caller is attempting to remove *all* entries; // The log requires that at least one entry exists following a truncate. ErrLogIndexOutOfRange = errors.New("out of range") ErrLogPathNotAbsolute = errors.New("log path is not absolute") )
Functions ¶
This section is empty.
Types ¶
type Batch ¶
type Batch struct { //Optional. Called once before calling FinalizeEntry. //The call is made while the *Log is locked. //The function should return as quickly as possible. FinalizeBatch func(lastEntryIndex uint64) //Optional. Called once, even if write failed. //The function should return as quickly as possible. AfterWriteAttempt func(error) //Optional, called for each entry just before writing it. //The call is made while the *Log is locked. FinalizeEntry func(entry []byte, absoluteIndex uint64) // contains filtered or unexported fields }
Batch of entries. Used to write multiple entries at once using WriteBatch().
type Log ¶
type Log struct {
// contains filtered or unexported fields
}
Log represents a write ahead log
func OpenWAL ¶
func OpenWAL(path string, fls afs.Filesystem, opts *LogOptions) (*Log, error)
OpenWAL a new write ahead log
func (*Log) FirstIndex ¶
FirstIndex returns the index of the first entry in the log. Returns zero when log has no entries.
func (*Log) LastIndex ¶
LastIndex returns the index of the last entry in the log. Returns zero when log has no entries.
func (*Log) Sync ¶
Sync performs an fsync on the log. This is not necessary when the NoSync option is set to false.
func (*Log) TruncateBack ¶
TruncateBack truncates the back of the log by removing all entries that are after the provided `index`. In other words the entry at `index` becomes the last entry in the log.
func (*Log) TruncateFront ¶
TruncateFront truncates the front of the log by removing all entries that are before the provided `index`. In other words the entry at `index` becomes the first entry in the log.
func (*Log) WriteBatch ¶
WriteBatch writes the entries in the batch to the log in the order that they were added to the batch. The batch is cleared upon a successful return.
type LogOptions ¶
type LogOptions struct { // NoSync disables fsync after writes. This is less durable and puts the // log at risk of data loss when there's a server crash. NoSync bool // SegmentSize of each segment. This is just a target value, actual size // may differ. Default is 20 MB. SegmentSize int // SegmentCacheSize is the maximum number of segments that will be held in // memory for caching. Increasing this value may enhance performance for // concurrent read operations. Default is 1 SegmentCacheSize int // NoCopy allows for the Read() operation to return the raw underlying data // slice. This is an optimization to help minimize allocations. When this // option is set, do not modify the returned data because it may affect // other Read calls. Default false NoCopy bool // Perms represents the datafiles modes and permission bits DirPerms os.FileMode FilePerms os.FileMode // FillID allow writes with a zero ID, will auto fill it with the next FillID bool // RecoverCorruptedTail will attempt to recover a corrupted tail in the last segment automatically. RecoverCorruptedTail bool }
LogOptions for Log