Documentation ¶
Index ¶
Constants ¶
const ( // PathSeparator default path separator. PathSeparator = string(os.PathSeparator) // WalSuffixName log file suffix name of write ahead log. WalSuffixName = ".wal" // VLogSuffixName log file suffix name of value log. VLogSuffixName = ".vlog" // InitialLogFileId initial log file id: 0. InitialLogFileId = 0 )
const MaxHeaderSize = 25
MaxHeaderSize max entry header size. crc32 typ kSize vSize expiredAt
4 + 1 + 5 + 5 + 10 = 25 (refer to binary.MaxVarintLen32 and binary.MaxVarintLen64)
Variables ¶
var ( // 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") // ErrEndOfEntry end of entry in log file. ErrEndOfEntry = errors.New("logfile: end of entry in log file") // ErrUnsupportedIoType unsupported io type, only mmap and fileIO now. ErrUnsupportedIoType = errors.New("unsupported io type") // ErrUnsupportedLogFileType unsupported log file type, only WAL and ValueLog now. ErrUnsupportedLogFileType = errors.New("unsupported log file type") )
Functions ¶
func EncodeEntry ¶
EncodeEntry will encode entry into a byte slice. The encoded Entry looks like: +-------+--------+----------+------------+-----------+-------+---------+ | crc | type | key size | value size | expiresAt | key | value | +-------+--------+----------+------------+-----------+-------+---------+ |------------------------HEADER----------------------|
|--------------------------crc check---------------------------|
Types ¶
type FileType ¶
type FileType int8
FileType represents different types of log file: wal and value log.
type IOType ¶
type IOType int8
IOType represents different types of file io: FileIO(standard file io) and MMap(Memory Map).
type LogFile ¶
type LogFile struct { sync.RWMutex Fid uint32 WriteAt int64 IoSelector ioselector.IOSelector }
LogFile is an abstraction of a disk file, entry`s read and write will go through it.
func OpenLogFile ¶
func OpenLogFile(path string, fid uint32, fsize int64, ftype FileType, ioType IOType) (lf *LogFile, err error)
OpenLogFile open an existing or create a new log file. fsize must be a postitive number.And we will create io selector according to ioType.
func (*LogFile) Delete ¶
Delete delete current log file. File can`t be retrieved if do this, so use it carefully.
func (*LogFile) Read ¶
Read a byte slice in the log file at offset, slice length is the given size. It returns the byte slice and error, if any.
func (*LogFile) ReadLogEntry ¶
ReadLogEntry read a LogEntry from log file at offset. It returns a LogEntry, entry size and an error, if any. If offset is invalid, the err is io.EOF.