client

package
v0.0.2-alpha Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2021 License: MIT Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
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.

View Source
var File_client_client_proto protoreflect.FileDescriptor
View Source
var ID = func(n1, n2 *Node) bool {
	return n1.id < n2.id
}

ID sorts nodes by their identifier in increasing order.

View Source
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.

View Source
var Port = func(n1, n2 *Node) bool {
	p1, _ := strconv.Atoi(n1.Port())
	p2, _ := strconv.Atoi(n2.Port())
	return p1 < p2
}

Port sorts nodes by their port number in increasing order. Warning: This function may be removed in the future.

Functions

func Equal

func Equal(a, b *Configuration) bool

Equal returns a boolean reporting whether a and b represents the same configuration.

func ManagerCreationError

func ManagerCreationError(err error) error

ManagerCreationError returns an error reporting that a Manager could not be created due to err.

Types

type BenchmarkData

type BenchmarkData struct {
	MeasuredThroughput float64         `protobuf:"fixed64,1,opt,name=MeasuredThroughput,proto3" json:"MeasuredThroughput,omitempty"` // ops/sec
	MeasuredLatency    float64         `protobuf:"fixed64,2,opt,name=MeasuredLatency,proto3" json:"MeasuredLatency,omitempty"`       // ms
	LatencyVariance    float64         `protobuf:"fixed64,3,opt,name=LatencyVariance,proto3" json:"LatencyVariance,omitempty"`       // ms^2
	Stats              []*CommandStats `protobuf:"bytes,4,rep,name=Stats,proto3" json:"Stats,omitempty"`
	// contains filtered or unexported fields
}

BenchmarkData contains the throughput (in ops/sec) and latency (in ms) as measured by the client, as well as the time and duration information for each command.

func (*BenchmarkData) Descriptor deprecated

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

Deprecated: Use BenchmarkData.ProtoReflect.Descriptor instead.

func (*BenchmarkData) GetLatencyVariance

func (x *BenchmarkData) GetLatencyVariance() float64

func (*BenchmarkData) GetMeasuredLatency

func (x *BenchmarkData) GetMeasuredLatency() float64

func (*BenchmarkData) GetMeasuredThroughput

func (x *BenchmarkData) GetMeasuredThroughput() float64

func (*BenchmarkData) GetStats

func (x *BenchmarkData) GetStats() []*CommandStats

func (*BenchmarkData) ProtoMessage

func (*BenchmarkData) ProtoMessage()

func (*BenchmarkData) ProtoReflect

func (x *BenchmarkData) ProtoReflect() protoreflect.Message

func (*BenchmarkData) Reset

func (x *BenchmarkData) Reset()

func (*BenchmarkData) String

func (x *BenchmarkData) String() string

type Client

type Client interface {
	ExecCommand(context.Context, *Command, func(*Empty, error))
}

Client is the server-side API for the Client Service

type Command

type Command struct {
	ClientID       uint32 `protobuf:"varint,1,opt,name=ClientID,proto3" json:"ClientID,omitempty"`
	SequenceNumber uint64 `protobuf:"varint,2,opt,name=SequenceNumber,proto3" json:"SequenceNumber,omitempty"`
	Data           []byte `protobuf:"bytes,3,opt,name=Data,proto3" json:"Data,omitempty"`
	// contains filtered or unexported fields
}

Command is the request that is sent to the HotStuff replicas with the data to be executed.

func (*Command) Descriptor deprecated

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

Deprecated: Use Command.ProtoReflect.Descriptor instead.

func (*Command) GetClientID

func (x *Command) GetClientID() uint32

func (*Command) GetData

func (x *Command) GetData() []byte

func (*Command) GetSequenceNumber

func (x *Command) GetSequenceNumber() uint64

func (*Command) ProtoMessage

func (*Command) ProtoMessage()

func (*Command) ProtoReflect

func (x *Command) ProtoReflect() protoreflect.Message

func (*Command) Reset

func (x *Command) Reset()

func (*Command) String

func (x *Command) String() string

type CommandStats

type CommandStats struct {
	StartTime *timestamp.Timestamp `protobuf:"bytes,1,opt,name=StartTime,proto3" json:"StartTime,omitempty"`
	Duration  *duration.Duration   `protobuf:"bytes,2,opt,name=Duration,proto3" json:"Duration,omitempty"`
	// contains filtered or unexported fields
}

CommandStats contains the start time and duration that elapsed before a command was executed.

func (*CommandStats) Descriptor deprecated

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

Deprecated: Use CommandStats.ProtoReflect.Descriptor instead.

func (*CommandStats) GetDuration

func (x *CommandStats) GetDuration() *duration.Duration

func (*CommandStats) GetStartTime

func (x *CommandStats) GetStartTime() *timestamp.Timestamp

func (*CommandStats) ProtoMessage

func (*CommandStats) ProtoMessage()

func (*CommandStats) ProtoReflect

func (x *CommandStats) ProtoReflect() protoreflect.Message

func (*CommandStats) Reset

func (x *CommandStats) Reset()

func (*CommandStats) String

func (x *CommandStats) String() 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 NewConfig

func NewConfig(qspec QuorumSpec, opts ...ManagerOption) (*Configuration, func(), error)

NewConfig returns a configuration for the given node addresses and quorum spec. The returned func() must be called to close the underlying connections. This is an experimental API.

func (*Configuration) ExecCommand

func (c *Configuration) ExecCommand(ctx context.Context, in *Command) *FutureEmpty

ExecCommand sends a command to all replicas and waits for valid signatures from f+1 replicas

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) 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 GRPCError

SubError returns a channel for listening to individual node errors. Currently only a single listener is supported.

type Empty

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

func (*Empty) Descriptor deprecated

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

Deprecated: Use Empty.ProtoReflect.Descriptor instead.

func (*Empty) ProtoMessage

func (*Empty) ProtoMessage()

func (*Empty) ProtoReflect

func (x *Empty) ProtoReflect() protoreflect.Message

func (*Empty) Reset

func (x *Empty) Reset()

func (*Empty) String

func (x *Empty) String() string

type FutureEmpty

type FutureEmpty struct {
	// the actual reply
	*Empty
	NodeIDs []uint32
	// contains filtered or unexported fields
}

FutureEmpty is a future object for processing replies.

func (*FutureEmpty) Done

func (f *FutureEmpty) Done() bool

Done reports if a reply and/or error is available for the called method.

func (*FutureEmpty) Get

func (f *FutureEmpty) Get() (*Empty, error)

Get returns the reply and any error associated with the called method. The method blocks until a reply or error is available.

type GRPCError

type GRPCError struct {
	NodeID uint32
	Cause  error
}

GRPCError is used to report that a single gRPC call failed.

func (GRPCError) Error

func (e GRPCError) Error() string

type GorumsServer

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

GorumsServer serves all ordering based RPCs using registered handlers.

func NewGorumsServer

func NewGorumsServer(opts ...ServerOption) *GorumsServer

NewGorumsServer returns a new instance of GorumsServer.

func (*GorumsServer) GracefulStop

func (s *GorumsServer) GracefulStop()

GracefulStop waits for all RPCs to finish before stopping.

func (*GorumsServer) RegisterClientServer

func (s *GorumsServer) RegisterClientServer(srv Client)

func (*GorumsServer) Serve

func (s *GorumsServer) Serve(listener net.Listener) error

Serve starts serving on the listener.

func (*GorumsServer) Stop

func (s *GorumsServer) Stop()

Stop stops the server immediately.

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(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

func (m *Manager) AddNode(addr string) error

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

func (m *Manager) ConfigurationIDs() []uint32

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) Node

func (m *Manager) Node(id uint32) (node *Node, found bool)

Node returns the node with the given identifier if present.

func (*Manager) NodeIDs

func (m *Manager) NodeIDs() []uint32

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.

func (*Manager) Nodes

func (m *Manager) 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 Manager.

func (*Manager) Size

func (m *Manager) Size() (nodes, configs int)

Size returns the number of nodes and configurations in the Manager.

type ManagerOption

type ManagerOption func(*managerOptions)

ManagerOption provides a way to set different options on a new Manager.

func WithBackoff

func WithBackoff(backoff backoff.Config) ManagerOption

WithBackoff allows for changing the backoff delays used by Gorums.

func WithDialTimeout

func WithDialTimeout(timeout time.Duration) ManagerOption

WithDialTimeout returns a ManagerOption which is used to set the dial context timeout to be used when initially connecting to each node in its pool.

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 WithMetadata

func WithMetadata(md metadata.MD) ManagerOption

WithMetadata returns a ManagerOption that sets the metadata that is sent to each node when the connection is initially established. This metadata can be retrieved from the server-side method handlers.

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 WithNodeList

func WithNodeList(addrsList []string) ManagerOption

WithNodeList returns a ManagerOption containing the provided list of node addresses. With this option, NodeIDs are generated by the Manager.

func WithNodeMap

func WithNodeMap(idMap map[string]uint32) ManagerOption

WithNodeMap returns a ManagerOption containing the provided mapping from node addresses to application-specific IDs.

func WithPerNodeMetadata

func WithPerNodeMetadata(f func(uint32) metadata.MD) ManagerOption

WithPerNodeMetadata returns a ManagerOption that allows you to set metadata for each node individually.

func WithSendBufferSize

func WithSendBufferSize(size uint) ManagerOption

WithSendBufferSize allows for changing the size of the send buffer used by Gorums. A larger buffer might achieve higher throughput for asynchronous calltypes, but at the cost of latency.

func WithTracing

func WithTracing() ManagerOption

WithTracing controls whether to trace quorum 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) Len

func (ms *MultiSorter) Len() int

Len is part of sort.Interface.

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.

func (*MultiSorter) Swap

func (ms *MultiSorter) Swap(i, j int)

Swap is part of sort.Interface.

type Node

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

Node encapsulates the state of a node on which a remote procedure call can be performed.

func (*Node) Address

func (n *Node) Address() string

Address returns network address of n.

func (*Node) FullString

func (n *Node) FullString() string

FullString returns a more descriptive string representation of n that includes id, network address and latency information.

func (*Node) ID

func (n *Node) ID() uint32

ID returns the ID of n.

func (*Node) LastErr

func (n *Node) LastErr() error

LastErr returns the last error encountered (if any) when invoking a remote procedure call on this node.

func (*Node) Latency

func (n *Node) Latency() time.Duration

Latency returns the latency of the last successful remote procedure call made to this node.

func (*Node) Port

func (n *Node) Port() string

Port returns network port of n.

func (*Node) String

func (n *Node) String() string

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

type QuorumCallError struct {
	Reason     string
	ReplyCount int
	Errors     []GRPCError
}

A QuorumCallError is used to report that a quorum call failed.

func (QuorumCallError) Error

func (e QuorumCallError) Error() string

type QuorumSpec

type QuorumSpec interface {

	// ExecCommandQF is the quorum function for the ExecCommand
	// asynchronous ordered quorum call method. The in parameter is the request object
	// supplied to the ExecCommand method at call time, and may or may not
	// be used by the quorum function. If the in parameter is not needed
	// you should implement your quorum function with '_ *Command'.
	ExecCommandQF(in *Command, replies map[uint32]*Empty) (*Empty, bool)
}

QuorumSpec is the interface of quorum functions for Client.

type ServerOption

type ServerOption func(*serverOptions)

ServerOption is used to change settings for the GorumsServer

func WithGRPCServerOptions

func WithGRPCServerOptions(opts ...grpc.ServerOption) ServerOption

WithGRPCServerOptions allows to set gRPC options for the server.

func WithServerBufferSize

func WithServerBufferSize(size uint) ServerOption

WithServerBufferSize sets the buffer size for the server. A larger buffer may result in higher throughput at the cost of higher latency.

Jump to

Keyboard shortcuts

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