Documentation
¶
Index ¶
- Constants
- Variables
- func EncodeLogRecord(logRecord *LogRecord) ([]byte, int64)
- func EncodeLogRecordPos(pos *LogRecordPos) []byte
- func GetDataFileName(dirPath string, fileId uint32) string
- type DataFile
- func (df *DataFile) Close() error
- func (df *DataFile) ReadLogRecord(offset int64) (*LogRecord, int64, error)
- func (df *DataFile) SetIOManager(dirPath string, ioType fio.FileIOType) error
- func (df *DataFile) Sync() error
- func (df *DataFile) Write(buf []byte) error
- func (df *DataFile) WriteHintRecord(key []byte, pos *LogRecordPos) error
- type LogRecord
- type LogRecordPos
- type LogRecordType
- type TransactionRecord
Constants ¶
View Source
const ( DataFileNameSuffix = ".data" HintFileName = "hint-index" MergeFinishedFileName = "merge-finished" SeqNoFileName = "seq-no" )
Variables ¶
View Source
var (
ErrInvalidCRC = errors.New("invalid crc value, log record maybe corrupted")
)
Functions ¶
func EncodeLogRecord ¶
EncodeLogRecord 对 LogRecord 进行编码,返回字节数组及长度
+-------------+-------------+-------------+--------------+-------------+--------------+ | crc 校验值 | type 类型 | key size | value size | key | value | +-------------+-------------+-------------+--------------+-------------+--------------+ 4字节 1字节 变长(最大5) 变长(最大5) 变长 变长
func EncodeLogRecordPos ¶
func EncodeLogRecordPos(pos *LogRecordPos) []byte
EncodeLogRecordPos 对位置信息进行编码
func GetDataFileName ¶
Types ¶
type DataFile ¶
type DataFile struct { FileId uint32 // 文件id WriteOff int64 // 文件写到了哪个位置 IoManager fio.IOManager // io 读写管理器 }
DataFile 数据文件
func OpenDataFile ¶
OpenDataFile 打开新的数据文件
func OpenMergeFinishedFile ¶
OpenMergeFinishedFile 打开标识 merge 完成的文件
func (*DataFile) ReadLogRecord ¶
ReadLogRecord 根据 offset 从数据文件中读取 LogRecord
func (*DataFile) SetIOManager ¶
func (df *DataFile) SetIOManager(dirPath string, ioType fio.FileIOType) error
func (*DataFile) WriteHintRecord ¶
func (df *DataFile) WriteHintRecord(key []byte, pos *LogRecordPos) error
WriteHintRecord 写入索引信息到 hint 文件中
type LogRecord ¶
type LogRecord struct { Key []byte Value []byte Type LogRecordType // tombstone墓碑值,删除数据时需要使用 }
Logecord 写入到数据文件的记录。日志:数据文件中的数据是追加写入的,类似日志格式
type LogRecordPos ¶
数据的内存索引,主要描述数据在磁盘上的位置
func DecodeLogRecordPos ¶
func DecodeLogRecordPos(buf []byte) *LogRecordPos
DecodeLogRecordPos 解码 LogRecordPos
type LogRecordType ¶
type LogRecordType = byte
const ( LogRecordNormal LogRecordType = iota LogRecordDeleted LogRecordTxnFinished )
type TransactionRecord ¶
type TransactionRecord struct { Record *LogRecord Pos *LogRecordPos }
TransactionRecord 暂存的事务相关的数据
Click to show internal directories.
Click to hide internal directories.