Documentation
¶
Index ¶
- Constants
- Variables
- type AOF
- func (aof *AOF) Append(reserve int64, appendFn AppendFunc) error
- func (aof *AOF) AppendNonBlocking(reserve int64, appendFn AppendFunc) error
- func (aof *AOF) Checkpoint() (int64, error)
- func (aof *AOF) Close() error
- func (aof *AOF) Finish() (err error)
- func (aof *AOF) Flush() error
- func (aof *AOF) IsAnonymous() bool
- func (aof *AOF) Subscribe(c Consumer) (*Tailer, error)
- func (aof *AOF) SubscribeInterval(interval time.Duration, c Consumer) (*Tailer, error)
- func (aof *AOF) SubscribeIntervalOn(r *reactor.Reactor, interval time.Duration, c Consumer) (*Tailer, error)
- func (aof *AOF) SubscribeOn(r *reactor.Reactor, c Consumer) (*Tailer, error)
- func (aof *AOF) Sync() error
- func (aof *AOF) Wake() error
- func (aof *AOF) Write(b []byte) (int, error)
- func (aof *AOF) WriteNonBlocking(b []byte) (int, error)
- type AppendEvent
- type AppendFunc
- type ClosedEvent
- type Consumer
- type ErrorFunc
- type FileState
- type FileStats
- type Geometry
- type Magic
- type Manager
- type ReadEvent
- type Recovery
- type RecoveryFunc
- type RecoveryKind
- type RecoveryResult
- type Stats
- type Tailer
- type TailerState
Constants ¶
const ( // MagicTail Little-Endian = [170 36 117 84 99 156 155 65] // After each write the MagicTail is appended to the end. MagicTail = uint64(4727544184288126122) // MagicCheckpoint Little-Endian = [44 219 31 242 165 172 120 248] MagicCheckpoint = uint64(17904250147343162156) )
Variables ¶
var ( ErrShrink = errors.New("shrink prohibited") ErrIsDirectory = errors.New("path is a directory") ErrCorrupted = errors.New("corrupted") ErrEmptyFile = errors.New("eof mode on empty file") ErrFileIsReadOnly = errors.New("file is read-only") ErrReadPermission = errors.New("file has no read permission") )
var ( SizeNowDefault = pageSize SizeUpperDefault = int64(1024 * 1024 * 16) // 16MB GrowthStepDefault = pageSize )
var ( RecoveryDefault = Recovery{ Magic: Magic{ Tail: MagicTail, Checkpoint: MagicCheckpoint, }, Func: RecoverWithMagic, } RecoveryReadOnly = Recovery{} )
var (
ErrAppendFuncNil = errors.New("append func nil")
)
var (
ErrWouldBlock = errors.New("would block")
)
var (
OpenFile = Geometry{}
)
Functions ¶
This section is empty.
Types ¶
type AOF ¶
type AOF struct {
// contains filtered or unexported fields
}
AOF is a single-producer multiple-consumer memory-mapped append only file. The same mapping is shared among any number of consumers. Each instance has a single mmap for its lifetime. The underlying file is then truncated "extended" in increments. Writes are blocked when writing past the current file size and a truncation is in-progress. Reads never block.
In order to minimize truncation blocking, the Manager can schedule AOF truncation to keep up with the writing pace.
func (*AOF) AppendNonBlocking ¶
func (aof *AOF) AppendNonBlocking(reserve int64, appendFn AppendFunc) error
func (*AOF) Checkpoint ¶
func (*AOF) IsAnonymous ¶
func (*AOF) SubscribeInterval ¶
func (*AOF) SubscribeIntervalOn ¶
func (*AOF) SubscribeOn ¶
type AppendEvent ¶
type AppendEvent struct {
Begin int64
End int64
Tail []byte
// contains filtered or unexported fields
}
func (*AppendEvent) File ¶
func (a *AppendEvent) File() []byte
type AppendFunc ¶
type AppendFunc func(event AppendEvent) (int64, error)
type ClosedEvent ¶
type Magic ¶
type Magic struct {
// Tail is the magic number that marks the tail of the file
Tail uint64
// Checkpoint is the magic number that marks the end of a chunk.
// During recovery if the Magic Tail is not found, it will search
// for the last Checkpoint
Checkpoint uint64
}
Magic provides magic numbers for Tail and Checkpoint.
func (*Magic) IsDisabled ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
func (*Manager) OpenAnonymous ¶
type ReadEvent ¶
type Recovery ¶
type Recovery struct {
Magic Magic
Func RecoveryFunc
// contains filtered or unexported fields
}
Recovery recovers an existing file on open by finding the tail. Since files are mapped and truncated according to the Geometry, it will be zero filled between logical tail and the file-system's tail. Furthermore, during crashes there is a potential that a partial write occurred. Using Magic numbers is the first line of defense to identify possible corruption. Since, this package does not define file formats, it is encouraged that the file format have the ability to recover to the last known commit point when the Magic number is not found.
func (*Recovery) Result ¶
func (r *Recovery) Result() RecoveryResult
type RecoveryFunc ¶
type RecoveryFunc func( fileSize int64, data []byte, magic Magic, ) (result RecoveryResult)
type RecoveryKind ¶
type RecoveryKind int
const ( Empty RecoveryKind = 0 // The Magic value was found at the tail Corrupted RecoveryKind = 1 // The Magic value was found at the tail Tail RecoveryKind = 2 // The Magic value was found at the tail Checkpoint RecoveryKind = 3 // The Magic Checkpoint value was found at the tail Panic RecoveryKind = 4 // The Magic Checkpoint value was found at the tail )
type RecoveryResult ¶
type RecoveryResult struct {
Magic Magic
Outcome RecoveryKind
FileSize int64
Checkpoint int64
Tail int64
Err error
}
func RecoverWithMagic ¶
func RecoverWithMagic(fileSize int64, data []byte, magic Magic) (result RecoveryResult)
RecoverWithMagic finds the last magic tail or last checkpoint
type Stats ¶
type Stats struct {
Creates Counter
CreatesDur TimeCounter
Opens Counter
OpensDur TimeCounter
OpenErrors Counter
OpenErrorsDur TimeCounter
OpenFileCount Counter
OpenFileDur TimeCounter
OpenFileErrors Counter
OpenFileErrorsDur TimeCounter
Closes Counter
CloseDur TimeCounter
ActiveMaps Counter
ActiveFileSize Counter
ActiveMappedMemory Counter
ActiveAnonymousMemory Counter
LifetimeMemory Counter
Flushes Counter
FlushesDur TimeCounter
FlushErrors Counter
FlushErrorsDur TimeCounter
Finishes Counter
FinishesDur TimeCounter
FinishErrors Counter
FinishErrorsDur TimeCounter
Syncs Counter
SyncsDur TimeCounter
SyncErrors Counter
SyncErrorsDur TimeCounter
Maps Counter
MapsDur TimeCounter
MapErrors Counter
MapErrorsDur TimeCounter
Unmaps Counter
UnmapsDur TimeCounter
UnmapErrors Counter
UnmapErrorsDur TimeCounter
Finalizes Counter
FinalizesDur TimeCounter
Truncates Counter
TruncatesDur TimeCounter
TruncateErrors Counter
TruncateErrorsDur TimeCounter
Chmods Counter
ChmodsDur TimeCounter
ChmodErrors Counter
ChmodErrorsDur TimeCounter
}
type Tailer ¶
type Tailer struct {
reactor.TaskProvider
// contains filtered or unexported fields
}
func (*Tailer) State ¶
func (t *Tailer) State() TailerState
type TailerState ¶
type TailerState int32
const ( TailerStart TailerState = 1 // Tailer was recently spawned and waiting for first start Dequeue TailerReading TailerState = 2 // Tailer is currently reading and is not at the tail yet TailerTail TailerState = 3 // Tailer has started and is now at the tail TailerEOF TailerState = 4 // Tailer parent AOF is finished the tailer goes from tail to Checkpoint state TailerClosing TailerState = 5 // Tailer is waiting for next Dequeue to close TailerClosed TailerState = 6 // Tailer is now safe to delete )
func (*TailerState) Load ¶
func (t *TailerState) Load() TailerState