blockfile

package
v2.3.6 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package blockfile package

Index

Constants

View Source
const (
	DBFileSuffix          = ".fdb"
	DBFileNameLen         = 20
	BlockFilenameTemplate = "%020d"
	LastFileSuffix        = ".END"
)

nolint

View Source
const (
	ArchivingPath           = "archiving"
	RestoringPath           = "restoring"
	ArchivingBlockFileName  = ".block.archiving.json"
	ArchivingResultFileName = ".result.archiving.json"
	RestoringIndexFileName  = ".restoring.json"
	MergingFileSuffix       = ".merging"
	BakFileSuffix           = ".bak"
)

nolint

Variables

View Source
var (
	//ErrInvalidateRestoreBlocks invalidate restore blocks
	ErrInvalidateRestoreBlocks = errors.New("invalidate restore blocks")
	//ErrConfigBlockArchive config block do not need to archive
	ErrConfigBlockArchive = errors.New("config block do not need archive")
	//ErrArchivedTx archived transaction
	ErrArchivedTx = errors.New("archived transaction")
	//ErrArchivedRWSet archived RWSet
	ErrArchivedRWSet = errors.New("archived RWSet")
	//ErrArchivedBlock archived block
	ErrArchivedBlock = errors.New("archived block")
)

Functions

func AppendChecksum

func AppendChecksum(dst []byte, checksum uint32) []byte

AppendChecksum Customize part start

@Description:
@param dst
@param checksum
@return []byte

func AppendFileEntry

func AppendFileEntry(data []byte, fw *FileWriter, dataSize int, logger protocol.Logger) error

AppendFileEntry add next time @Description: @receiver l @param s @return error

func AppendUvarint

func AppendUvarint(dst []byte, x uint64) []byte

AppendUvarint Customize part end

@Description:
@param dst
@param x 整型序列化
@return []byte

func CheckSegmentName

func CheckSegmentName(name string) bool

CheckSegmentName add next time @Description: @param name @return bool

func CopyThenRemoveFile

func CopyThenRemoveFile(src, dst string, srcf *os.File) error

CopyThenRemoveFile copy src file to dst file.

these two path may be located in different disk, so can not use 'mv' directly to prevent network or power issue

@Description: @param src @param dst @return error

func FileIndexToString

func FileIndexToString(fiIndex *storePb.StoreInfo) string

FileIndexToString convert

@Description:
@param fiIndex
@return string

func LoadNextBinaryEntry

func LoadNextBinaryEntry(data []byte) (n, prefixLen int, err error)

LoadNextBinaryEntry 读取entry,返回

@Description:
@param data
@return n
@return prefixLen
@return err

func SegmentIndexPath

func SegmentIndexPath(name, path string) string

SegmentIndexPath build segment index dir path

@Description:
@receiver l
@param name
@return string

func SegmentNameToUint64

func SegmentNameToUint64(fileName string) (uint64, error)

SegmentNameToUint64 add next time @Description: @param fileName @return uint64 @return error

func SegmentPath

func SegmentPath(name, path string) string

SegmentPath build segment dir path

@Description:
@receiver l
@param name
@return string

func Uint64ToSegmentName

func Uint64ToSegmentName(index uint64) string

Uint64ToSegmentName returns a 20-byte textual representation of an index for lexical ordering. This is used for the rfile names of log segments.

@Description:
@receiver l
@param index
@return string

Types

type Bpos

type Bpos struct {
	Pos       int // byte position
	End       int // one byte past pos
	PrefixLen int
}

Bpos byte position info @Description:

func AppendBinaryEntry

func AppendBinaryEntry(dst []byte, data []byte) (out []byte, epos Bpos)

AppendBinaryEntry append an entry

@Description:
@receiver l
@param dst
@param data
@return out
@return epos

func LoadEntriesForRestarting

func LoadEntriesForRestarting(path string) ([]byte, []Bpos, error)

LoadEntriesForRestarting loads ebuf and epos in the segment when restarting

@Description:
@receiver l
@param s
@return error

func LoadSegmentEntriesForRestarting

func LoadSegmentEntriesForRestarting(path string, index uint64) ([]byte, []Bpos, error)

LoadSegmentEntriesForRestarting loads ebuf and epos in the segment when restarting

@Description:
@receiver l
@param s
@return error

type CRC

type CRC uint32

CRC is a CRC-32 checksum computed using Castagnoli's polynomial.

func NewCRC

func NewCRC(b []byte) CRC

NewCRC creates a new crc based on the given bytes.

@Description:
@param b
@return CRC

func (CRC) Update

func (c CRC) Update(b []byte) CRC

Update updates the crc with the given bytes.

@Description:
@receiver c
@param b
@return CRC

func (CRC) Value

func (c CRC) Value() uint32

Value returns a masked crc.

@Description:
@receiver c
@return uint32

type FileWriter

type FileWriter struct {
	Path  string
	Lfile *LockableFile // index file handle
	Ebuf  []byte        // cached entries buffer, storage format of one log entry: checksum|data_size|data
	Epos  []Bpos        // cached entries positions in buffer
}

FileWriter block file db file writer @Description:

func NewFileWriter

func NewFileWriter(path string) (*FileWriter, error)

NewFileWriter add next time @Description: @param path @return *FileWriter @return error

type IndexPair

type IndexPair struct {
	Key   []byte `json:"key"`
	Value []byte `json:"value"`
}

IndexPair index pair to contain update batch data

type LockableFile

type LockableFile struct {
	sync.RWMutex

	Wfile lwsf.WalFile
	Rfile *os.File
}

LockableFile add next time @Description:

func OpenWriteFile

func OpenWriteFile(path, fileSuffix string, useMmap bool, segSize int, log protocol.Logger) (*LockableFile, error)

OpenWriteFile open block file write file

@Description:
@receiver l
@param path
@return *lockableFile
@return error

type SegIndex

type SegIndex struct {
	Height uint64
	BIndex *serialization.BlockIndexMeta
}

SegIndex restore segment index structure @Description:

func LoadArchiveSegIndex

func LoadArchiveSegIndex(fw *FileWriter) ([]*SegIndex, error)

LoadArchiveSegIndex add next time @Description: @receiver l @param s @return error

type SegName

type SegName struct {
	IsTmp bool
	Name  string
	Index uint64
}

SegName segment name @Description:

Jump to

Keyboard shortcuts

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