blockfiledb

package
v2.3.2 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2022 License: Apache-2.0 Imports: 29 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 wrap "invalidate rfile index"
	ErrInvalidateIndex = errors.New("invalidate rfile index")

	// ErrBlockWrite wrap "write block wfile size invalidate"
	ErrBlockWrite = errors.New("write block wfile size invalidate")
)
View Source
var DbType_Mysql = "mysql"

nolint

View Source
var DefaultOptions = &Options{
	NoSync:           false,
	SegmentSize:      67108864,
	SegmentCacheSize: 25,
	NoCopy:           false,
	UseMmap:          true,
}

DefaultOptions for Open().

Functions

func FileIndexToString

func FileIndexToString(fiIndex *storePb.StoreInfo) string

FileIndexToString convert

@Description:
@param fiIndex
@return string

Types

type Batch

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

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

@Description:

func (*Batch) Write

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

Write @Description: Write an entry to the batch @receiver b @param index @param data

type BlockFile

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

BlockFile represents a block to rfile

func Open

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

Open a new write ahead log

@Description:
@param path
@param opts
@param logger
@return *BlockFile
@return error

func (*BlockFile) ClearCache

func (l *BlockFile) ClearCache() error

ClearCache clears the segment cache

@Description:
@receiver l
@return error

func (*BlockFile) Close

func (l *BlockFile) Close() error

Close the log.

@Description:
@receiver l
@return error

func (*BlockFile) LastIndex

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

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

@Description:

log has no entries.

@receiver l
@return index
@return err

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.

@Description:
@receiver l
@param fiIndex
@return []byte
@return error

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.

@Description:
@receiver l
@param index
@return data
@return fileName
@return offset
@return byteLen
@return err

func (*BlockFile) Sync

func (l *BlockFile) Sync() error

Sync performs an fsync on the log. This is not necessary when the

@Description:

NoSync option is set to false.

@receiver l
@return error

func (*BlockFile) TruncateFront

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

TruncateFront 清除数据

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

func (*BlockFile) Write

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

Write @Description: Write an entry to the block rfile db. @receiver l @param index @param data @return fileName @return offset @return blkLen @return err

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.

@Description:
@receiver l
@param b
@return *storePb.StoreInfo
@return error

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

NewBlockFileDB construct BlockFileDB

@Description:
@param chainId
@param dbHandle
@param logger
@param storeConfig
@param fileStore
@return *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.

@Description:
@receiver b
@param blockHash
@return bool
@return error

func (*BlockFileDB) Close

func (b *BlockFileDB) Close()

Close is used to close database

@Description:
@receiver b

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

@Description:
@receiver b
@param blockInfo
@param isCache
@return error

func (*BlockFileDB) CommitCache

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

CommitCache 提交数据到cache

@Description:
@receiver b
@param blockInfo
@return error

func (*BlockFileDB) CommitDB

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

CommitDB 提交数据到kvdb

@Description:
@receiver b
@param blockInfo
@return error

func (*BlockFileDB) GetArchivedPivot

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

GetArchivedPivot return archived pivot

@Description:
@receiver b
@return uint64
@return error

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.

@Description:
@receiver b
@param height
@return *commonPb.Block
@return error

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.

@Description:
@receiver b
@param blockHash
@return *commonPb.Block
@return error

func (*BlockFileDB) GetBlockByTx

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

GetBlockByTx returns a block which contains a tx.

@Description:
@receiver b
@param txId
@return *commonPb.Block
@return error

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.

@Description:
@receiver b
@param height
@return *commonPb.BlockHeader
@return error

func (*BlockFileDB) GetBlockIndex

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

GetBlockIndex returns the offset of the block in the rfile

@Description:
@receiver b
@param height
@return *storePb.StoreInfo
@return error

func (*BlockFileDB) GetBlockMeta

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

GetBlockMeta add next time

@Description:
@receiver b
@param height
@return *storePb.SerializedBlock
@return error

func (*BlockFileDB) GetBlockMetaIndex

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

GetBlockMetaIndex returns the offset of the block in the rfile

@Description:
@receiver b
@param height
@return *storePb.StoreInfo
@return error

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.

@Description:
@receiver b
@param height
@return *storePb.SerializedBlock
@return error

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.

@Description:
@receiver b
@param blockHash
@return uint64
@return error

func (*BlockFileDB) GetLastBlock

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

GetLastBlock returns the last block.

@Description:
@receiver b
@return *commonPb.Block
@return error

func (*BlockFileDB) GetLastConfigBlock

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

GetLastConfigBlock returns the last config block.

@Description:
@receiver b
@return *commonPb.Block
@return error

func (*BlockFileDB) GetLastConfigBlockHeight

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

GetLastConfigBlockHeight returns the last config block height.

@Description:
@receiver b
@return uint64
@return error

func (*BlockFileDB) GetLastSavepoint

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

GetLastSavepoint returns the last block height

@Description:
@receiver b
@return uint64
@return error

func (*BlockFileDB) GetTx

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

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

@Description:
@receiver b
@param txId
@return *commonPb.Transaction
@return error

func (*BlockFileDB) GetTxConfirmedTime

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

GetTxConfirmedTime returns the confirmed time of a given tx

@Description:
@receiver b
@param txId
@return int64
@return error

func (*BlockFileDB) GetTxHeight

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

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

@Description:
@receiver b
@param txId
@return uint64
@return error

func (*BlockFileDB) GetTxIndex

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

GetTxIndex returns the offset of the transaction in the rfile

@Description:
@receiver b
@param txId
@return *storePb.StoreInfo
@return error

func (*BlockFileDB) GetTxInfoOnly

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

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

@Description:
@receiver b
@param txId
@return *storePb.TransactionStoreInfo
@return error

func (*BlockFileDB) GetTxWithBlockInfo

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

GetTxWithBlockInfo add next time

@Description:
@receiver b
@param txId
@return *storePb.TransactionStoreInfo
@return error

func (*BlockFileDB) InitGenesis

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

InitGenesis init genesis block

@Description:
@receiver b
@param genesisBlock
@return error

func (*BlockFileDB) RestoreBlocks

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

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

@Description:
@receiver b
@param blockInfos
@return error

func (*BlockFileDB) ShrinkBlocks

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

ShrinkBlocks remove ranged txid--SerializedTx from kvdb

@Description:
@receiver b
@param startHeight
@param endHeight
@return map[uint64][]string
@return error

func (*BlockFileDB) TxArchived

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

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

@Description:
@receiver b
@param txId
@return bool
@return error

func (*BlockFileDB) TxExists

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

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

@Description:
@receiver b
@param txId
@return bool
@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 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
	// UseMmap It is a method of memory-mapped rfile I/O. It implements demand
	// paging because rfile contents are not read from disk directly and initially
	// do not use physical RAM at all
	UseMmap bool
}

Options for BlockFile

Jump to

Keyboard shortcuts

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