Documentation ¶
Overview ¶
Package balanced implements an allocator that can sort allocations based on multiple metrics, where metrics may be an arbitrary way to partition a set of peers.
For example, allocating by ["tag:region", "disk"] the resulting peer candidate order will balanced between regions and ordered by the value of the weight of the disk metric.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var (
DefaultAllocateBy = []string{"tag:group", "freespace"}
)
These are the default values for a Config.
Functions ¶
This section is empty.
Types ¶
type Allocator ¶
type Allocator struct {
// contains filtered or unexported fields
}
Allocator is an allocator that partitions metrics and orders the final list of allocation by selecting for each partition.
func (*Allocator) Allocate ¶
func (a *Allocator) Allocate( ctx context.Context, c api.Cid, current, candidates, priority api.MetricsSet, ) ([]peer.ID, error)
Allocate produces a sorted list of cluster peer IDs based on different metrics provided for those peer IDs. It works as follows:
- First, it buckets each peer metrics based on the AllocateBy list. The metric name must match the bucket name, otherwise they are put at the end.
- Second, based on the AllocateBy order, it orders the first bucket and groups peers by ordered value.
- Third, it selects metrics on the second bucket for the most prioritary peers of the first bucket and orders their metrics. Then for the peers in second position etc.
- It repeats the process until there is no more buckets to sort.
- Finally, it returns the first peer of the first
- Third, based on the AllocateBy order, it select the first metric
func (*Allocator) Metrics ¶
Metrics returns the names of the metrics that have been registered with this allocator.
type Config ¶
Config allows to initialize the Allocator.
func (*Config) ApplyEnvVars ¶
ApplyEnvVars fills in any Config fields found as environment variables.
func (*Config) ToDisplayJSON ¶
ToDisplayJSON returns JSON config as a string.