node

package
v0.1.0-alpha4 Latest Latest
Warning

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

Go to latest
Published: May 4, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package node provides all functionality within arrebato regarding nodes. This includes the gRPC service implementation.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoNode = errors.New("no node")

ErrNoNode is the error given when querying a node that does not exist, or when querying a topic's owner and none is found.

View Source
var ErrNodeExists = errors.New("node exists")

ErrNodeExists is the error given when attempting to create a node that already exists in the store.

Functions

This section is empty.

Types

type BoltStore

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

The BoltStore type is responsible for managing node state within a boltdb database.

func NewBoltStore

func NewBoltStore(db *bbolt.DB) *BoltStore

NewBoltStore returns a new instance of the BoltStore type that will store node state within the bbolt.DB instance.

func (*BoltStore) AssignTopic

func (bs *BoltStore) AssignTopic(ctx context.Context, nodeName string, topicName string) error

AssignTopic adds the provided topic name to a node's list of topics. It also checks other node records and removes the topic from their list if present.

func (*BoltStore) Create

func (bs *BoltStore) Create(ctx context.Context, n *node.Node) error

Create a record for the node. Returns ErrNodeExists if a record already exists for the given node.

func (*BoltStore) Delete

func (bs *BoltStore) Delete(ctx context.Context, name string) error

Delete the record of a named node. If the node does not exist, nothing happens and a nil error is returned.

func (*BoltStore) GetTopicOwner

func (bs *BoltStore) GetTopicOwner(ctx context.Context, topicName string) (*node.Node, error)

GetTopicOwner returns the node that is assigned to the provided topic. Returns ErrNoNode if a node cannot be found that owns the topic.

func (*BoltStore) List

func (bs *BoltStore) List(ctx context.Context) ([]*node.Node, error)

List all nodes in the store.

type GRPC

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

The GRPC type is a nodesvc.NodeServiceServer implementation that handles inbound gRPC requests to get information on the node.

func NewGRPC

func NewGRPC(raft Raft, info Info, backup io.WriterTo, nodes Lister) *GRPC

NewGRPC returns a new instance of the GRPC type that returns node information based on the Raft state.

func (*GRPC) Backup

Backup the server state, writing it to the outbound stream.

func (*GRPC) Describe

Describe the node.

func (*GRPC) Register

func (svr *GRPC) Register(registrar grpc.ServiceRegistrar, health *health.Server)

Register the GRPC service onto the grpc.ServiceRegistrar.

func (*GRPC) Watch

Watch the node state, writing data to the server stream when the leadership or known peers changes.

type Handler

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

The Handler type is responsible for handling raft commands regarding nodes and maintaining the node state.

func NewHandler

func NewHandler(nodes Store, logger hclog.Logger) *Handler

NewHandler returns a new instance of the Handler type that will maintain node state via the Store implementation.

func (*Handler) Add

func (h *Handler) Add(ctx context.Context, payload *nodecmd.AddNode) error

Add a new node to the state.

func (*Handler) AssignTopic

func (h *Handler) AssignTopic(ctx context.Context, payload *nodecmd.AssignTopic) error

AssignTopic assigns a topic to a desired node.

func (*Handler) Remove

func (h *Handler) Remove(ctx context.Context, payload *nodecmd.RemoveNode) error

Remove an existing node from the state.

type Info

type Info struct {
	Name    string
	Version string
}

The Info type contains node information served from the gRPC service.

type Lister

type Lister interface {
	// List should return all nodes within the cluster, including the current one.
	List(ctx context.Context) ([]*node.Node, error)
}

The Lister interface describes types that can list nodes within the state.

type Raft

type Raft interface {
	State() raft.RaftState
}

The Raft interface describes types that can return information regarding the raft state.

type Store

type Store interface {
	Create(ctx context.Context, n *node.Node) error
	Delete(ctx context.Context, name string) error
	AssignTopic(ctx context.Context, nodeName, topicName string) error
}

The Store interface describes types that manage node state within the database.

Jump to

Keyboard shortcuts

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