Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoKey = errors.New("no key in context")
ErrNoKey is returned when a key is missing.
var ErrSelfRouting = errors.New("route to self")
Functions ¶
func ExtractClientKey ¶
ExtractClientKey will extract the client key from ctx. Returns ErrNoKey when no key was found.
func WithClientKey ¶
WithClientKey injects the ID into the context to be used for request routing.
Types ¶
type Application ¶
type Application interface { // PeersChanged is invoked when the set of peers changes. PeersChanged(ps []Peer) }
Application represents the application using the cluster. Methods will be invoked by the node depending on the state of the cluster.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a transparent gRPC client interface to the cluster. If a request context is missing a key from WithClientKey, requests will fail with InvalidArgument.
func NewClient ¶
func NewClient(n *Node, opts ...ClientOption) *Client
NewClient creates a new server Client using the node for routing. If allowSelfRouting is false, requests will fail with ErrSelfRouting if a node would connect to itself.
func (*Client) Invoke ¶
func (c *Client) Invoke(ctx context.Context, method string, args interface{}, reply interface{}, opts ...grpc.CallOption) error
Invoke makes a request against the cluster, routing the request to the appropriate node. ctx must have a ClientKey set (via WithClientKey) or the request will fail.
func (*Client) NewStream ¶
func (c *Client) NewStream(ctx context.Context, desc *grpc.StreamDesc, method string, opts ...grpc.CallOption) (grpc.ClientStream, error)
NewStream makes a request against the cluster, routing the request to the appropriate node. ctx must have a ClientKey set (via WithClientKey) or the request will fail.
type ClientOption ¶
type ClientOption func(c *Client)
ClientOption modifies a Client.
func WithAllowSelfRouting ¶
func WithAllowSelfRouting(allow bool) ClientOption
WithAllowSelfRouting enables routing to self. Default is true.
func WithForwardHook ¶
func WithForwardHook(hook func(Peer) (Peer, error)) ClientOption
WithForwardHook allows to hook into the forwarding functionality. Hooks may change the address of where data is sent or modify the message prior to sending.
type Config ¶
type Config struct { // ID represents the server. Must be specified. ID id.ID // BroadcastAddr is the address to share with peers when joining. // Must bet set. BroadcastAddr string // Number of leaves to track. Will be divisible by 2. Defaults to 8 if // unset. NumLeaves int // Number of neighbors to track for locality. Defaults to 8 if unset. NumNeighbors int // Log will be used for logging messages. Log log.Logger }
Config controls how a node is initialized.
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node is a node within a Croissant cluster.
func New ¶
func New(cfg Config, app Application, dial ...grpc.DialOption) (*Node, error)
New creates a new Node and registers it against the given gRPC server. The provided set of DialOptions are used when communicating with a cluster peer.
func (*Node) Join ¶
Join joins the cluster. Calling this more than once will attempt to re-join the cluster.
func (*Node) NextPeer ¶
NextPeer returns the next peer in the routing chain for a given key. self will be true if next is the node itself.
This allows applications to implement special routing methods; e.g., batch routing.
func (*Node) Register ¶
func (n *Node) Register(s grpc.ServiceRegistrar)
Register registers the cluster API to gRPC. Must be called before Join, otherwise other nodes will be unable to connect to this node.
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router supplies a set of gRPC server interceptors that can route requests through the cluster. A Node must be set with SetNode for the Router to work. set with SetNode
func (*Router) Stream ¶
func (r *Router) Stream() grpc.StreamServerInterceptor
Stream returns grpc.StreamServerInterceptor.
func (*Router) Unary ¶
func (r *Router) Unary() grpc.UnaryServerInterceptor
Unary returns a grpc.UnaryServerInterceptor.