Documentation
¶
Index ¶
- Constants
- func BackupFilter[T any]() selector.Filter[T]
- func FIFOStrategy[T any]() selector.Strategy[T]
- func FailFilter[T any](maxFails int, timeout time.Duration) selector.Filter[T]
- func HashStrategy[T any]() selector.Strategy[T]
- func IsFailed[T any](v T, maxFails int, failTimeout time.Duration) bool
- func LatencyFilter[T any](maxLatency time.Duration) selector.Filter[T]
- func LowestLatencyStrategy[T any]() selector.Strategy[T]
- func NewSelector[T any](strategy selector.Strategy[T], filters ...selector.Filter[T]) selector.Selector[T]
- func ParallelStrategy[T any](opts ...ParallelOption) selector.Strategy[T]
- func RandomStrategy[T any]() selector.Strategy[T]
- func RoundRobinStrategy[T any]() selector.Strategy[T]
- type ParallelOption
- type RandomWeighted
Constants ¶
const ( DefaultMaxFails = 1 DefaultFailTimeout = 10 * time.Second )
default options for FailFilter
Variables ¶
This section is empty.
Functions ¶
func BackupFilter ¶
BackupFilter filters the backup objects. An object is marked as backup if its metadata has backup flag.
func FIFOStrategy ¶
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 ¶
FailFilter filters the dead objects. An object is marked as dead if its failed count is greater than MaxFails.
func HashStrategy ¶
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
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
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
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 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 ¶
RandomStrategy is a strategy for node selector. The node will be selected randomly.
func RoundRobinStrategy ¶
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.