data

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// A fixed name suffix of every single data file in the DB engine
	DataFileNameSuffix = ".data"
	HintFileName       = "hint-index"
	MergedFileName     = "merged"
	TranNoFileName     = "tran-no"
)

Variables

View Source
var ErrInvalidCRC = errors.New("invalid CRC value. Maybe the log record was corrupted")

Functions

func DecodeKey

func DecodeKey(key []byte) ([]byte, uint64)

DecodeKey decodes the given key to get another record and a transaction serial number

Usually the given key has been encoded.

As an output, the decoded key is the one of a certain log record.

func EncodeKey

func EncodeKey(key []byte, tranNo uint64) []byte

EncodeKey encodes a key and a transaction serial number

The given key is usually from a log record

func EncodeLogRecord

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

EncodeLogRecord encodes a log record

func EncodeLogRecordPosition

func EncodeLogRecordPosition(lrp *LogRecordPosition) []byte

EncodeLogRecordPosition encodes a LogRecordPosition into a byte array

func GetDataFilePath

func GetDataFilePath(directory string, fileID uint32) string

func WriteHintRecord

func WriteHintRecord(hintFile *DataFile, key []byte, lrp *LogRecordPosition) error

WriteHintRecord writes a LogRecordPosition to a hint file

Types

type DataFile

type DataFile struct {
	FileID      uint32 // FileID identifies of a data file
	WriteOffset int64  // WriteOffset indicates the offset of the written data in a data file
	// contains filtered or unexported fields
}

DataFile represents a data file in a DB engine instance

func OpenDataFile

func OpenDataFile(
	directory string,
	fileID uint32,
	ioHandlerType io_handler.IOHandlerType,
) (*DataFile, error)

OpenDataFile opens a data file

func OpenHintFile

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

OpenHintFile opens a hint file

func OpenMergedFile

func OpenMergedFile(directory string) (*DataFile, error)

OpenMergedFile opens a merged file

func OpenTranNoFile

func OpenTranNoFile(directory string) (*DataFile, error)

OpenTranNoFile opens a file about a transaction serial number

func (*DataFile) Close

func (df *DataFile) Close() error

func (*DataFile) Path

func (df *DataFile) Path() string

Path returns the path of a data file

func (*DataFile) ReadLogRecord

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

ReadLogRecord reads single log record by given offset in a data file

func (*DataFile) SetIOHandler

func (df *DataFile) SetIOHandler(ioHandlerType io_handler.IOHandlerType) error

SetIOHandler switches I/O handler of a data file

func (*DataFile) Size

func (df *DataFile) Size() (int64, error)

func (*DataFile) Sync

func (df *DataFile) Sync() error

func (*DataFile) Write

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

type LogRecord

type LogRecord struct {
	Key   []byte        // Key
	Value []byte        // Value
	Type  LogRecordType // Type indicates whether a log record is unusable (deleted) or not
}

LogRecord represents a log record in a data file

type LogRecordPosition

type LogRecordPosition struct {
	// ID of the data file where the log record is stored in
	FileID uint32

	// Offset of the log record in the data file
	Offset int64

	// Size of the log record (uint: Byte)
	Size uint32
}

LogRecordPosition represents a position of a LogRecord A position of a LogRecord stores in an in-memory index

func DecodeLogRecordPosition

func DecodeLogRecordPosition(buffer []byte) *LogRecordPosition

DecodeLogRecordPosition decodes a byte array into a DecodeLogRecordPosition

type LogRecordType

type LogRecordType = byte

LogRecordType types of log records

const (
	NormalLogRecord              LogRecordType = iota + 1 // NormalLogRecord indicates that a log record is normal to read, update or delete
	DeletedLogRecord                                      // DeletedLogRecord indicates that a log record is deleted and unusable
	TransactionFinishedLogRecord                          // TransactionFinishedLogRecord indicates that a Transaction is finished
)

type TransactionRecord

type TransactionRecord struct {
	Log      *LogRecord         // a log record
	Position *LogRecordPosition // position of the log record
}

TransactionRecord

Jump to

Keyboard shortcuts

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