etcdraft

package
v1.4.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2018 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultSnapshotCatchUpEntries = uint64(500)

DefaultSnapshotCatchUpEntries is the default number of entries to preserve in memory when a snapshot is taken. This is for slow followers to catch up.

Variables

This section is empty.

Functions

func ConfigEnvelopeFromBlock added in v1.4.0

func ConfigEnvelopeFromBlock(block *common.Block) (*common.Envelope, error)

ConfigEnvelopeFromBlock extracts configuration envelop from the block based on the config type, i.e. HeaderType_ORDERER_TRANSACTION or HeaderType_CONFIG

func ConsensusMetadataFromConfigBlock added in v1.4.0

func ConsensusMetadataFromConfigBlock(block *common.Block) (*etcdraft.Metadata, error)

ConsensusMetadataFromConfigBlock reads consensus metadata updates from the configuration block

func ConsentersToMap added in v1.4.0

func ConsentersToMap(consenters []*etcdraft.Consenter) map[string]struct{}

ConsentersToMap maps consenters into set where key is client TLS certificate

func EndpointconfigFromFromSupport added in v1.4.0

func EndpointconfigFromFromSupport(support consensus.ConsenterSupport) (*cluster.EndpointConfig, error)

EndpointconfigFromFromSupport extracts TLS CA certificates and endpoints from the ConsenterSupport

func IsMembershipUpdate added in v1.4.0

func IsMembershipUpdate(block *common.Block, currentMetadata *etcdraft.RaftMetadata) (bool, error)

IsMembershipUpdate checks whenever block is config block and carries raft cluster membership updates

func LastConfigBlock added in v1.4.0

func LastConfigBlock(block *common.Block, support consensus.ConsenterSupport) (*common.Block, error)

LastConfigBlock returns the last config block relative to the given block.

func MembershipByCert added in v1.4.0

func MembershipByCert(consenters map[uint64]*etcdraft.Consenter) map[string]struct{}

MembershipByCert convert consenters map into set encapsulated by map where key is client TLS certificate

func MetadataFromConfigUpdate added in v1.4.0

func MetadataFromConfigUpdate(update *common.ConfigUpdate) (*etcdraft.Metadata, error)

MetadataFromConfigUpdate extracts consensus metadata from config update

func MetadataFromConfigValue added in v1.4.0

func MetadataFromConfigValue(configValue *common.ConfigValue) (*etcdraft.Metadata, error)

MetadataFromConfigValue reads and translates configuration updates from config value into raft metadata

func RaftPeers added in v1.4.0

func RaftPeers(consenters map[uint64]*etcdraft.Consenter) []raft.Peer

RaftPeers maps consenters to slice of raft.Peer

Types

type BlockPuller added in v1.4.0

type BlockPuller interface {
	PullBlock(seq uint64) *common.Block
	Close()
}

BlockPuller is used to pull blocks from other OSN

type Chain

type Chain struct {
	BlockCreator *blockCreator
	// contains filtered or unexported fields
}

Chain implements consensus.Chain interface.

func NewChain

func NewChain(
	support consensus.ConsenterSupport,
	opts Options,
	conf Configurator,
	rpc RPC,
	puller BlockPuller,
	observeC chan<- uint64) (*Chain, error)

NewChain constructs a chain object.

func (*Chain) Configure

func (c *Chain) Configure(env *common.Envelope, configSeq uint64) error

Configure submits config type transactions for ordering.

func (*Chain) Errored

func (c *Chain) Errored() <-chan struct{}

Errored returns a channel that closes when the chain stops.

func (*Chain) Halt

func (c *Chain) Halt()

Halt stops the chain.

func (*Chain) Order

func (c *Chain) Order(env *common.Envelope, configSeq uint64) error

Order submits normal type transactions for ordering.

func (*Chain) Start

func (c *Chain) Start()

Start instructs the orderer to begin serving the chain and keep it current.

func (*Chain) Step added in v1.4.0

func (c *Chain) Step(req *orderer.StepRequest, sender uint64) error

Step passes the given StepRequest message to the raft.Node instance

func (*Chain) Submit

func (c *Chain) Submit(req *orderer.SubmitRequest, sender uint64) error

Submit forwards the incoming request to: - the local serveRequest goroutine if this is leader - the actual leader via the transport mechanism The call fails if there's no leader elected yet.

func (*Chain) WaitReady

func (c *Chain) WaitReady() error

WaitReady blocks when the chain: - is catching up with other nodes using snapshot

In any other case, it returns right away.

type ChainGetter added in v1.4.0

type ChainGetter interface {
	// GetChain obtains the ChainSupport for the given channel.
	// Returns nil, false when the ChainSupport for the given channel
	// isn't found.
	GetChain(chainID string) *multichannel.ChainSupport
}

ChainGetter obtains instances of ChainSupport for the given channel

type Config added in v1.4.0

type Config struct {
	WALDir  string // WAL data of <my-channel> is stored in WALDir/<my-channel>
	SnapDir string // Snapshots of <my-channel> are stored in SnapDir/<my-channel>
}

Config contains etcdraft configurations

type Configurator added in v1.4.0

type Configurator interface {
	Configure(channel string, newNodes []cluster.RemoteNode)
}

Configurator is used to configure the communication layer when the chain starts.

type Consenter added in v1.4.0

type Consenter struct {
	Dialer        *cluster.PredicateDialer
	Communication cluster.Communicator
	*Dispatcher
	Chains         ChainGetter
	Logger         *flogging.FabricLogger
	EtcdRaftConfig Config
	OrdererConfig  localconfig.TopLevel
	Cert           []byte
}

Consenter implements etddraft consenter

func New added in v1.4.0

New creates a etcdraft Consenter

func (*Consenter) HandleChain added in v1.4.0

func (c *Consenter) HandleChain(support consensus.ConsenterSupport, metadata *common.Metadata) (consensus.Chain, error)

HandleChain returns a new Chain instance or an error upon failure

func (*Consenter) ReceiverByChain added in v1.4.0

func (c *Consenter) ReceiverByChain(channelID string) MessageReceiver

ReceiverByChain returns the MessageReceiver for the given channelID or nil if not found.

func (*Consenter) TargetChannel added in v1.4.0

func (c *Consenter) TargetChannel(message proto.Message) string

TargetChannel extracts the channel from the given proto.Message. Returns an empty string on failure.

type ConsenterCertificate added in v1.4.0

type ConsenterCertificate []byte

ConsenterCertificate denotes a TLS certificate of a consenter

func (ConsenterCertificate) IsConsenterOfChannel added in v1.4.0

func (conCert ConsenterCertificate) IsConsenterOfChannel(configBlock *common.Block) error

IsConsenterOfChannel returns whether the caller is a consenter of a channel by inspecting the given configuration block. It returns nil if true, else returns an error.

type Dispatcher

type Dispatcher struct {
	Logger        *flogging.FabricLogger
	ChainSelector ReceiverGetter
}

Dispatcher dispatches Submit and Step requests to the designated per chain instances

func (*Dispatcher) OnStep

func (d *Dispatcher) OnStep(channel string, sender uint64, request *orderer.StepRequest) (*orderer.StepResponse, error)

OnStep notifies the Dispatcher for a reception of a StepRequest from a given sender on a given channel

func (*Dispatcher) OnSubmit

func (d *Dispatcher) OnSubmit(channel string, sender uint64, request *orderer.SubmitRequest) (*orderer.SubmitResponse, error)

OnSubmit notifies the Dispatcher for a reception of a SubmitRequest from a given sender on a given channel

type MembershipChanges added in v1.4.0

type MembershipChanges struct {
	AddedNodes   []*etcdraft.Consenter
	RemovedNodes []*etcdraft.Consenter
	TotalChanges uint32
}

MembershipChanges keeps information about membership changes introduced during configuration update

func ComputeMembershipChanges added in v1.4.0

func ComputeMembershipChanges(oldConsenters map[uint64]*etcdraft.Consenter, newConsenters []*etcdraft.Consenter) *MembershipChanges

ComputeMembershipChanges computes membership update based on information about new conseters, returns two slices: a slice of added consenters and a slice of consenters to be removed

func (*MembershipChanges) UpdateRaftMetadataAndConfChange added in v1.4.0

func (mc *MembershipChanges) UpdateRaftMetadataAndConfChange(raftMetadata *etcdraft.RaftMetadata) *raftpb.ConfChange

UpdateRaftMetadataAndConfChange given the membership changes and RaftMetadata method calculates updates to be applied to the raft cluster configuration in addition updates mapping between consenter and its id within metadata

type MemoryStorage added in v1.4.0

type MemoryStorage interface {
	raft.Storage
	Append(entries []raftpb.Entry) error
	SetHardState(st raftpb.HardState) error
	CreateSnapshot(i uint64, cs *raftpb.ConfState, data []byte) (raftpb.Snapshot, error)
	Compact(compactIndex uint64) error
	ApplySnapshot(snap raftpb.Snapshot) error
}

MemoryStorage is currently backed by etcd/raft.MemoryStorage. This interface is defined to expose dependencies of fsm so that it may be swapped in the future. TODO(jay) Add other necessary methods to this interface once we need them in implementation, e.g. ApplySnapshot.

type MessageReceiver

type MessageReceiver interface {
	// Step passes the given StepRequest message to the MessageReceiver
	Step(req *orderer.StepRequest, sender uint64) error

	// Submit passes the given SubmitRequest message to the MessageReceiver
	Submit(req *orderer.SubmitRequest, sender uint64) error
}

MessageReceiver receives messages

type Options

type Options struct {
	RaftID uint64

	Clock clock.Clock

	WALDir       string
	SnapDir      string
	SnapInterval uint64

	// This is configurable mainly for testing purpose. Users are not
	// expected to alter this. Instead, DefaultSnapshotCatchUpEntries is used.
	SnapshotCatchUpEntries uint64

	MemoryStorage MemoryStorage
	Logger        *flogging.FabricLogger

	TickInterval    time.Duration
	ElectionTick    int
	HeartbeatTick   int
	MaxSizePerMsg   uint64
	MaxInflightMsgs int

	RaftMetadata *etcdraft.RaftMetadata
}

Options contains all the configurations relevant to the chain.

type RPC added in v1.4.0

type RPC interface {
	Step(dest uint64, msg *orderer.StepRequest) (*orderer.StepResponse, error)
	SendSubmit(dest uint64, request *orderer.SubmitRequest) error
}

RPC is used to mock the transport layer in tests.

type RaftStorage added in v1.4.0

type RaftStorage struct {
	SnapshotCatchUpEntries uint64
	// contains filtered or unexported fields
}

RaftStorage encapsulates storages needed for etcd/raft data, i.e. memory, wal

func CreateStorage added in v1.4.0

func CreateStorage(
	lg *flogging.FabricLogger,
	applied uint64,
	walDir string,
	snapDir string,
	ram MemoryStorage,
) (*RaftStorage, error)

CreateStorage attempts to create a storage to persist etcd/raft data. If data presents in specified disk, they are loaded to reconstruct storage state.

func (*RaftStorage) ApplySnapshot added in v1.4.0

func (rs *RaftStorage) ApplySnapshot(snap raftpb.Snapshot)

ApplySnapshot applies snapshot to local memory storage

func (*RaftStorage) Close added in v1.4.0

func (rs *RaftStorage) Close() error

Close closes storage

func (*RaftStorage) Snapshot added in v1.4.0

func (rs *RaftStorage) Snapshot() raftpb.Snapshot

Snapshot returns the latest snapshot stored in memory

func (*RaftStorage) Store added in v1.4.0

func (rs *RaftStorage) Store(entries []raftpb.Entry, hardstate raftpb.HardState, snapshot raftpb.Snapshot) error

Store persists etcd/raft data

func (*RaftStorage) TakeSnapshot added in v1.4.0

func (rs *RaftStorage) TakeSnapshot(i uint64, cs *raftpb.ConfState, data []byte) error

TakeSnapshot takes a snapshot at index i from MemoryStorage, and persists it to wal and disk.

type ReceiverGetter

type ReceiverGetter interface {
	// ReceiverByChain returns the MessageReceiver if it exists, or nil if it doesn't
	ReceiverByChain(channelID string) MessageReceiver
}

ReceiverGetter obtains instances of MessageReceiver given a channel ID

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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