data

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DataFileSuffix      = ".data"
	HintFileSuffix      = "hintIndex"
	MergeFinaFileSuffix = "mergeFina"
)

Variables

View Source
var (
	ErrInvalidCRC = errors.New("InvalidCrcError : invalid crc value, log record maybe corrupted")
)

Functions

func EncodeLogRecord

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

EncodeLogRecord encodes a LogRecord and returns the byte array and length. +-------------+------------+------------+--------------+-------+---------+---------+---------+---------+ | crc checksum | record type | key size | value size | key | value | +-------------+------------+------------+--------------+-------+---------+ | 4 bytes | 1 byte | variable (max 5) | variable (max 5) | variable | variable | +-------------+------------+------------+--------------+-------+---------+---------+---------+---------+

func EncodeLogRecordPst

func EncodeLogRecordPst(pst *LogRecordPst) []byte

EncodeLogRecordPst encodes the position information of a log record.

func GetDataFileName

func GetDataFileName(dirPath string, fileID uint32) string

GetDataFileName returns the file name for a data file.

Types

type DataFile

type DataFile struct {
	FileID    uint32           // File ID
	WriteOff  int64            // Position where the file is currently being written
	IoManager fileio.IOManager // IO read/write operations
}

DataFile represents a data file.

func OpenDataFile

func OpenDataFile(dirPath string, fileID uint32, fileSize int64, fioType int8) (*DataFile, error)

OpenDataFile opens a new data file.

func OpenHintFile

func OpenHintFile(dirPath string, fileSize int64, fioType int8) (*DataFile, error)

OpenHintFile opens the hint index file.

func OpenMergeFinaFile

func OpenMergeFinaFile(dirPath string, fileSize int64, fioType int8) (*DataFile, error)

OpenMergeFinaFile opens the file that indicates merge completion.

func (*DataFile) Close

func (df *DataFile) Close() error

func (*DataFile) ReadLogRecord

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

ReadLogRecord reads a log record from the data file based on the offset.

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, pst *LogRecordPst) error

WriteHintRecord writes index information to the hint file.

type LogRecord

type LogRecord struct {
	Key   []byte       // The key of the record
	Value []byte       // The value of the record
	Type  LogRecrdType // The type of the record
}

LogRecord represents a record written to the data file.

type LogRecordHeader

type LogRecordHeader struct {
	// contains filtered or unexported fields
}

LogRecordHeader represents the header information of a LogRecord.

type LogRecordPst

type LogRecordPst struct {
	Fid    uint32 // File ID: Indicates which file the data is stored in
	Offset int64  // Offset: Indicates the position in the data file where the data is stored
}

LogRecordPst represents the in-memory index of data, mainly describing the location of data on disk.

func DecodeLogRecordPst

func DecodeLogRecordPst(buf []byte) *LogRecordPst

DecodeLogRecordPst decodes the position information from a byte buffer.

type LogRecrdType

type LogRecrdType = byte
const (
	LogRecordNormal LogRecrdType = iota
	LogRecordDeleted
	LogRecordTransFinished
)

type TransactionRecord

type TransactionRecord struct {
	Record *LogRecord    // The log record associated with the transaction
	Pos    *LogRecordPst // The position of the log record in the data file
}

TransactionRecord temporarily holds transaction-related data.

Jump to

Keyboard shortcuts

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