discovery

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NewStateMachineFn = NewStateMachine

NewStateMachineFn represents new state machine function.

Functions

func ExploreData added in v0.2.4

func ExploreData(ctx context.Context, repo state.Repository, stateMachineInfo models.StateMachineInfo) (interface{}, error)

ExploreData explores state repository data by given path.

Types

type Discovery

type Discovery interface {
	// Discovery starts discovery resources change, includes create/delete/clean,
	// if init = true, need list all resources before watch path.
	Discovery(init bool) error
	// Close stops watch, trigger all resource cleanup callback.
	Close()
}

Discovery represents discovery resources, through watch resource's prefix.

type Event

type Event struct {
	Type  EventType
	Key   string
	Value []byte

	Attributes map[string]string
}

Event represents discovery state change event.

type EventType

type EventType int

EventType represents coordinator event type.

const (
	DatabaseConfigChanged EventType = iota + 1
	DatabaseConfigDeletion
	ShardAssignmentChanged
	ShardAssignmentDeletion
	NodeStartup
	NodeFailure
	StorageStateChanged
	StorageStateDeletion
	StorageConfigChanged
	StorageConfigDeletion
	BrokerConfigChanged
	BrokerConfigDeletion
	DatabaseLimitsChanged
)

func (EventType) String

func (e EventType) String() string

String returns string value of EventType.

type Factory

type Factory interface {
	// GetRepo returns the repo of discovery used.
	GetRepo() state.Repository
	// CreateDiscovery creates a discovery who will watch the changes with the given prefix.
	CreateDiscovery(prefix string, listener Listener) Discovery
}

Factory represents a discovery create factory.

func NewFactory

func NewFactory(repo state.Repository) Factory

NewFactory creates a factory.

type Listener

type Listener interface {
	// OnCreate is resource creation callback.
	OnCreate(key string, resource []byte)
	// OnDelete is resource deletion callback.
	OnDelete(key string)
}

Listener represents discovery resource event callback interface, includes create/delete/cleanup operation.

type Registry

type Registry interface {
	io.Closer
	// Register registers node info, add it to active node list for discovery.
	Register(node models.Node) error
	// Deregister deregister node info, remove it from active list.
	Deregister(node models.Node) error
	// IsSuccess returns if registry successfully.
	IsSuccess() bool
}

Registry represents server node register.

func NewRegistry

func NewRegistry(repo state.Repository, prefixPath string, ttl time.Duration) Registry

NewRegistry returns a new registry with prefix and ttl.

type StateMachine

type StateMachine interface {
	Listener
	io.Closer
}

StateMachine represents state changed event state machine. Like node online/offline, database create events etc.

func NewStateMachine

func NewStateMachine(ctx context.Context,
	stateMachineType StateMachineType,
	discoveryFactory Factory,
	watchPath string,
	needInitialize bool,
	onCreateFn func(key string, resource []byte),
	onDeleteFn func(key string),
) (StateMachine, error)

NewStateMachine creates a state machine instance.

type StateMachineEventHandle

type StateMachineEventHandle interface {
	// EmitEvent emits discovery event when state changed.
	EmitEvent(event *Event)
	// Close cleans the resource.
	Close()
}

StateMachineEventHandle represents handle state machine event.

type StateMachineFactory

type StateMachineFactory interface {
	// Start starts all state machines, do init logic.
	Start() error
	// Stop stops all state machines, clean all resources.
	Stop()
}

StateMachineFactory represents maintain all state machines for each role.

type StateMachineType

type StateMachineType int

StateMachineType represents state machine type.

const (
	DatabaseConfigStateMachine StateMachineType = iota + 1
	ShardAssignmentStateMachine
	LiveNodeStateMachine
	StorageStatusStateMachine
	StorageConfigStateMachine
	StorageNodeStateMachine
	BrokerConfigStateMachine
	BrokerNodeStateMachine
	DatabaseLimitsStateMachine
)

func (StateMachineType) String

func (st StateMachineType) String() string

String returns state machine type desc.

Jump to

Keyboard shortcuts

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