Documentation ¶
Index ¶
- Constants
- Variables
- func Delete(path string) (err error)
- func Restore(path string, r io.Reader) (err error)
- func Scan(path string) (err error)
- func Truncate(path string) (err error)
- type Config
- type Fanin
- type FaninWriter
- type Log
- func (l *Log) Backup(w io.Writer) (err error)
- func (l *Log) Close() (err error)
- func (l *Log) NewReader(bufferSize int, follow bool, ioMode recio.IOMode) (lr *LogReader, err error)
- func (l *Log) NewWriter(bufferSize int, ioMode recio.IOMode) (lw *LogWriter, err error)
- func (l *Log) Stat() (stat Stat)
- func (l *Log) Subscribe(subscriber chan Stat)
- func (l *Log) Unsubscribe(subscriber chan Stat)
- type LogReader
- func (lr *LogReader) Close() (err error)
- func (lr *LogReader) Fill() (err error)
- func (lr *LogReader) Read(r *Record) (n int, err error)
- func (lr *LogReader) Seek(position int64, whence Whence) (err error)
- func (lr *LogReader) SetWaitDeadline(t time.Time) (err error)
- func (lr *LogReader) Tell() (position int64, offset int64)
- type LogWriter
- type Options
- type Record
- type Stat
- type SyncHandler
- type SyncProgress
- type Whence
Constants ¶
const ( MaxRecordSize = 1<<31 - 1 // Maximum size of an encoded record MaxPayloadSize = MaxRecordSize - 4 - 4 // MaxRecordSize - size - CRC )
Variables ¶
var ( ErrExist = errors.New("log: already exists") ErrNotExist = errors.New("log: does not exist") ErrBadVersion = errors.New("log: bad version") ErrCorrupt = errors.New("log: corrupt") ErrOutOfRange = errors.New("log: out of range") ErrLagging = errors.New("log: lagging") ErrLocked = errors.New("log: locked") ErrOrphaned = errors.New("log: orphaned") ErrClosed = errors.New("log: closed") ErrTimeout = errors.New("log: timeout") )
var (
DefaultConfig = Config{
MaxRecordSize: 1 << 20,
IndexAfterSize: 1 << 20,
SegmentMaxCount: -1,
SegmentMaxSize: 1 << 30,
SegmentMaxAge: -1,
LogMaxCount: -1,
LogMaxSize: -1,
LogMaxAge: -1,
}
)
var ( DefaultOptions = Options{ SyncLock: sync.Mutex{}, } )
var ErrRecordTooLarge = errors.New("log: record too large")
ErrRecordTooLarge is returned when the payload size is too large for the encoded size to stay below the MaxRecordSize hard limit.
Functions ¶
Types ¶
type Config ¶
type Config struct { MaxRecordSize int // Maximum size of an encoded record. IndexAfterSize int64 // Create an index entry every N bytes. SegmentMaxCount int64 // Maximum record count in a segment. SegmentMaxSize int64 // Maximum byte size of a segment. SegmentMaxAge int64 // Maximum age in seconds of a segment. LogMaxCount int64 // Maximum record count in the log. LogMaxSize int64 // Maximum byte size of the log. LogMaxAge int64 // Maximum age in seconds of the log. }
type FaninWriter ¶
type FaninWriter struct {
// contains filtered or unexported fields
}
func NewFaninWriter ¶
func NewFaninWriter(f *Fanin, ioMode recio.IOMode) (fw *FaninWriter)
func (*FaninWriter) Close ¶
func (fw *FaninWriter) Close() (err error)
func (*FaninWriter) Flush ¶
func (fw *FaninWriter) Flush() (err error)
func (*FaninWriter) HandleSync ¶
func (fw *FaninWriter) HandleSync(h SyncHandler)
type Log ¶
type Log struct {
// contains filtered or unexported fields
}
func (*Log) Unsubscribe ¶
type LogWriter ¶
type LogWriter struct {
// contains filtered or unexported fields
}
func (*LogWriter) HandleSync ¶
func (lw *LogWriter) HandleSync(h SyncHandler)
type Record ¶
type Record []byte
Record implements the encoding and decoding of length-prefixed byte buffers.
Encoded log records are structured as follows.
+----------------+--------------------------------+- - - - - - - - + | size (int32) | payload (size bytes) | CRC (uint32) | +----------------+--------------------------------+- - - - - - - - +
Size is a big-endian int32 and encodes the payload length. Payload is a variable length byte buffer. A CRC32-C of the whole record is implicitly appended and checked when using recio atomic readers / writers.
Payload length is limited to 2,147,483,639 bytes (~2GB, max int32 - 8).
DESIGN: Limiting record size to the maximum signed 32 bits integer ensures that records will not overflow Encode and Decode return values, and that record sizes can be delt with on any platform as a standard int, avoiding cascading typing issues.
Overall, sticking to int avoids awkward and brittle type conversions in client code at the relatively low cost of limiting payload sizes to a little bit less that 2GB.
Using int64 for sizes was rejected in favor of int32 both for performance and data integrity reasons, since no CRC for this kind of block length is as well understood and hardware accelerated as CRC32-C.
func (*Record) Decode ¶
Decode implements the recio.Decoder interface. It decodes the record from the provided byte slice. It fails with err == ErrRecordTooLarge if the payload exeeds MaxPayloadSize. If the records is not decodeable, it returns err == ErrInvalidRecord. This method is used by Read to decode records and should not be called directly.
type SyncHandler ¶
type SyncHandler func(syncProgress SyncProgress)