serialization

package
v2.4.0 Latest Latest
Warning

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

Go to latest
Published: May 28, 2025 License: Apache-2.0 Imports: 7 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 Deprecated: use NormalBlockNormalizer

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 BlockNormalized added in v2.4.0

type BlockNormalized struct {
	Block          *commonPb.Block
	Meta           *storePb.SerializedBlock // Block without Txs
	Txs            []*commonPb.Transaction
	TxRWSets       []*commonPb.TxRWSet
	ContractEvents []*commonPb.ContractEvent
	SerializationNormalized
}

BlockNormalized contains block,txs.. and corresponding serialized data

func (*BlockNormalized) ToBlockWithRWSet added in v2.4.0

func (n *BlockNormalized) ToBlockWithRWSet() *storePb.BlockWithRWSet

ToBlockWithRWSet build a BlockWithRWSet from BlockNormalized.

type BlockNormalizer added in v2.4.0

type BlockNormalizer interface {
	// NormalizeBlock Organize blocks into a standard format for storage definition.
	NormalizeBlock(blockWithRWSet *storePb.BlockWithRWSet) (*BlockNormalized, error)
	// NormalizeFromSerialization restore normalized data from serialized data
	NormalizeFromSerialization(*SerializationNormalized) (*BlockNormalized, error) //
	// Serializer get the serializer used by BlockNormalizer,
	// so that users can deserialize the character data in BlockNormalized.
	Serializer() Serializer
}

BlockNormalizer Organize blocks into a standard format for storage definition, and subsequent processes operate based on this format. It splits block data and serializes and deserializes the split data.

type BlockWithSerializedInfo

type BlockWithSerializedInfo struct {
	BlockNormalized
	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 Deprecated: use NormalBlockNormalizer

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

type NormalBlockNormalizer added in v2.4.0

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

NormalBlockNormalizer This is a general block normalizer. It uses the external serializer to serialize and deserialize the organization data, so that different serialization methods can be met in the future.

func NewNormalBlockNormalizer added in v2.4.0

func NewNormalBlockNormalizer(sinkCodec Serializer) *NormalBlockNormalizer

NewNormalBlockNormalizer constructs a NormalBlockNormalizer object using an externally provided serializer.

func NewNormalProtobufBlockNormalizer added in v2.4.0

func NewNormalProtobufBlockNormalizer() *NormalBlockNormalizer

NewNormalProtobufBlockNormalizer new normalizer with protobuf as serializer.

func (*NormalBlockNormalizer) NormalizeBlock added in v2.4.0

func (n *NormalBlockNormalizer) NormalizeBlock(blockWithRWSet *storePb.BlockWithRWSet) (
	*BlockNormalized, error)

NormalizeBlock organizes blocks into a standard format for storage definition. 1. Split and organize block data. 2. Serialize the split data.

func (*NormalBlockNormalizer) NormalizeFromSerialization added in v2.4.0

func (n *NormalBlockNormalizer) NormalizeFromSerialization(normal *SerializationNormalized) (*BlockNormalized, error)

NormalizeFromSerialization restore normalized data from serialized data

func (*NormalBlockNormalizer) Serializer added in v2.4.0

func (n *NormalBlockNormalizer) Serializer() Serializer

Serializer get the serializer used by BlockNormalizer, so that users can deserialize the character data in BlockNormalized

type SerializationNormalized added in v2.4.0

type SerializationNormalized struct {
	SerializedMeta           []byte
	SerializedTxs            [][]byte
	SerializedTxRWSets       [][]byte
	SerializedContractEvents [][]byte
}

SerializationNormalized serialized data of each part of the block

type Serializer added in v2.4.0

type Serializer interface {
	Encode(interface{}) ([]byte, error)
	Decode([]byte, interface{}) error
}

Serializer serializes and deserializes Objects

Source Files

  • block_normalzer.go
  • block_serialization.go
  • kind_go118.go
  • serializer.go

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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