selectors

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HashKey

func HashKey(topic topic.Topic) uint32

HashKey hashes the topic to a stable uint32 hash using SHA-256.

Types

type ClosestNodeSelectorAlgorithm

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

ClosestNodeSelectorAlgorithm selects the node with the lowest measured TCP connect latency, excluding any nodes present in the banlist. Latency measurements are cached for a configured duration and refreshed periodically to reduce overhead.

func NewClosestNodeSelectorAlgorithm

func NewClosestNodeSelectorAlgorithm(
	reg registry.NodeRegistry,
	cacheExpiry time.Duration,
	connectTimeout time.Duration,
	preferredNodes ...[]uint32,
) *ClosestNodeSelectorAlgorithm

func (*ClosestNodeSelectorAlgorithm) GetNode

func (c *ClosestNodeSelectorAlgorithm) GetNode(
	_ topic.Topic,
	banlist ...[]uint32,
) (uint32, error)

type ManualNodeSelectorAlgorithm

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

ManualNodeSelectorAlgorithm always selects the first available node from an explicit list of node IDs. The topic is ignored. If a node in the manual list is not present in the registry or is banned, it is skipped. If no node from the list is usable, selection fails.

This strategy is useful for pinning traffic to specific nodes (e.g., during testing or partial rollouts).

func NewManualNodeSelectorAlgorithm

func NewManualNodeSelectorAlgorithm(
	reg registry.NodeRegistry,
	nodeIDs []uint32,
) *ManualNodeSelectorAlgorithm

func (*ManualNodeSelectorAlgorithm) GetNode

func (m *ManualNodeSelectorAlgorithm) GetNode(
	_ topic.Topic,
	banlist ...[]uint32,
) (uint32, error)

type NodeSelectorAlgorithm

type NodeSelectorAlgorithm interface {
	GetNode(topic topic.Topic, banlist ...[]uint32) (uint32, error)
}

type NodeSelectorConfig

type NodeSelectorConfig struct {
	Strategy       NodeSelectorStrategy
	PreferredNodes []uint32
	CacheExpiry    time.Duration
	ConnectTimeout time.Duration
}

type NodeSelectorStrategy

type NodeSelectorStrategy string
const (
	NodeSelectorStrategyStable  NodeSelectorStrategy = "stable"
	NodeSelectorStrategyManual  NodeSelectorStrategy = "manual"
	NodeSelectorStrategyOrdered NodeSelectorStrategy = "ordered"
	NodeSelectorStrategyRandom  NodeSelectorStrategy = "random"
	NodeSelectorStrategyClosest NodeSelectorStrategy = "closest"
)

type OrderedPreferenceNodeSelectorAlgorithm

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

OrderedPreferenceNodeSelectorAlgorithm selects the first available node from a preferred ordered list, falling back to the first unbanned node in the full registry if none of the preferred nodes are usable.

This strategy is useful when you want to prioritize certain nodes but retain automatic fallback in case preferred nodes are unavailable.

func NewOrderedPreferenceNodeSelectorAlgorithm

func NewOrderedPreferenceNodeSelectorAlgorithm(
	reg registry.NodeRegistry,
	preferredNodeIDs []uint32,
) *OrderedPreferenceNodeSelectorAlgorithm

func (*OrderedPreferenceNodeSelectorAlgorithm) GetNode

func (o *OrderedPreferenceNodeSelectorAlgorithm) GetNode(
	_ topic.Topic,
	banlist ...[]uint32,
) (uint32, error)

type RandomNodeSelectorAlgorithm

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

RandomNodeSelectorAlgorithm selects a node uniformly at random from all currently available nodes, excluding any nodes present in the banlist.

This strategy provides load distribution but does not provide affinity or determinism.

func NewRandomNodeSelectorAlgorithm

func NewRandomNodeSelectorAlgorithm(
	reg registry.NodeRegistry,
) *RandomNodeSelectorAlgorithm

func (*RandomNodeSelectorAlgorithm) GetNode

func (r *RandomNodeSelectorAlgorithm) GetNode(
	_ topic.Topic,
	banlist ...[]uint32,
) (uint32, error)

type StableHashingNodeSelectorAlgorithm

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

StableHashingNodeSelectorAlgorithm implements deterministic topic-to-node selection using a stable hash. Nodes are sorted by NodeID to ensure consistent ordering.

This strategy provides stickiness (topic affinity) and minimizes churn as long as the node set is stable, but any node set change will cause remapping for some topics.

func NewStableHashingNodeSelectorAlgorithm

func NewStableHashingNodeSelectorAlgorithm(
	reg registry.NodeRegistry,
) *StableHashingNodeSelectorAlgorithm

func (*StableHashingNodeSelectorAlgorithm) GetNode

func (s *StableHashingNodeSelectorAlgorithm) GetNode(
	topic topic.Topic,
	banlist ...[]uint32,
) (uint32, error)

GetNode selects a node for a given topic using stable hashing

Jump to

Keyboard shortcuts

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