data

package
v0.0.0-...-63846e3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

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")
	ErrInvalidSize   = errors.New("invalid size value in log record")
	ErrReadLogRecord = errors.New("failed to read log record")
)

Functions

func EncodeLogRecord

func EncodeLogRecord(logRecord *LogRecord) ([]byte, int64)

EncodeLogRecord 对 LogRecord 进行编码,返回字节数组及长度

+-------------+-------------+-------------+--------------+-------------+--------------+
| crc 校验值  |  type 类型   |    key size |   value size |      key    |      value   |
+-------------+-------------+-------------+--------------+-------------+--------------+
    4字节          1字节        变长(最大5)   变长(最大5)     变长           变长

func EncodeLogRecordPos

func EncodeLogRecordPos(pos *Position) []byte

func GetDataFileName

func GetDataFileName(dirPath string, fileId uint32) string

Types

type DataFile

type DataFile struct {
	FileId    uint32        // File ID
	WriteOff  int64         // 文件写到哪个位置
	IoManager fio.IOManager // io 读写管理
}

DataFile represents a data file

func OpenDataFile

func OpenDataFile(dirPath string, fileId uint32, ioType fio.FileIOType) (*DataFile, error)

func OpenHintFile

func OpenHintFile(dirPath string) (*DataFile, error)

func OpenMergeFinishedFile

func OpenMergeFinishedFile(dirPath string) (*DataFile, error)

func OpenSeqNoFile

func OpenSeqNoFile(dirPath string) (*DataFile, error)

OpenSeqNoFile opens the file that stores transaction sequence numbers

func (*DataFile) Close

func (df *DataFile) Close() error

func (*DataFile) ReadLogRecord

func (df *DataFile) ReadLogRecord(offset int64) (*LogRecord, int64, error)

ReadLogRecord reads a LogRecord from the data file at the given offset

func (*DataFile) SetIOManager

func (df *DataFile) SetIOManager(dirPath string, ioType fio.FileIOType) error

func (*DataFile) Sync

func (df *DataFile) Sync() error

func (*DataFile) Write

func (df *DataFile) Write(buf []byte) error

func (*DataFile) WriteHintRecord

func (df *DataFile) WriteHintRecord(key []byte, pos *Position) error

WriteHintRecord writes the index to the hint file

type LogRecord

type LogRecord struct {
	Key   []byte
	Value []byte
	Type  LogRecordType
}

LogRecord 之所以叫日志,是因为数据文件中的数据是追加写入的,类似日志的格式

type LogRecordType

type LogRecordType = byte
const (
	LogRecordNormal  LogRecordType = iota
	LogRecordDeleted               // 在 loadIndexFromDataFiles 的时候遇到有删除标记的,也就会删除
	LogRecordTxnFinished
)

type Position

type Position struct {
	Fid    uint32 // 文件id, 将文件存储的到了哪个文件夹
	Offset int64  // 偏移,数据存储到了数据文件中的哪个位置
	Size   uint32 // 标识数据在磁盘上的大小

}

Position 数据内存索引,主要是描述数据在磁盘上的位置

func DecodeLogRecordPos

func DecodeLogRecordPos(buf []byte) *Position

type TransactionRecord

type TransactionRecord struct {
	Record *LogRecord
	Pos    *Position
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL