disk

package
v0.0.0-...-43c3cf5 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxBlockfileSize   = 128 * 1024 * 1024 // 128 MiB
	BlockfileChunkSize = 16 * 1024 * 1024  // 16 MiB

	MinDiskSpace = 256 * 1024 * 1024 // 256 MiB
)
View Source
const (
	MaxFileIdleTime = 10 * time.Minute
)

Variables

View Source
var (
	ErrInvalidFlatFilePos    = errors.New("invalid FlatFilePos")
	ErrOutOfSpace            = errors.New("out of space")
	ErrReadBrokenBlockHeader = errors.New("read broken block header")
	ErrReadBrokenBlock       = errors.New("read broken block")
	ErrReadBrokenData        = errors.New("read broken data")
	ErrFileOutOfRange        = errors.New("file out of range")
	ErrClosed                = errors.New("file writer closed")
)
View Source
var (
	MagicNo                = [4]byte{0xf9, 0xbe, 0xb4, 0xd9}
	MagicNoLength          = len(MagicNo)
	RawBlkSizeLength       = 8
	BlkMessageHeaderLength = MagicNoLength + RawBlkSizeLength
)
View Source
var CheckDiskSpaceStub func(path string, additional uint64) bool

Functions

func CheckDiskSpaceNonWin

func CheckDiskSpaceNonWin(path string, additional uint64) bool

func TruncateFile

func TruncateFile(f *os.File, size int64) error

Types

type BlockFile

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

func NewBlockFile

func NewBlockFile(fileNo uint32, readonly bool) *BlockFile

func NewBlockFileFromBytes

func NewBlockFileFromBytes(data []byte, readonly bool) *BlockFile

func (*BlockFile) AddBlock

func (b *BlockFile) AddBlock(height, size uint64, timestamp uint64)

func (*BlockFile) Bytes

func (b *BlockFile) Bytes() []byte

func (*BlockFile) Close

func (b *BlockFile) Close()

func (*BlockFile) Flush

func (b *BlockFile) Flush(size int64, finalize bool)

func (*BlockFile) Number

func (b *BlockFile) Number() uint32

func (*BlockFile) ReadRawData

func (b *BlockFile) ReadRawData(flatFileSeq *FlatFileSeq, offset int64, size int) ([]byte, error)

read raw data

func (*BlockFile) Size

func (b *BlockFile) Size() uint64

func (*BlockFile) WriteRawBlock

func (b *BlockFile) WriteRawBlock(flatFileSeq *FlatFileSeq, offset int64, data []byte) error

write raw block

type BlockFileKeeper

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

func NewBlockFileKeeper

func NewBlockFileKeeper(dir string, records [][]byte) *BlockFileKeeper

func (*BlockFileKeeper) Close

func (b *BlockFileKeeper) Close()

func (*BlockFileKeeper) CommitRecentChange

func (b *BlockFileKeeper) CommitRecentChange()

func (*BlockFileKeeper) DiscardRecentChange

func (b *BlockFileKeeper) DiscardRecentChange()

func (*BlockFileKeeper) ReadRawBlock

func (b *BlockFileKeeper) ReadRawBlock(fileNo uint32, offset int64, blkSize int) ([]byte, error)

ReadRawBlock returns raw block bytes

func (*BlockFileKeeper) ReadRawTx

func (b *BlockFileKeeper) ReadRawTx(fileNo uint32, offsetBlk, offsetTxInBlk int64, txSize int) ([]byte, error)

ReadRawTx returns raw transaction bytes

func (*BlockFileKeeper) SaveRawBlockToDisk

func (b *BlockFileKeeper) SaveRawBlockToDisk(rawBlk []byte, height uint64, timestamp int64) (file *BlockFile, offset int64, err error)

type FlatFilePos

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

func NewFlatFilePos

func NewFlatFilePos(fileNo uint32, pos int64) *FlatFilePos

func (*FlatFilePos) FileNo

func (f *FlatFilePos) FileNo() uint32

func (*FlatFilePos) Pos

func (f *FlatFilePos) Pos() int64

func (*FlatFilePos) String

func (f *FlatFilePos) String() string

type FlatFileSeq

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

func NewFlatFileSeq

func NewFlatFileSeq(dir, prefix string, chunkSize int64) *FlatFileSeq

func (*FlatFileSeq) Allocate

func (f *FlatFileSeq) Allocate(pos *FlatFilePos, size int64) error

func (*FlatFileSeq) ExistFile

func (f *FlatFileSeq) ExistFile(pos *FlatFilePos) (bool, error)

func (*FlatFileSeq) FilePath

func (f *FlatFileSeq) FilePath(pos *FlatFilePos) string

func (*FlatFileSeq) Open

func (f *FlatFileSeq) Open(pos *FlatFilePos, readOnly bool) (file *os.File, err error)

Jump to

Keyboard shortcuts

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