balancer

package
v0.10.3-0...-54aaeda Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterPolicy

func RegisterPolicy(p Policy)

RegisterPolicy registers balancer policy.

Types

type Balancer

type Balancer interface {
	// WatchChannelAssignments watches the balance result.
	WatchChannelAssignments(ctx context.Context, cb func(version typeutil.VersionInt64Pair, relations []types.PChannelInfoAssigned) error) error

	// MarkAsAvailable marks the pchannels as available, and trigger a rebalance.
	MarkAsUnavailable(ctx context.Context, pChannels []types.PChannelInfo) error

	// Trigger is a hint to trigger a balance.
	Trigger(ctx context.Context) error

	// Close close the balancer.
	Close()
}

Balancer is a load balancer to balance the load of log node. Given the balance result to assign or remove channels to corresponding log node. Balancer is a local component, it should promise all channel can be assigned, and reach the final consistency. Balancer should be thread safe.

func RecoverBalancer

func RecoverBalancer(
	ctx context.Context,
	policy string,
	incomingNewChannel ...string,

) (Balancer, error)

RecoverBalancer recover the balancer working.

type CurrentLayout

type CurrentLayout struct {
	IncomingChannels []string                          // IncomingChannels is the channels that are waiting for assignment (not assigned in AllNodesInfo).
	AllNodesInfo     map[int64]types.StreamingNodeInfo // AllNodesInfo is the full information of all available streaming nodes and related pchannels (contain the node not assign anything on it).
	AssignedChannels map[int64][]types.PChannelInfo    // AssignedChannels maps the node id to assigned channels.
	ChannelsToNodes  map[string]int64                  // ChannelsToNodes maps assigned channel name to node id.
}

CurrentLayout is the full topology of streaming node and pChannel.

func (*CurrentLayout) TotalChannels

func (layout *CurrentLayout) TotalChannels() int

TotalChannels returns the total number of channels in the layout.

func (*CurrentLayout) TotalNodes

func (layout *CurrentLayout) TotalNodes() int

TotalNodes returns the total number of nodes in the layout.

type ExpectedLayout

type ExpectedLayout struct {
	ChannelAssignment map[string]types.StreamingNodeInfo // ChannelAssignment is the assignment of channel to node.
}

ExpectedLayout is the expected layout of streaming node and pChannel.

type Policy

type Policy interface {
	// Name is the name of the policy.
	Name() string

	// Balance is a function to balance the load of streaming node.
	// 1. all channel should be assigned.
	// 2. incoming layout should not be changed.
	// 3. return a expected layout.
	// 4. otherwise, error must be returned.
	// return a map of channel to a list of balance operation.
	// All balance operation in a list will be executed in order.
	// different channel's balance operation can be executed concurrently.
	Balance(currentLayout CurrentLayout) (expectedLayout ExpectedLayout, err error)
}

Policy is a interface to define the policy of rebalance.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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