blockfiledb

package
v0.0.0-...-8b03266 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCorrupt is returns when the log is corrupt.
	ErrCorrupt = errors.New("log corrupt")

	// ErrClosed is returned when an operation cannot be completed because
	// the log is closed.
	ErrClosed = errors.New("log closed")

	// ErrNotFound is returned when an entry is not found.
	ErrNotFound = errors.New("not found")

	// ErrOutOfOrder is returned from Write() when the index is not equal to
	// LastIndex()+1. It's required that log monotonically grows by one and has
	// no gaps. Thus, the series 10,11,12,13,14 is valid, but 10,11,13,14 is
	// not because there's a gap between 11 and 13. Also, 10,12,11,13 is not
	// valid because 12 and 11 are out of order.
	ErrOutOfOrder = errors.New("out of order")

	// ErrInvalidateIndex
	ErrInvalidateIndex = errors.New("invalidate file index")

	ErrBlockWrite = errors.New("write block file size invalidate")
)
View Source
var DbType_Mysql = "mysql"
View Source
var DefaultOptions = &Options{
	NoSync:           false,
	SegmentSize:      20971520,
	SegmentCacheSize: 25,
	NoCopy:           false,
}

DefaultOptions for Open().

Functions

func FileIndexToString

func FileIndexToString(fiIndex *storePb.StoreInfo) string

Types

type Batch

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

Batch of entries. Used to write multiple entries at once using WriteBatch().

func (*Batch) Write

func (b *Batch) Write(index uint64, data []byte)

Write an entry to the batch

type BlockFile

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

BlockFile represents a block to file

func Open

func Open(path string, opts *Options, logger protocol.Logger) (*BlockFile, error)

Open a new write ahead log

func (*BlockFile) ClearCache

func (l *BlockFile) ClearCache() error

ClearCache clears the segment cache

func (*BlockFile) Close

func (l *BlockFile) Close() error

Close the log.

func (*BlockFile) LastIndex

func (l *BlockFile) LastIndex() (index uint64, err error)

LastIndex returns the index of the last entry in the log. Returns zero when log has no entries.

func (*BlockFile) ReadFileSection

func (l *BlockFile) ReadFileSection(fiIndex *storePb.StoreInfo) ([]byte, error)

ReadFileSection an entry from the log. Returns a byte slice containing the data entry.

func (*BlockFile) ReadLastSegSection

func (l *BlockFile) ReadLastSegSection(index uint64) (data []byte,
	fileName string, offset uint64, byteLen uint64, err error)

ReadLastSegSection an entry from the log. Returns a byte slice containing the data entry.

func (*BlockFile) Sync

func (l *BlockFile) Sync() error

Sync performs an fsync on the log. This is not necessary when the NoSync option is set to false.

func (*BlockFile) TruncateFront

func (l *BlockFile) TruncateFront(index uint64) error

清除数据

func (*BlockFile) Write

func (l *BlockFile) Write(index uint64, data []byte) (fileName string, offset, blkLen uint64, err error)

Write an entry to the block file db.

func (*BlockFile) WriteBatch

func (l *BlockFile) WriteBatch(b *Batch) (*storePb.StoreInfo, error)

WriteBatch writes the entries in the batch to the log in the order that they were added to the batch. The batch is cleared upon a successful return.

type BlockFileDB

type BlockFileDB struct {
	sync.Mutex
	// contains filtered or unexported fields
}

BlockFileDB provider a implementation of `blockdb.BlockDB` This implementation provides a key-value based data model

func NewBlockFileDB

func NewBlockFileDB(chainId string, dbHandle protocol.DBHandle, logger protocol.Logger,
	storeConfig *conf.StorageConfig, fileStore binlog.BinLogger) *BlockFileDB

func (*BlockFileDB) BlockExists

func (b *BlockFileDB) BlockExists(blockHash []byte) (bool, error)

BlockExists returns true if the block hash exist, or returns false if none exists.

func (*BlockFileDB) Close

func (b *BlockFileDB) Close()

Close is used to close database

func (*BlockFileDB) CommitBlock

func (b *BlockFileDB) CommitBlock(blockInfo *serialization.BlockWithSerializedInfo, isCache bool) error

CommitBlock commits the block and the corresponding rwsets in an atomic operation

func (*BlockFileDB) CommitCache

func (b *BlockFileDB) CommitCache(blockInfo *serialization.BlockWithSerializedInfo) error

CommitCache 提交数据到cache

func (*BlockFileDB) CommitDB

func (b *BlockFileDB) CommitDB(blockInfo *serialization.BlockWithSerializedInfo) error

提交数据到kvdb

func (*BlockFileDB) GetArchivedPivot

func (b *BlockFileDB) GetArchivedPivot() (uint64, error)

GetArchivedPivot return archived pivot

func (*BlockFileDB) GetBlock

func (b *BlockFileDB) GetBlock(height uint64) (*commonPb.Block, error)

GetBlock returns a block given it's block height, or returns nil if none exists.

func (*BlockFileDB) GetBlockByHash

func (b *BlockFileDB) GetBlockByHash(blockHash []byte) (*commonPb.Block, error)

GetBlockByHash returns a block given it's hash, or returns nil if none exists.

func (*BlockFileDB) GetBlockByTx

func (b *BlockFileDB) GetBlockByTx(txId string) (*commonPb.Block, error)

GetBlockByTx returns a block which contains a tx.

func (*BlockFileDB) GetBlockHeaderByHeight

func (b *BlockFileDB) GetBlockHeaderByHeight(height uint64) (*commonPb.BlockHeader, error)

GetBlockHeaderByHeight returns a block header by given it's height, or returns nil if none exists.

func (*BlockFileDB) GetBlockIndex

func (b *BlockFileDB) GetBlockIndex(height uint64) (*storePb.StoreInfo, error)

GetBlockIndex reurns the offset of the block in the file

func (*BlockFileDB) GetBlockMeta

func (b *BlockFileDB) GetBlockMeta(height uint64) (*storePb.SerializedBlock, error)

func (*BlockFileDB) GetBlockMetaIndex

func (b *BlockFileDB) GetBlockMetaIndex(height uint64) (*storePb.StoreInfo, error)

GetBlockMetaIndex returns the offset of the block in the file

func (*BlockFileDB) GetFilteredBlock

func (b *BlockFileDB) GetFilteredBlock(height uint64) (*storePb.SerializedBlock, error)

GetFilteredBlock returns a filtered block given it's block height, or return nil if none exists.

func (*BlockFileDB) GetHeightByHash

func (b *BlockFileDB) GetHeightByHash(blockHash []byte) (uint64, error)

GetHeightByHash returns a block height given it's hash, or returns nil if none exists.

func (*BlockFileDB) GetLastBlock

func (b *BlockFileDB) GetLastBlock() (*commonPb.Block, error)

GetLastBlock returns the last block.

func (*BlockFileDB) GetLastConfigBlock

func (b *BlockFileDB) GetLastConfigBlock() (*commonPb.Block, error)

GetLastConfigBlock returns the last config block.

func (*BlockFileDB) GetLastConfigBlockHeight

func (b *BlockFileDB) GetLastConfigBlockHeight() (uint64, error)

GetLastConfigBlockHeight returns the last config block height.

func (*BlockFileDB) GetLastSavepoint

func (b *BlockFileDB) GetLastSavepoint() (uint64, error)

GetLastSavepoint reurns the last block height

func (*BlockFileDB) GetTx

func (b *BlockFileDB) GetTx(txId string) (*commonPb.Transaction, error)

GetTx retrieves a transaction by txid, or returns nil if none exists.

func (*BlockFileDB) GetTxConfirmedTime

func (b *BlockFileDB) GetTxConfirmedTime(txId string) (int64, error)

GetTxConfirmedTime returns the confirmed time of a given tx

func (*BlockFileDB) GetTxHeight

func (b *BlockFileDB) GetTxHeight(txId string) (uint64, error)

GetTxHeight retrieves a transaction height by txid, or returns nil if none exists.

func (*BlockFileDB) GetTxIndex

func (b *BlockFileDB) GetTxIndex(txId string) (*storePb.StoreInfo, error)

GetTxIndex returns the offset of the transaction in the file

func (*BlockFileDB) GetTxInfoOnly

func (b *BlockFileDB) GetTxInfoOnly(txId string) (*storePb.TransactionStoreInfo, error)

GetTxInfoOnly 获得除Tx之外的其他TxInfo信息

func (*BlockFileDB) GetTxWithBlockInfo

func (b *BlockFileDB) GetTxWithBlockInfo(txId string) (*storePb.TransactionStoreInfo, error)

func (*BlockFileDB) InitGenesis

func (b *BlockFileDB) InitGenesis(genesisBlock *serialization.BlockWithSerializedInfo) error

func (*BlockFileDB) RestoreBlocks

func (b *BlockFileDB) RestoreBlocks(blockInfos []*serialization.BlockWithSerializedInfo) error

RestoreBlocks restore block data from outside to kvdb: txid--SerializedTx

func (*BlockFileDB) ShrinkBlocks

func (b *BlockFileDB) ShrinkBlocks(startHeight uint64, endHeight uint64) (map[uint64][]string, error)

ShrinkBlocks remove ranged txid--SerializedTx from kvdb

func (*BlockFileDB) TxArchived

func (b *BlockFileDB) TxArchived(txId string) (bool, error)

TxArchived returns true if the tx archived, or returns false.

func (*BlockFileDB) TxExists

func (b *BlockFileDB) TxExists(txId string) (bool, error)

TxExists returns true if the tx exist, or returns false if none exists.

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.

func (CRC) Update

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

Update updates the crc with the given bytes.

func (CRC) Value

func (c CRC) Value() uint32

Value returns a masked crc.

type Options

type Options struct {
	// NoSync disables fsync after writes. This is less durable and puts the
	// log at risk of data loss when there's a server crash.
	NoSync bool
	// SegmentSize of each segment. This is just a target value, actual size
	// may differ. Default is 20 MB.
	SegmentSize int
	// SegmentCacheSize is the maximum number of segments that will be held in
	// memory for caching. Increasing this value may enhance performance for
	// concurrent read operations. Default is 1
	SegmentCacheSize int
	// NoCopy allows for the Read() operation to return the raw underlying data
	// slice. This is an optimization to help minimize allocations. When this
	// option is set, do not modify the returned data because it may affect
	// other Read calls. Default false
	NoCopy bool
}

Options for BlockFile

Jump to

Keyboard shortcuts

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