pickers

package
v0.0.0-...-e78f20e Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoFeasibleChoice is returned by a picker when there is no feasible choice among
	// the offered possibilities.
	ErrNoFeasibleChoice = errors.New("Picker could not find a feasible choice")
)

Functions

This section is empty.

Types

type ClusterUsePicker

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

ClusterUsePicker is a picker that considers broker use across the entire cluster to break ties.

func NewClusterUsePicker

func NewClusterUsePicker(
	brokers []admin.BrokerInfo,
	topics []admin.TopicInfo,
) *ClusterUsePicker

NewClusterUsePicker generates a new picker from the argument brokers and topics.

func (*ClusterUsePicker) PickNew

func (c *ClusterUsePicker) PickNew(
	topic string,
	brokerChoices []int,
	curr []admin.PartitionAssignment,
	partition int,
	index int,
) error

PickNew updates the replica for the argument partition and index, using the choices in brokerChoices.

func (*ClusterUsePicker) ScoreBroker

func (c *ClusterUsePicker) ScoreBroker(
	topic string,
	brokerID int,
	partition int,
	index int,
) int

ScoreBroker returns an integer score for the given broker at the provided partition and index.

func (*ClusterUsePicker) SortRemovals

func (c *ClusterUsePicker) SortRemovals(
	topic string,
	partitionChoices []int,
	curr []admin.PartitionAssignment,
	index int,
) error

SortRemovals sorts the argument partitions in order of priority for removing the broker at the argument index.

type LowestIndexPicker

type LowestIndexPicker struct{}

LowestIndexPicker is a picker that uses broker index to break ties.

func NewLowestIndexPicker

func NewLowestIndexPicker() *LowestIndexPicker

NewLowestIndexPicker returns a new LowestIndexPicker instance.

func (*LowestIndexPicker) PickNew

func (l *LowestIndexPicker) PickNew(
	topic string,
	brokerChoices []int,
	curr []admin.PartitionAssignment,
	partition int,
	index int,
) error

PickNew updates the replica for the argument partition and index, using the choices in brokerChoices.

func (*LowestIndexPicker) ScoreBroker

func (l *LowestIndexPicker) ScoreBroker(
	topic string,
	brokerID int,
	partition int,
	index int,
) int

ScoreBroker returns an integer score for the given broker at the provided partition and index.

func (*LowestIndexPicker) SortRemovals

func (l *LowestIndexPicker) SortRemovals(
	topic string,
	partitionChoices []int,
	curr []admin.PartitionAssignment,
	index int,
) error

SortRemovals sorts the argument partitions in order of priority for removing the broker at the argument index.

type Picker

type Picker interface {
	// PickNew is the primary method used for assignment and extension. It chooses a new
	// replica for the given partition and index and directly modifies the argument assignments.
	PickNew(
		topic string,
		brokerChoices []int,
		curr []admin.PartitionAssignment,
		partition int,
		index int,
	) error

	// SortRemovals is a helper for choosing which replica in a set of partitions to replace.
	// Because the actual replacement logic is somewhat complex at the moment, the interface
	// is a little different than the PickNew function above. In particular, the choices are
	// a slice of partitions and these are sorted in place (without any replacement in curr).
	SortRemovals(
		topic string,
		partitionChoices []int,
		curr []admin.PartitionAssignment,
		index int,
	) error

	// ScoreBroker is a helper for generating a static "score" for a broker. It's used in
	// rebalancing and other applications where we're doing swaps as opposed to a single
	// addition or subtraction. A higher score should correspond to higher frequency, i.e.
	// more likely to be removed.
	ScoreBroker(
		topic string,
		brokerID int,
		partition int,
		index int,
	) int
}

Picker is an interface that picks a replica assignment based on arbitrary criteria (e.g., the current number of brokers in the given index). It's used by assigners and extenders to make choices, subject to specific constraints (e.g., must be in certain rack).

type RandomizedPicker

type RandomizedPicker struct{}

RandomizedPicker is a picker that uses broker index to break ties.

func NewRandomizedPicker

func NewRandomizedPicker() *RandomizedPicker

NewRandomizedPicker returns a new RandomizedPicker instance.

func (*RandomizedPicker) PickNew

func (r *RandomizedPicker) PickNew(
	topic string,
	brokerChoices []int,
	curr []admin.PartitionAssignment,
	partition int,
	index int,
) error

PickNew updates the replica for the argument partition and index, using the choices in brokerChoices.

func (*RandomizedPicker) ScoreBroker

func (r *RandomizedPicker) ScoreBroker(
	topic string,
	brokerID int,
	partition int,
	index int,
) int

ScoreBroker returns an integer score for the given broker at the provided partition and index.

func (*RandomizedPicker) SortRemovals

func (r *RandomizedPicker) SortRemovals(
	topic string,
	partitionChoices []int,
	curr []admin.PartitionAssignment,
	index int,
) error

SortRemovals sorts the argument partitions in order of priority for removing the broker at the argument index.

Jump to

Keyboard shortcuts

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