Documentation ¶
Index ¶
Constants ¶
const (
// FilePrefix log file prefix. Full name of a file for example file of strings is like: "path/log.strs.00000001".
FilePrefix = "log."
)
const MaxHeaderSize = 25
MaxHeaderSize max entry header size. 4 + 1 + 10 + 10 + 3 + 5 + 5 = 38 crc stat ExpiredAt TxID TxStatus kSize vSize (refer to binary.MaxVarintLen32 and binary.MaxVarintLen64)
Variables ¶
var ( // ErrLogEndOfFile read to the end of the logEntry file ErrLogEndOfFile = errors.New("logfile: end of logEntry file") // ErrIllegalFileSize illegal file size ErrIllegalFileSize = errors.New("logfile: illegal file size") // ErrUnsupportedIoType ioType not supported ErrUnsupportedIoType = errors.New("logfile: ioType not supported") // ErrUnsupportedFileType fileType not supported ErrUnsupportedFileType = errors.New("logfile fileType not supported") // ErrInvalidCrc invalid crc. ErrInvalidCrc = errors.New("logfile: invalid crc") // ErrWriteSizeNotEqual write size is not equal to entry size. ErrWriteSizeNotEqual = errors.New("logfile: write size is not equal to entry size") )
Functions ¶
func EncodeEntry ¶
EncodeEntry encodes LogEntry into binary form, returns binary LogEntry and the size of LogEntry.
Types ¶
type IOType ¶
type IOType uint8
IOType represents different types of file io: FileIO(standard file io).
type LogEntry ¶
type LogEntry struct { ExpiredAt int64 // expire time Stat Status // delete or list meta TxID uint64 // transaction id TxStat TxStatus // committed / uncommitted Key []byte // key Value []byte // value // contains filtered or unexported fields }
LogEntry is the data will be appended in log file.
type LogFile ¶
type LogFile struct { Fid uint32 Offset int64 // WriteAt IoController iocontroller.IOController Mu sync.RWMutex }
LogFile is an abstraction of a disk file, entry`s read and write will go through it.
func Open ¶
Open opens an existing or create a new log file. fsize must be a postitive number.And we will create io controller according to ioType.
func (*LogFile) ReadLogEntry ¶
ReadLogEntry read a LogEntry from log file at offset. it returns LogEntry, entrySize and err if any