consensus

package
v0.3.0-docs.0...-f96dd80 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2019 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Overview

	Package consensus is a generated protocol buffer package.

	It is generated from these files:
		cluster.proto

	It has these top-level messages:
		NodeInfo
		ClusterInfo
		RaftJoinRequest
		RaftJoinResponse
		FetchSnapshotRequest
		Chunk
		InfoResponse
		InfoRequest

   Copyright 2018-2019 Banco Bilbao Vizcaya Argentaria, S.A.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotLeader is raised when no a raft node tries to execute an operation
	// on a non-primary node.
	ErrNotLeader = errors.New("Not cluster leader")

	// ErrCannotJoin is raised when a node cannot join to any specified seed
	// (e.g. not leader).
	ErrCannotJoin = errors.New("Unable to join to the cluster")

	// ErrCannotSync is raised when a node cannot synchronize its cluster info.
	ErrCannotSync = errors.New("Unable to sync cluster info")
)
View Source
var (
	ErrInvalidLengthCluster = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowCluster   = fmt.Errorf("proto: integer overflow")
)
View Source
var (
	// ErrKeyNotFound is an error indicating a given key does not exist
	ErrKeyNotFound = errors.New("not found")
)

Functions

func NewCMuxTCPTransport

func NewCMuxTCPTransport(
	node *RaftNode,
	maxPool int,
	timeout time.Duration,
	logOutput io.Writer,
) (*raft.NetworkTransport, error)

NewCMuxTCPTransport returns a NetworkTransport that is built on top of a TCP streaming transport layer.

func NewCMuxTCPTransportWithConfig

func NewCMuxTCPTransportWithConfig(
	node *RaftNode,
	config *raft.NetworkTransportConfig,
) (*raft.NetworkTransport, error)

NewCMuxTCPTransportWithConfig returns a NetworkTransport that is built on top of a TCP streaming transport layer, using the given config struct.

func NewCMuxTCPTransportWithLogger

func NewCMuxTCPTransportWithLogger(
	node *RaftNode,
	maxPool int,
	timeout time.Duration,
	logger *log.Logger,
) (*raft.NetworkTransport, error)

NewCMuxTCPTransportWithLogger returns a NetworkTransport that is built on top of a TCP streaming transport layer, with log output going to the supplied Logger

func RegisterClusterServiceServer

func RegisterClusterServiceServer(s *grpc.Server, srv ClusterServiceServer)

Types

type Chunk

type Chunk struct {
	Content []byte `protobuf:"bytes,1,opt,name=Content,proto3" json:"Content,omitempty"`
}

func (*Chunk) Descriptor

func (*Chunk) Descriptor() ([]byte, []int)

func (*Chunk) GetContent

func (m *Chunk) GetContent() []byte

func (*Chunk) Marshal

func (m *Chunk) Marshal() (dAtA []byte, err error)

func (*Chunk) MarshalTo

func (m *Chunk) MarshalTo(dAtA []byte) (int, error)

func (*Chunk) ProtoMessage

func (*Chunk) ProtoMessage()

func (*Chunk) Reset

func (m *Chunk) Reset()

func (*Chunk) Size

func (m *Chunk) Size() (n int)

func (*Chunk) String

func (m *Chunk) String() string

func (*Chunk) Unmarshal

func (m *Chunk) Unmarshal(dAtA []byte) error

type ClusterInfo

type ClusterInfo struct {
	LeaderId string               `protobuf:"bytes,1,opt,name=leader_id,json=leaderId,proto3" json:"leader_id,omitempty"`
	Nodes    map[string]*NodeInfo `` /* 137-byte string literal not displayed */
}

func (*ClusterInfo) Descriptor

func (*ClusterInfo) Descriptor() ([]byte, []int)

func (*ClusterInfo) GetLeaderId

func (m *ClusterInfo) GetLeaderId() string

func (*ClusterInfo) GetNodes

func (m *ClusterInfo) GetNodes() map[string]*NodeInfo

func (*ClusterInfo) Marshal

func (m *ClusterInfo) Marshal() (dAtA []byte, err error)

func (*ClusterInfo) MarshalTo

func (m *ClusterInfo) MarshalTo(dAtA []byte) (int, error)

func (*ClusterInfo) ProtoMessage

func (*ClusterInfo) ProtoMessage()

func (*ClusterInfo) Reset

func (m *ClusterInfo) Reset()

func (*ClusterInfo) Size

func (m *ClusterInfo) Size() (n int)

func (*ClusterInfo) String

func (m *ClusterInfo) String() string

func (*ClusterInfo) Unmarshal

func (m *ClusterInfo) Unmarshal(dAtA []byte) error

type ClusterServiceClient

type ClusterServiceClient interface {
	JoinCluster(ctx context.Context, in *RaftJoinRequest, opts ...grpc.CallOption) (*RaftJoinResponse, error)
	FetchSnapshot(ctx context.Context, in *FetchSnapshotRequest, opts ...grpc.CallOption) (ClusterService_FetchSnapshotClient, error)
	FetchNodeInfo(ctx context.Context, in *InfoRequest, opts ...grpc.CallOption) (*InfoResponse, error)
}

func NewClusterServiceClient

func NewClusterServiceClient(cc *grpc.ClientConn) ClusterServiceClient

type ClusterServiceServer

type ClusterServiceServer interface {
	JoinCluster(context.Context, *RaftJoinRequest) (*RaftJoinResponse, error)
	FetchSnapshot(*FetchSnapshotRequest, ClusterService_FetchSnapshotServer) error
	FetchNodeInfo(context.Context, *InfoRequest) (*InfoResponse, error)
}

type ClusterService_FetchSnapshotClient

type ClusterService_FetchSnapshotClient interface {
	Recv() (*Chunk, error)
	grpc.ClientStream
}

type ClusterService_FetchSnapshotServer

type ClusterService_FetchSnapshotServer interface {
	Send(*Chunk) error
	grpc.ServerStream
}

type ClusteringOptions

type ClusteringOptions struct {
	NodeID            string   // ID of the node within the cluster.
	Addr              string   // IP address where to listen for Raft commands.
	MgmtAddr          string   // IP address where to listen for management operations.
	HttpAddr          string   // IP address where clients can connect (this is used to populate node info)
	Bootstrap         bool     // Bootstrap the cluster as a seed node if there is no existing state.
	Seeds             []string // List of cluster peer node IDs to bootstrap the cluster state.
	RaftLogPath       string   // Path to Raft log store directory.
	LogCacheSize      int      // Number of Raft log entries to cache in memory to reduce disk IO.
	LogSnapshots      int      // Number of Raft log snapshots to retain.
	SnapshotThreshold uint64   // Controls how many outstanding logs there must be before we perform a snapshot.
	TrailingLogs      uint64   // Number of logs left after a snapshot.
	Sync              bool     // Do a file sync after every write to the Raft log and stable store.
	RaftLogging       bool     // Enable logging of Raft library (disabled by default since really verbose).

	// These will be set to some sane defaults. Change only if experiencing raft issues.
	RaftHeartbeatTimeout time.Duration
	RaftElectionTimeout  time.Duration
	RaftLeaseTimeout     time.Duration
	RaftCommitTimeout    time.Duration
	RaftApplyTimeout     time.Duration // Amount of time we wait for the command to be started.
}

ClusteringOptions contains node options related to clustering.

func DefaultClusteringOptions

func DefaultClusteringOptions() *ClusteringOptions

type FetchSnapshotRequest

type FetchSnapshotRequest struct {
	StartSeqNum uint64 `protobuf:"varint,1,opt,name=startSeqNum,proto3" json:"startSeqNum,omitempty"`
	EndSeqNum   uint64 `protobuf:"varint,2,opt,name=endSeqNum,proto3" json:"endSeqNum,omitempty"`
}

func (*FetchSnapshotRequest) Descriptor

func (*FetchSnapshotRequest) Descriptor() ([]byte, []int)

func (*FetchSnapshotRequest) GetEndSeqNum

func (m *FetchSnapshotRequest) GetEndSeqNum() uint64

func (*FetchSnapshotRequest) GetStartSeqNum

func (m *FetchSnapshotRequest) GetStartSeqNum() uint64

func (*FetchSnapshotRequest) Marshal

func (m *FetchSnapshotRequest) Marshal() (dAtA []byte, err error)

func (*FetchSnapshotRequest) MarshalTo

func (m *FetchSnapshotRequest) MarshalTo(dAtA []byte) (int, error)

func (*FetchSnapshotRequest) ProtoMessage

func (*FetchSnapshotRequest) ProtoMessage()

func (*FetchSnapshotRequest) Reset

func (m *FetchSnapshotRequest) Reset()

func (*FetchSnapshotRequest) Size

func (m *FetchSnapshotRequest) Size() (n int)

func (*FetchSnapshotRequest) String

func (m *FetchSnapshotRequest) String() string

func (*FetchSnapshotRequest) Unmarshal

func (m *FetchSnapshotRequest) Unmarshal(dAtA []byte) error

type InfoRequest

type InfoRequest struct {
}

func (*InfoRequest) Descriptor

func (*InfoRequest) Descriptor() ([]byte, []int)

func (*InfoRequest) Marshal

func (m *InfoRequest) Marshal() (dAtA []byte, err error)

func (*InfoRequest) MarshalTo

func (m *InfoRequest) MarshalTo(dAtA []byte) (int, error)

func (*InfoRequest) ProtoMessage

func (*InfoRequest) ProtoMessage()

func (*InfoRequest) Reset

func (m *InfoRequest) Reset()

func (*InfoRequest) Size

func (m *InfoRequest) Size() (n int)

func (*InfoRequest) String

func (m *InfoRequest) String() string

func (*InfoRequest) Unmarshal

func (m *InfoRequest) Unmarshal(dAtA []byte) error

type InfoResponse

type InfoResponse struct {
	NodeInfo *NodeInfo `protobuf:"bytes,1,opt,name=node_info,json=nodeInfo" json:"node_info,omitempty"`
}

func (*InfoResponse) Descriptor

func (*InfoResponse) Descriptor() ([]byte, []int)

func (*InfoResponse) GetNodeInfo

func (m *InfoResponse) GetNodeInfo() *NodeInfo

func (*InfoResponse) Marshal

func (m *InfoResponse) Marshal() (dAtA []byte, err error)

func (*InfoResponse) MarshalTo

func (m *InfoResponse) MarshalTo(dAtA []byte) (int, error)

func (*InfoResponse) ProtoMessage

func (*InfoResponse) ProtoMessage()

func (*InfoResponse) Reset

func (m *InfoResponse) Reset()

func (*InfoResponse) Size

func (m *InfoResponse) Size() (n int)

func (*InfoResponse) String

func (m *InfoResponse) String() string

func (*InfoResponse) Unmarshal

func (m *InfoResponse) Unmarshal(dAtA []byte) error

type NodeInfo

type NodeInfo struct {
	NodeId      string `protobuf:"bytes,1,opt,name=node_id,json=nodeId,proto3" json:"node_id,omitempty"`
	RaftAddr    string `protobuf:"bytes,2,opt,name=raft_addr,json=raftAddr,proto3" json:"raft_addr,omitempty"`
	MgmtAddr    string `protobuf:"bytes,3,opt,name=mgmt_addr,json=mgmtAddr,proto3" json:"mgmt_addr,omitempty"`
	HttpAddr    string `protobuf:"bytes,4,opt,name=http_addr,json=httpAddr,proto3" json:"http_addr,omitempty"`
	MetricsAddr string `protobuf:"bytes,5,opt,name=metrics_addr,json=metricsAddr,proto3" json:"metrics_addr,omitempty"`
}

func (*NodeInfo) Descriptor

func (*NodeInfo) Descriptor() ([]byte, []int)

func (*NodeInfo) GetHttpAddr

func (m *NodeInfo) GetHttpAddr() string

func (*NodeInfo) GetMetricsAddr

func (m *NodeInfo) GetMetricsAddr() string

func (*NodeInfo) GetMgmtAddr

func (m *NodeInfo) GetMgmtAddr() string

func (*NodeInfo) GetNodeId

func (m *NodeInfo) GetNodeId() string

func (*NodeInfo) GetRaftAddr

func (m *NodeInfo) GetRaftAddr() string

func (*NodeInfo) Marshal

func (m *NodeInfo) Marshal() (dAtA []byte, err error)

func (*NodeInfo) MarshalTo

func (m *NodeInfo) MarshalTo(dAtA []byte) (int, error)

func (*NodeInfo) ProtoMessage

func (*NodeInfo) ProtoMessage()

func (*NodeInfo) Reset

func (m *NodeInfo) Reset()

func (*NodeInfo) Size

func (m *NodeInfo) Size() (n int)

func (*NodeInfo) String

func (m *NodeInfo) String() string

func (*NodeInfo) Unmarshal

func (m *NodeInfo) Unmarshal(dAtA []byte) error

type RaftJoinRequest

type RaftJoinRequest struct {
	NodeId   string `protobuf:"bytes,1,opt,name=node_id,json=nodeId,proto3" json:"node_id,omitempty"`
	RaftAddr string `protobuf:"bytes,2,opt,name=raft_addr,json=raftAddr,proto3" json:"raft_addr,omitempty"`
}

func (*RaftJoinRequest) Descriptor

func (*RaftJoinRequest) Descriptor() ([]byte, []int)

func (*RaftJoinRequest) GetNodeId

func (m *RaftJoinRequest) GetNodeId() string

func (*RaftJoinRequest) GetRaftAddr

func (m *RaftJoinRequest) GetRaftAddr() string

func (*RaftJoinRequest) Marshal

func (m *RaftJoinRequest) Marshal() (dAtA []byte, err error)

func (*RaftJoinRequest) MarshalTo

func (m *RaftJoinRequest) MarshalTo(dAtA []byte) (int, error)

func (*RaftJoinRequest) ProtoMessage

func (*RaftJoinRequest) ProtoMessage()

func (*RaftJoinRequest) Reset

func (m *RaftJoinRequest) Reset()

func (*RaftJoinRequest) Size

func (m *RaftJoinRequest) Size() (n int)

func (*RaftJoinRequest) String

func (m *RaftJoinRequest) String() string

func (*RaftJoinRequest) Unmarshal

func (m *RaftJoinRequest) Unmarshal(dAtA []byte) error

type RaftJoinResponse

type RaftJoinResponse struct {
}

func (*RaftJoinResponse) Descriptor

func (*RaftJoinResponse) Descriptor() ([]byte, []int)

func (*RaftJoinResponse) Marshal

func (m *RaftJoinResponse) Marshal() (dAtA []byte, err error)

func (*RaftJoinResponse) MarshalTo

func (m *RaftJoinResponse) MarshalTo(dAtA []byte) (int, error)

func (*RaftJoinResponse) ProtoMessage

func (*RaftJoinResponse) ProtoMessage()

func (*RaftJoinResponse) Reset

func (m *RaftJoinResponse) Reset()

func (*RaftJoinResponse) Size

func (m *RaftJoinResponse) Size() (n int)

func (*RaftJoinResponse) String

func (m *RaftJoinResponse) String() string

func (*RaftJoinResponse) Unmarshal

func (m *RaftJoinResponse) Unmarshal(dAtA []byte) error

type RaftNode

type RaftNode struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewRaftNode

func NewRaftNode(opts *ClusteringOptions, store storage.ManagedStore, snapshotsCh chan *protocol.Snapshot) (*RaftNode, error)

func (*RaftNode) Add

func (n *RaftNode) Add(event []byte) (*balloon.Snapshot, error)

Add function applies an add operation into a Raft balloon. As a result, it returns a shapshot, but previously it sends the snapshot to the agents channel, in order to be published/queried.

func (*RaftNode) AddBulk

func (n *RaftNode) AddBulk(bulk [][]byte) ([]*balloon.Snapshot, error)

AddBulk function applies an add bulk operation into a Raft balloon. As a result, it returns a bulk of shapshots, but previously it sends each snapshot of the bulk to the agents channel, in order to be published/queried.

func (*RaftNode) Apply

func (n *RaftNode) Apply(l *raft.Log) interface{}

Apply applies a Raft log entry to the database.

func (*RaftNode) Close

func (n *RaftNode) Close(wait bool) error

Close closes the RaftNode. If wait is true, waits for a graceful shutdown. Once closed, a RaftNode may not be re-opened.

func (*RaftNode) ClusterInfo

func (n *RaftNode) ClusterInfo() *ClusterInfo

ClusterInfo function returns Raft current node info plus certain raft cluster info. Used in /info/shard.

func (*RaftNode) CreateBackup

func (n *RaftNode) CreateBackup() error

Backup function calls store's backup function, passing certain metadata. Previously, it gets balloon version to build this metadata.

func (*RaftNode) DeleteBackup

func (n *RaftNode) DeleteBackup(backupID uint32) error

DeleteBackup function is a passthough to store's equivalent funcion.

func (*RaftNode) FetchNodeInfo

func (n *RaftNode) FetchNodeInfo(ctx context.Context, req *InfoRequest) (*InfoResponse, error)

func (*RaftNode) FetchSnapshot

func (*RaftNode) Info

func (n *RaftNode) Info() *NodeInfo

Info function returns Raft current node info.

func (*RaftNode) IsLeader

func (n *RaftNode) IsLeader() bool

func (*RaftNode) JoinCluster

func (n *RaftNode) JoinCluster(ctx context.Context, req *RaftJoinRequest) (*RaftJoinResponse, error)

JoinCluster joins a node, identified by id and located at addr, to this store. The node must be ready to respond to Raft communications at that address. This must be called from the Leader or it will fail.

func (*RaftNode) ListBackups

func (n *RaftNode) ListBackups() []*storage.BackupInfo

BackupsInfo function is a passthough to store's equivalent funcion.

func (*RaftNode) QueryConsistency

func (n *RaftNode) QueryConsistency(start, end uint64) (*balloon.IncrementalProof, error)

QueryConsistency acts as a passthrough when requesting an incremental proof.

func (*RaftNode) QueryDigestMembership

func (n *RaftNode) QueryDigestMembership(keyDigest hashing.Digest) (*balloon.MembershipProof, error)

QueryDigestMembership acts as a passthrough when an event digest is given to request a membership proof against the last balloon version.

func (*RaftNode) QueryDigestMembershipConsistency

func (n *RaftNode) QueryDigestMembershipConsistency(keyDigest hashing.Digest, version uint64) (*balloon.MembershipProof, error)

QueryDigestMembershipConsistency acts as a passthrough when an event digest is given to request a membership proof against a certain balloon version.

func (*RaftNode) QueryMembership

func (n *RaftNode) QueryMembership(event []byte) (*balloon.MembershipProof, error)

QueryMembership acts as a passthrough when an event is given to request a membership proof against the last balloon version.

func (*RaftNode) QueryMembershipConsistency

func (n *RaftNode) QueryMembershipConsistency(event []byte, version uint64) (*balloon.MembershipProof, error)

QueryMembershipConsistency acts as a passthrough when an event is given to request a membership proof against a certain balloon version.

func (*RaftNode) RegisterMetrics

func (n *RaftNode) RegisterMetrics(registry metrics.Registry)

RegisterMetrics register raft metrics: prometheus collectors and raftLog metrics.

func (*RaftNode) Restore

func (n *RaftNode) Restore(rc io.ReadCloser) error

Restore restores the node to a previous state.

func (*RaftNode) Snapshot

func (n *RaftNode) Snapshot() (raft.FSMSnapshot, error)

Snapshot returns a snapshot of the key-value store. The caller must ensure that no Raft transaction is taking place during this call. Hashicorp Raft guarantees that this function will not be called concurrently with Apply.

func (*RaftNode) StoreConfiguration

func (n *RaftNode) StoreConfiguration(index uint64, config raft.Configuration)

StoreConfiguration is invoked once a log entry containing a configuration change is committed. It takes the index at which the configuration was written and the configuration value.

func (*RaftNode) WaitForLeader

func (n *RaftNode) WaitForLeader(timeout time.Duration) error

WaitForLeader waits until the node becomes leader or time is out.

type TCPStreamLayer

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

TCPStreamLayer implements StreamLayer interface for plain TCP.

func (*TCPStreamLayer) Accept

func (t *TCPStreamLayer) Accept() (c net.Conn, err error)

Accept implements the net.Listener interface.

func (*TCPStreamLayer) Addr

func (t *TCPStreamLayer) Addr() net.Addr

Addr implements the net.Listener interface.

func (*TCPStreamLayer) Close

func (t *TCPStreamLayer) Close() (err error)

Close implements the net.Listener interface.

func (*TCPStreamLayer) Dial

func (t *TCPStreamLayer) Dial(address raft.ServerAddress, timeout time.Duration) (net.Conn, error)

Dial implements the StreamLayer interface.

type VersionMetadata

type VersionMetadata struct {
	PreviousVersion uint64
	NewVersion      uint64
}

Jump to

Keyboard shortcuts

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