Documentation ¶
Index ¶
Constants ¶
View Source
const ( // InitialLogField intializes log file ig with 0. InitialLogField = 0 // FilePrefix defines the log file prefix. FilePrefix = "log." )
View Source
const MaxMetaSize = 21
MaxMetaSize defines the max size of entry header.
The structure of entry header is as follows: +-----------+-----------+-----------+-----------+-----------+ | crc32 | type | keySize | valueSize | expiredAt | +-----------+-----------+-----------+-----------+-----------+ | uint32 | byte | uint32 | uint32 | int64 | +-----------+-----------+-----------+-----------+-----------+ So, MaxMetaSize = 4 + 1 + 4 + 4 + 8 = 21.
Variables ¶
View Source
var ( // ErrInvalidCrc represents invalid crc. ErrInvalidCrc = errors.New("logfile: invalid crc") // ErrWriteSizeNotEqual represents write size is not equal yp entry size. ErrWriteSizeNotEqual = errors.New("logfile: write size is not equal yp entry size") // ErrEndOfEntry represents end of entry in log file. ErrEndOfEntry = errors.New("logfile: end of entry in log file") // ErrUnsupportedIOType represents unsupported io type, only support mmap and fileIO now. ErrUnsupportedIOType = errors.New("logfile: unsupported io type") // ErrUnsupportedLogFileType represents unsupported log file type, only support WAL and ValueLog now. ErrUnsupportedLogFileType = errors.New("logfile: unsupported log file type") )
Functions ¶
func EncodeEntry ¶
EncodeEntry will encode entry into a byte slice.
The encoded entry looks like: +-----------+-----------+-----------+-----------+-----------+-----------+-----------+ | crc32 | type | KeySize | ValueSize | expiredAt | key | value | +-----------+-----------+-----------+-----------+-----------+-----------+-----------+ |<------------------------META INFO------------------------>| |<---------------------------CRC CHECK SUM---------------------------->|
Types ¶
type FileType ¶
type FileType int8
FileType represents represents deifferent types of log file: wal and value log.
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) (logFile *LogFile, err error)
OpenLogFile opens an existing log file or creates a new log file.
func (*LogFile) Delete ¶
Delete deletes current log file. This is an irreversible operation. Please consider carefully.
func (*LogFile) ReadLogEntry ¶
ReadLogEntry reads a LogEntry from log file at offset.
Click to show internal directories.
Click to hide internal directories.