dispatcher

package
v0.0.0-...-3ca6529 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dispatcher

type Dispatcher interface {
	// Start initializes and runs the dispatcher based on different implementations.
	Start(ctx context.Context)
	// Dispatch determines if the current Maestro instance should process the resource status update based on the consumer ID.
	Dispatch(consumerName string) bool
	// OnInstanceUp is called when a new maestro instance is up.
	OnInstanceUp(instanceID string) error
	// OnInstanceDown is called when a maestro instance is inactive.
	OnInstanceDown(instanceID string) error
}

Dispatcher defines methods for coordinating resource status updates in the context of multiple active maestro instances.

The dispatcher ensures only one instance processes specific resource status updates from a consumer. It needs to handle status resync based on the instances' status and different implementations.

type HashDispatcher

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

HashDispatcher is an implementation of Dispatcher. It uses consistent hashing to map consumers to maestro instances. Only the maestro instance that is mapped to a consumer will process the resource status update from that consumer. Need to trigger status resync for the consumer when an instance is up or down.

func NewHashDispatcher

func NewHashDispatcher(instanceID string, instanceDao dao.InstanceDao, consumerDao dao.ConsumerDao, sourceClient cloudevents.SourceClient) *HashDispatcher

func (*HashDispatcher) Dispatch

func (d *HashDispatcher) Dispatch(consumerName string) bool

Dispatch checks if the provided consumer ID is owned by the current maestro instance. It returns true if the consumer is part of the current instance's consumer set; otherwise, it returns false.

func (*HashDispatcher) OnInstanceDown

func (d *HashDispatcher) OnInstanceDown(instanceID string) error

OnInstanceDown removes the instance from the hashing ring and updates the consumer set for the current instance.

func (*HashDispatcher) OnInstanceUp

func (d *HashDispatcher) OnInstanceUp(instanceID string) error

OnInstanceUp adds the new instance to the hashing ring and updates the consumer set for the current instance.

func (*HashDispatcher) Start

func (d *HashDispatcher) Start(ctx context.Context)

Start initializes and runs the dispatcher, updating the hashing ring and consumer set for the current instance.

type NoopDispatcher

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

NoopDispatcher is a no-op implementation of Dispatcher. It will always dispatch the resource status update to the current maestro instance. This is the default implementation when shared subscription is enabled. Need to trigger status resync from all consumers when an instance is down.

func NewNoopDispatcher

func NewNoopDispatcher(consumerDao dao.ConsumerDao, sourceClient cloudevents.SourceClient) *NoopDispatcher

NewNoopDispatcher creates a new NoopDispatcher instance.

func (*NoopDispatcher) Dispatch

func (d *NoopDispatcher) Dispatch(consumerID string) bool

Dispatch always returns true, indicating that the current maestro instance should process the resource status update.

func (*NoopDispatcher) OnInstanceDown

func (d *NoopDispatcher) OnInstanceDown(instanceID string) error

OnInstanceDown triggers status resync from all consumers.

func (*NoopDispatcher) OnInstanceUp

func (d *NoopDispatcher) OnInstanceUp(instanceID string) error

OnInstanceUp is a no-op implementation.

func (*NoopDispatcher) Start

func (d *NoopDispatcher) Start(ctx context.Context)

Start is a no-op implementation.

Jump to

Keyboard shortcuts

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