serialization

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

README

设计思路

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

BlockWithSerializedInfo对象的设计

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

Documentation

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

func DeserializeMeta

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

反序列化 meta 数据

Types

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
	//整个Block+RWSet序列化后存储的位置
	Index *storePb.StoreInfo
	//Block基本信息(storePb.SerializedBlock)序列化后存储的位置
	MetaIndex *storePb.StoreInfo
	//交易列表序列化后的存储位置
	TxsIndex []*storePb.StoreInfo
	//读写集序列化后存储的位置
	RWSetsIndex []*storePb.StoreInfo
}

BlockWithSerializedInfo contains block,txs and corresponding serialized data

func NewBlockSerializedInfo

func NewBlockSerializedInfo() *BlockWithSerializedInfo

创建一个序列化对象

func SerializeBlock

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

SerializeBlock serialized a BlockWithRWSet and return serialized data which combined as a BlockWithSerializedInfo

func (*BlockWithSerializedInfo) ReSet

func (b *BlockWithSerializedInfo) ReSet()

为sync.pool 重置 BlockWithSerializedInfo 状态时使用

func (*BlockWithSerializedInfo) SerializeEventTopicTable

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

序列化ContractEvents信息

func (*BlockWithSerializedInfo) SerializeMeta

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

序列化meta信息,主要包括 header,dag,txids,additionalData数据

func (*BlockWithSerializedInfo) SerializeTxRWSets

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

序列化读写集

func (*BlockWithSerializedInfo) SerializeTxs

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

序列化txs信息

Jump to

Keyboard shortcuts

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