Documentation ¶
Overview ¶
Package gorums is a generated protocol buffer package.
It is generated from these files:
gorumspb/gorums.proto
It has these top-level messages:
Index ¶
- Constants
- Variables
- func Equal(a, b *Configuration) bool
- func ManagerCreationError(err error) error
- func RegisterRaftServer(s *grpc.Server, srv RaftServer)
- type CallGRPCError
- type ConfigNotFoundError
- type Configuration
- func (c *Configuration) AppendEntries(ctx context.Context, arg *raftpb.AppendEntriesRequest, ...) (*raftpb.AppendEntriesQFResponse, error)
- func (c *Configuration) ID() uint32
- func (c *Configuration) NodeIDs() []uint32
- func (c *Configuration) Nodes() []*Node
- func (c *Configuration) RequestVote(ctx context.Context, arg *raftpb.RequestVoteRequest) (*raftpb.RequestVoteResponse, error)
- func (c *Configuration) Size() int
- func (c *Configuration) String() string
- func (c *Configuration) SubError() <-chan CallGRPCError
- type IllegalConfigError
- type Manager
- func (m *Manager) AddNode(addr string) error
- func (m *Manager) Close()
- func (m *Manager) Configuration(id uint32) (config *Configuration, found bool)
- func (m *Manager) ConfigurationIDs() []uint32
- func (m *Manager) Configurations() []*Configuration
- func (m *Manager) NewConfiguration(ids []uint32, qspec QuorumSpec) (*Configuration, error)
- func (m *Manager) Node(id uint32) (node *Node, found bool)
- func (m *Manager) NodeIDs() []uint32
- func (m *Manager) Nodes() []*Node
- func (m *Manager) Size() (nodes, configs int)
- type ManagerOption
- type MultiSorter
- type Node
- type NodeNotFoundError
- type QuorumCallError
- type QuorumSpec
- type RaftClient
- type RaftServer
Constants ¶
const LevelNotSet = -1
LevelNotSet is the zero value level used to indicate that no level (and thereby no reply) has been set for a correctable quorum call.
Variables ¶
var Error = func(n1, n2 *Node) bool { if n1.lastErr != nil && n2.lastErr == nil { return false } return true }
Error sorts nodes by their LastErr() status in increasing order. A node with LastErr() != nil is larger than a node with LastErr() == nil.
var ID = func(n1, n2 *Node) bool {
return n1.id < n2.id
}
ID sorts nodes by their identifier in increasing order.
var Latency = func(n1, n2 *Node) bool { if n1.latency < 0 { return false } return n1.latency < n2.latency }
Latency sorts nodes by latency in increasing order. Latencies less then zero (sentinel value) are considered greater than any positive latency.
Functions ¶
func Equal ¶
func Equal(a, b *Configuration) bool
Equal returns a boolean reporting whether a and b represents the same configuration.
func ManagerCreationError ¶
ManagerCreationError returns an error reporting that a Manager could not be created due to err.
func RegisterRaftServer ¶
func RegisterRaftServer(s *grpc.Server, srv RaftServer)
Types ¶
type CallGRPCError ¶
CallGRPCError is used to report that a single gRPC call failed.
func (CallGRPCError) Error ¶
func (e CallGRPCError) Error() string
type ConfigNotFoundError ¶
type ConfigNotFoundError uint32
A ConfigNotFoundError reports that a specified configuration could not be found.
func (ConfigNotFoundError) Error ¶
func (e ConfigNotFoundError) Error() string
type Configuration ¶
type Configuration struct {
// contains filtered or unexported fields
}
A Configuration represents a static set of nodes on which quorum remote procedure calls may be invoked.
func (*Configuration) AppendEntries ¶
func (c *Configuration) AppendEntries(ctx context.Context, arg *raftpb.AppendEntriesRequest, perNode func(arg raftpb.AppendEntriesRequest, nodeID uint32) *raftpb.AppendEntriesRequest) (*raftpb.AppendEntriesQFResponse, error)
AppendEntries is invoked as a quorum call on each node in configuration c, with the argument returned by the provided perNode function and returns the result. The perNode function takes a request arg and returns a raftpb.AppendEntriesRequest object to be passed to the given nodeID. The perNode function should be thread-safe.
func (*Configuration) ID ¶
func (c *Configuration) ID() uint32
ID reports the identifier for the configuration.
func (*Configuration) NodeIDs ¶
func (c *Configuration) NodeIDs() []uint32
NodeIDs returns a slice containing the local ids of all the nodes in the configuration. IDs are returned in the same order as they were provided in the creation of the Configuration.
func (*Configuration) Nodes ¶
func (c *Configuration) Nodes() []*Node
Nodes returns a slice of each available node. IDs are returned in the same order as they were provided in the creation of the Configuration.
func (*Configuration) RequestVote ¶
func (c *Configuration) RequestVote(ctx context.Context, arg *raftpb.RequestVoteRequest) (*raftpb.RequestVoteResponse, error)
RequestVote is invoked as a quorum call on all nodes in configuration c, using the same argument arg, and returns the result.
func (*Configuration) Size ¶
func (c *Configuration) Size() int
Size returns the number of nodes in the configuration.
func (*Configuration) String ¶
func (c *Configuration) String() string
func (*Configuration) SubError ¶
func (c *Configuration) SubError() <-chan CallGRPCError
SubError returns a channel for listening to individual node errors. Currently only a single listener is supported.
type IllegalConfigError ¶
type IllegalConfigError string
An IllegalConfigError reports that a specified configuration could not be created.
func (IllegalConfigError) Error ¶
func (e IllegalConfigError) Error() string
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages a pool of node configurations on which quorum remote procedure calls can be made.
func NewManager ¶
func NewManager(nodeAddrs []string, opts ...ManagerOption) (*Manager, error)
NewManager attempts to connect to the given set of node addresses and if successful returns a new Manager containing connections to those nodes.
func (*Manager) AddNode ¶
AddNode attempts to dial to the provide node address. The node is added to the Manager's pool of nodes if a connection was established.
func (*Manager) Close ¶
func (m *Manager) Close()
Close closes all node connections and any client streams.
func (*Manager) Configuration ¶
func (m *Manager) Configuration(id uint32) (config *Configuration, found bool)
Configuration returns the configuration with the given global identifier if present.
func (*Manager) ConfigurationIDs ¶
ConfigurationIDs returns the identifier of each available configuration.
func (*Manager) Configurations ¶
func (m *Manager) Configurations() []*Configuration
Configurations returns a slice of each available configuration.
func (*Manager) NewConfiguration ¶
func (m *Manager) NewConfiguration(ids []uint32, qspec QuorumSpec) (*Configuration, error)
NewConfiguration returns a new configuration given quorum specification and a timeout.
func (*Manager) NodeIDs ¶
NodeIDs returns the identifier of each available node. IDs are returned in the same order as they were provided in the creation of the Manager.
type ManagerOption ¶
type ManagerOption func(*managerOptions)
ManagerOption provides a way to set different options on a new Manager.
func WithGrpcDialOptions ¶
func WithGrpcDialOptions(opts ...grpc.DialOption) ManagerOption
WithGrpcDialOptions returns a ManagerOption which sets any gRPC dial options the Manager should use when initially connecting to each node in its pool.
func WithLogger ¶
func WithLogger(logger *log.Logger) ManagerOption
WithLogger returns a ManagerOption which sets an optional error logger for the Manager.
func WithNoConnect ¶
func WithNoConnect() ManagerOption
WithNoConnect returns a ManagerOption which instructs the Manager not to connect to any of its nodes. Mainly used for testing purposes.
func WithTracing ¶
func WithTracing() ManagerOption
WithTracing controls whether to trace qourum calls for this Manager instance using the golang.org/x/net/trace package. Tracing is currently only supported for regular quorum calls.
type MultiSorter ¶
type MultiSorter struct {
// contains filtered or unexported fields
}
MultiSorter implements the Sort interface, sorting the nodes within.
func OrderedBy ¶
func OrderedBy(less ...lessFunc) *MultiSorter
OrderedBy returns a Sorter that sorts using the less functions, in order. Call its Sort method to sort the data.
func (*MultiSorter) Less ¶
func (ms *MultiSorter) Less(i, j int) bool
Less is part of sort.Interface. It is implemented by looping along the less functions until it finds a comparison that is either Less or !Less. Note that it can call the less functions twice per call. We could change the functions to return -1, 0, 1 and reduce the number of calls for greater efficiency: an exercise for the reader.
func (*MultiSorter) Sort ¶
func (ms *MultiSorter) Sort(nodes []*Node)
Sort sorts the argument slice according to the less functions passed to OrderedBy.
type Node ¶
type Node struct { RaftClient RaftClient // contains filtered or unexported fields }
Node encapsulates the state of a node on which a remote procedure call can be made.
func (*Node) LastErr ¶
LastErr returns the last error encountered (if any) when invoking a remote procedure call on this node.
type NodeNotFoundError ¶
type NodeNotFoundError uint32
A NodeNotFoundError reports that a specified node could not be found.
func (NodeNotFoundError) Error ¶
func (e NodeNotFoundError) Error() string
type QuorumCallError ¶
A QuorumCallError is used to report that a quorum call failed.
func (QuorumCallError) Error ¶
func (e QuorumCallError) Error() string
type QuorumSpec ¶
type QuorumSpec interface { // AppendEntriesQF is the quorum function for the AppendEntries // quorum call method. AppendEntriesQF(req *raftpb.AppendEntriesRequest, replies []*raftpb.AppendEntriesResponse) (*raftpb.AppendEntriesQFResponse, bool) // RequestVoteQF is the quorum function for the RequestVote // quorum call method. RequestVoteQF(req *raftpb.RequestVoteRequest, replies []*raftpb.RequestVoteResponse) (*raftpb.RequestVoteResponse, bool) }
QuorumSpec is the interface that wraps every quorum function.
type RaftClient ¶
type RaftClient interface { RequestVote(ctx context.Context, in *raftpb.RequestVoteRequest, opts ...grpc.CallOption) (*raftpb.RequestVoteResponse, error) AppendEntries(ctx context.Context, in *raftpb.AppendEntriesRequest, opts ...grpc.CallOption) (*raftpb.AppendEntriesResponse, error) InstallSnapshot(ctx context.Context, in *commonpb.Snapshot, opts ...grpc.CallOption) (*raftpb.InstallSnapshotResponse, error) CatchMeUp(ctx context.Context, in *raftpb.CatchMeUpRequest, opts ...grpc.CallOption) (*raftpb.Empty, error) }
func NewRaftClient ¶
func NewRaftClient(cc *grpc.ClientConn) RaftClient
type RaftServer ¶
type RaftServer interface { RequestVote(context.Context, *raftpb.RequestVoteRequest) (*raftpb.RequestVoteResponse, error) AppendEntries(context.Context, *raftpb.AppendEntriesRequest) (*raftpb.AppendEntriesResponse, error) InstallSnapshot(context.Context, *commonpb.Snapshot) (*raftpb.InstallSnapshotResponse, error) CatchMeUp(context.Context, *raftpb.CatchMeUpRequest) (*raftpb.Empty, error) }