selector

package
v0.28.2 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: MIT Imports: 17 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	DefaultMaxFails    = 1
	DefaultFailTimeout = 10 * time.Second
)

default options for FailFilter

Variables

This section is empty.

Functions

func BackupFilter

func BackupFilter[T any]() selector.Filter[T]

BackupFilter filters the backup objects. An object is marked as backup if its metadata has backup flag.

func FIFOStrategy

func FIFOStrategy[T any]() selector.Strategy[T]

FIFOStrategy is a strategy for node selector. The node will be selected from first to last, and will stick to the selected node until it is failed.

func FailFilter

func FailFilter[T any](maxFails int, timeout time.Duration) selector.Filter[T]

FailFilter filters the dead objects. An object is marked as dead if its failed count is greater than MaxFails.

func HashStrategy

func HashStrategy[T any]() selector.Strategy[T]

HashStrategy is a strategy for node selector. The node will be selected by hashing the client ID or hash source from the context. Falls back to random selection when neither is available.

func IsFailed added in v0.28.1

func IsFailed[T any](v T, maxFails int, failTimeout time.Duration) bool

IsFailed reports whether v is currently marked failed: its failure count has reached maxFails and the last failure is still within failTimeout. Per-item metadata keys "maxFails" and "failTimeout" override the given defaults. Items without a failure marker are never considered failed.

func LatencyFilter added in v0.28.1

func LatencyFilter[T any](maxLatency time.Duration) selector.Filter[T]

LatencyFilter filters out items whose probe result indicates failure or latency exceeding maxLatency. Items without a probe result are passed through (no instrumentation = no filtering).

func LowestLatencyStrategy added in v0.28.1

func LowestLatencyStrategy[T any]() selector.Strategy[T]

LowestLatencyStrategy selects the item with the lowest probe latency. Items without a probe result or with failed probes are deprioritized (placed after items with successful probes).

func NewSelector

func NewSelector[T any](strategy selector.Strategy[T], filters ...selector.Filter[T]) selector.Selector[T]

func ParallelStrategy added in v0.28.1

func ParallelStrategy[T any](opts ...ParallelOption) selector.Strategy[T]

ParallelStrategy is a strategy for node selector. It dials the selected nodes concurrently and uses the first successful connection. Without a limit all nodes take part in every race; with a limit only that many nodes are picked from the candidate pool for each connection attempt.

func RandomStrategy

func RandomStrategy[T any]() selector.Strategy[T]

RandomStrategy is a strategy for node selector. The node will be selected randomly.

func RoundRobinStrategy

func RoundRobinStrategy[T any]() selector.Strategy[T]

RoundRobinStrategy is a strategy for node selector. The node will be selected by round-robin algorithm.

Types

type ParallelOption added in v0.28.1

type ParallelOption func(*parallelConfig)

ParallelOption configures the parallel strategy.

func ParallelLimit added in v0.28.1

func ParallelLimit(n int) ParallelOption

ParallelLimit sets the maximum number of nodes racing concurrently in a single connection attempt. The remaining nodes stay in the candidate pool and take part in later races. A value <= 0 means no limit: all nodes race.

func ParallelMode added in v0.28.1

func ParallelMode(mode string) ParallelOption

ParallelMode sets how the racing subset is selected from the candidate pool. Supported modes are "round" (round-robin, the default) and "random". An unrecognized mode falls back to round-robin.

type RandomWeighted

type RandomWeighted[T any] struct {
	// contains filtered or unexported fields
}

RandomWeighted is a weighted random selector. Items are selected randomly with probability proportional to their weight.

func NewRandomWeighted

func NewRandomWeighted[T any]() *RandomWeighted[T]

NewRandomWeighted creates a new RandomWeighted selector.

func (*RandomWeighted[T]) Add

func (rw *RandomWeighted[T]) Add(item T, weight int)

Add adds an item with the given weight to the selector.

func (*RandomWeighted[T]) Next

func (rw *RandomWeighted[T]) Next() (v T)

Next selects an item randomly based on weights. Returns the zero value if no items are added.

func (*RandomWeighted[T]) Reset

func (rw *RandomWeighted[T]) Reset()

Reset clears all items and weights.

Jump to

Keyboard shortcuts

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