Help us shape the future of Go! Take the 2026 Go Developer Survey

serialization

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: 4 Imported by: 0

README

设计思路

因为我们在底层上分了4、5个不同的数据库,而每个数据库又有可能是KV或者SQL类型的数据库,所以如果我们每次传入的都是pb.Block对象的话,就可能在每个数据库中都要去做Block、Tx的序列化,这样重复的序列化导致性能下降,所以我们需要设计一个BlockWithSerializedInfo,传入的是这个对象,而这个对象中如果要序列化的话,只序列化一次,另一个数据库中要使用时就不用重复的序列化了。

BlockWithSerializedInfo对象的设计

构造的时候基于BlockWithRWSet,然后对外的公共属性就行Block和[]RWSet,剩下的都应该通过方法来提供。实际情况中,就算每个数据库都使用同样的KV数据库,其逻辑上其实并没有出现需要重复序列化的情景,所以这个设计算是一个为未来扩展而做的设计,当前看来并没有什么优势。

Documentation

Overview

Package serialization package

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeserializeBlock

func DeserializeBlock(serializedBlock []byte) (*storePb.BlockWithRWSet, error)

DeserializeBlock returns a deserialized block for given serialized bytes @Description: @param serializedBlock @return *storePb.BlockWithRWSet @return error

func DeserializeMeta added in v2.2.0

func DeserializeMeta(serializedBlock []byte) (*storePb.SerializedBlock, error)

DeserializeMeta 反序列化 meta 数据 @Description: @param serializedBlock @return *storePb.SerializedBlock @return error

Types

type BlockIndex added in v2.3.4

type BlockIndex struct {
	//整个Block+RWSet序列化后存储的位置
	Index *storePb.StoreInfo
	//Block基本信息(storePb.SerializedBlock)序列化后存储的位置
	MetaIndex *storePb.StoreInfo
	//交易列表序列化后的存储位置
	TxsIndex []*storePb.StoreInfo
	//读写集序列化后存储的位置
	RWSetsIndex []*storePb.StoreInfo
}

BlockIndex file block's block index detail @Description:

type BlockIndexMeta added in v2.3.4

type BlockIndexMeta struct {
	Height         uint64
	BlockTimestamp int64
	BlockHash      []byte
	TxIds          []string
	RwSets         []string
	BlockIndex
}

BlockIndexMeta add next time @Description:

type BlockWithSerializedInfo

type BlockWithSerializedInfo struct {
	Block                    *commonPb.Block
	Meta                     *storePb.SerializedBlock // Block without Txs
	SerializedMeta           []byte
	Txs                      []*commonPb.Transaction
	SerializedTxs            [][]byte
	TxRWSets                 []*commonPb.TxRWSet
	SerializedTxRWSets       [][]byte
	ContractEvents           []*commonPb.ContractEvent
	SerializedContractEvents [][]byte
	BlockIndex
}

BlockWithSerializedInfo contains block,txs and corresponding serialized data @Description:

func NewBlockSerializedInfo added in v2.2.0

func NewBlockSerializedInfo() *BlockWithSerializedInfo

NewBlockSerializedInfo 创建一个序列化对象 @Description: @return *BlockWithSerializedInfo

func SerializeBlock

func SerializeBlock(blockWithRWSet *storePb.BlockWithRWSet) ([]byte, *BlockWithSerializedInfo, error)

SerializeBlock serialized a BlockWithRWSet and return serialized data which combined as a BlockWithSerializedInfo @Description: @param blockWithRWSet @return []byte @return *BlockWithSerializedInfo @return error

func (*BlockWithSerializedInfo) ReSet added in v2.2.0

func (b *BlockWithSerializedInfo) ReSet()

ReSet 为sync.pool 重置 BlockWithSerializedInfo 状态时使用 @Description: @receiver b

func (*BlockWithSerializedInfo) SerializeEventTopicTable added in v2.2.0

func (b *BlockWithSerializedInfo) SerializeEventTopicTable(buf *proto.Buffer) error

SerializeEventTopicTable 序列化ContractEvents信息 @Description: @receiver b @param buf @return error

func (*BlockWithSerializedInfo) SerializeMeta added in v2.2.0

func (b *BlockWithSerializedInfo) SerializeMeta(buf *proto.Buffer) error

SerializeMeta 序列化meta信息,主要包括 header,dag,txids,additionalData数据 @Description: @receiver b @param buf @return error

func (*BlockWithSerializedInfo) SerializeTxRWSets added in v2.2.0

func (b *BlockWithSerializedInfo) SerializeTxRWSets(buf *proto.Buffer) error

SerializeTxRWSets 序列化读写集 @Description: @receiver b @param buf @return error

func (*BlockWithSerializedInfo) SerializeTxs added in v2.2.0

func (b *BlockWithSerializedInfo) SerializeTxs(buf *proto.Buffer) error

SerializeTxs 序列化txs信息 @Description: @receiver b @param buf @return error

Source Files

  • block_serialization.go

Jump to

Keyboard shortcuts

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