cluster

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2025 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// master
	// the cluster master is responsible for managing garbage collection for both nodes and plugins.
	// typically, each node handles the garbage collection for its own plugins
	// However, if a node becomes inactive, the master takes over this task.
	// every node has an equal chance of becoming the master.
	// once a node is selected as the master, it is locked in that role.
	// If the master node becomes inactive, the master slot is released, allowing other nodes to attempt to take over the role.
	MASTER_LOCKING_INTERVAL  = time.Millisecond * 500 // interval to try to lock the slot to be the master
	MASTER_LOCK_EXPIRED_TIME = time.Second * 2        // expired time of master key
	MASTER_GC_INTERVAL       = time.Second * 10       // interval to do garbage collection of nodes has already deactivated

	// node
	// To determine the available IPs of the nodes, each node will vote for the IPs of other nodes.
	// this voting process will occur every $NODE_VOTE_INTERVAL.
	// simultaneously, all nodes will synchronize to the latest status in memory every $UPDATE_NODE_STATUS_INTERVAL.
	// each node will also update its own status to remain active. If a node becomes inactive, it will be removed from the cluster.
	NODE_VOTE_INTERVAL          = time.Second * 30 // interval to vote the ips of the nodes
	UPDATE_NODE_STATUS_INTERVAL = time.Second * 5  // interval to update the status of the node
	NODE_DISCONNECTED_TIMEOUT   = time.Second * 10 // once a node is no longer active, it will be removed from the cluster

	// plugin scheduler
	// each node will schedule its plugins every $PLUGIN_SCHEDULER_INTERVAL time
	// and schedule process will be triggered every $PLUGIN_SCHEDULER_TICKER_INTERVAL time
	// not all the plugins will be scheduled every time, only the plugins that are not scheduled in $PLUGIN_SCHEDULER_INTERVAL time will be scheduled
	// and the plugins that are not active will be removed from the cluster
	PLUGIN_SCHEDULER_TICKER_INTERVAL = time.Second * 3  // interval to schedule the plugins
	PLUGIN_SCHEDULER_INTERVAL        = time.Second * 10 // interval to schedule the plugins
	PLUGIN_DEACTIVATED_TIMEOUT       = time.Second * 30 // once a plugin is no longer active, it will be removed from the cluster
)
View Source
const (
	CLUSTER_STATUS_HASH_MAP_KEY = "cluster-nodes-status-hash-map"
	PREEMPTION_LOCK_KEY         = "cluster-master-preemption-lock"
)
View Source
const (
	CLUSTER_NEW_NODE_CHANNEL = "cluster-new-node-channel"
)
View Source
const (
	CLUSTER_UPDATE_NODE_STATUS_LOCK_PREFIX = "cluster-update-node-status-lock"
)
View Source
const (
	PLUGIN_STATE_MAP_KEY = "plugin_state"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Cluster

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

func NewCluster

func NewCluster(config *app.Config, plugin_manager *plugin_manager.PluginManager) *Cluster

func (*Cluster) Close

func (c *Cluster) Close() error

func (*Cluster) FetchPluginAvailableNodesByHashedId

func (c *Cluster) FetchPluginAvailableNodesByHashedId(hashedPluginId string) ([]string, error)

FetchPluginAvailableNodesByHashedId fetches the available nodes of the given plugin

func (*Cluster) FetchPluginAvailableNodesById

func (c *Cluster) FetchPluginAvailableNodesById(plugin_id string) ([]string, error)

func (*Cluster) GetNodes

func (c *Cluster) GetNodes() (map[string]node, error)

func (*Cluster) ID

func (c *Cluster) ID() string

func (*Cluster) IsMaster

func (c *Cluster) IsMaster() bool

func (*Cluster) IsNodeAlive

func (c *Cluster) IsNodeAlive(nodeId string) bool

func (*Cluster) IsPluginOnCurrentNode

func (c *Cluster) IsPluginOnCurrentNode(identity plugin_entities.PluginUniqueIdentifier) (bool, error)

func (*Cluster) Launch

func (c *Cluster) Launch()

func (*Cluster) LockNodeStatus

func (c *Cluster) LockNodeStatus(nodeId string) error

func (*Cluster) NotifyBecomeMaster

func (c *Cluster) NotifyBecomeMaster() <-chan bool

receive the master event

func (*Cluster) NotifyClusterStopped

func (c *Cluster) NotifyClusterStopped() <-chan bool

receive the cluster stopped event

func (*Cluster) NotifyMasterGC

func (c *Cluster) NotifyMasterGC() <-chan bool

receive the master gc event

func (*Cluster) NotifyMasterGCCompleted

func (c *Cluster) NotifyMasterGCCompleted() <-chan bool

receive the master gc completed event

func (*Cluster) NotifyNodeUpdate

func (c *Cluster) NotifyNodeUpdate() <-chan bool

receive the node update event

func (*Cluster) NotifyNodeUpdateCompleted

func (c *Cluster) NotifyNodeUpdateCompleted() <-chan bool

receive the node update completed event

func (*Cluster) NotifyPluginSchedule

func (c *Cluster) NotifyPluginSchedule() <-chan bool

receive the plugin schedule event

func (*Cluster) NotifyPluginScheduleCompleted

func (c *Cluster) NotifyPluginScheduleCompleted() <-chan bool

receive the plugin schedule completed event

func (*Cluster) NotifyVoting

func (c *Cluster) NotifyVoting() <-chan bool

receive the voting event

func (*Cluster) NotifyVotingCompleted

func (c *Cluster) NotifyVotingCompleted() <-chan bool

receive the voting completed event

func (*Cluster) RedirectRequest

func (c *Cluster) RedirectRequest(
	node_id string, request *http.Request,
) (int, http.Header, io.ReadCloser, error)

RedirectRequest redirects the request to the specified node

func (*Cluster) RegisterPlugin

func (c *Cluster) RegisterPlugin(lifetime plugin_entities.PluginLifetime) error

RegisterPlugin registers a plugin to the cluster, and start to be scheduled

func (*Cluster) SortIps

func (c *Cluster) SortIps(nodeStatus node) []address

func (*Cluster) UnlockNodeStatus

func (c *Cluster) UnlockNodeStatus(nodeId string) error

Jump to

Keyboard shortcuts

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