node

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterServer

func RegisterServer(server func(*grpc.Server, Protocol))

RegisterServer registers a service server

func RegisterServers

func RegisterServers(server *grpc.Server, protocol Protocol)

RegisterServers registers service servers on the given gRPC server

func RegisterService

func RegisterService(serviceType service.ServiceType, service func(scheduler service.Scheduler, context service.Context) service.Service)

RegisterService registers a new service

Types

type Context

type Context interface {
	// Node is the local node identifier
	Node() string

	// Index returns the current index of the state machine
	Index() uint64

	// Timestamp returns a deterministic, monotonically increasing timestamp
	Timestamp() time.Time
}

Context provides information about the context within which a state machine is running

type Partition

type Partition interface {
	// MustLeader returns whether the client can only be used on the leader
	MustLeader() bool

	// IsLeader returns whether the client is the leader
	IsLeader() bool

	// Leader returns the current leader
	Leader() string

	// Write sends a write request
	Write(ctx context.Context, input []byte, stream stream.WriteStream) error

	// Read sends a read request
	Read(ctx context.Context, input []byte, stream stream.WriteStream) error
}

Partition is the interface for a partition client

type Protocol

type Protocol interface {
	// Start starts the protocol
	Start(cluster cluster.Cluster, registry *Registry) error

	// Partition returns a partition
	Partition(partitionID int) Partition

	// Partitions returns the protocol partitions
	Partitions() []Partition

	// Stop stops the protocol
	Stop() error
}

Protocol is the interface to be implemented by replication protocols

type Registry

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

Registry is a registry of service types

func GetRegistry

func GetRegistry() *Registry

GetRegistry returns the service registry

func (*Registry) GetType

func (r *Registry) GetType(serviceType service.ServiceType) func(scheduler service.Scheduler, context service.Context) service.Service

GetType returns a service type by name

func (*Registry) RegisterServer

func (r *Registry) RegisterServer(server func(*grpc.Server, Protocol))

RegisterServer registers a new primitive server

func (*Registry) RegisterService

func (r *Registry) RegisterService(serviceType service.ServiceType, service func(scheduler service.Scheduler, context service.Context) service.Service)

RegisterService registers a new primitive service

type StateMachine

type StateMachine interface {
	// Snapshot writes the state machine snapshot to the given writer
	Snapshot(writer io.Writer) error

	// Install reads the state machine snapshot from the given reader
	Install(reader io.Reader) error

	// Command applies a command to the state machine
	Command(bytes []byte, stream streams.WriteStream)

	// Query applies a query to the state machine
	Query(bytes []byte, stream streams.WriteStream)
}

StateMachine applies commands from a protocol to a collection of state machines

Jump to

Keyboard shortcuts

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