topo

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package topo provides utility functions for interacting with the Multigres global topology server (etcd). It consolidates store creation and common topology operations (database/cell registration, pooler queries) that were previously duplicated across data-handler controllers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CollectCells

func CollectCells(shard *multigresv1alpha1.Shard) []string

CollectCells returns the sorted, deduplicated set of cell names from the shard's pools.

func FindPrimaryPooler

func FindPrimaryPooler(
	ctx context.Context,
	store topoclient.Store,
	shard *multigresv1alpha1.Shard,
	cells []string,
) (*clustermetadatapb.MultiPooler, error)

FindPrimaryPooler discovers the PRIMARY multipooler from the given cells in the topology. Returns (nil, nil) only if at least one cell was successfully queried but no primary was found. Returns an error if all cells are unavailable.

func ForceUnregisterPod

func ForceUnregisterPod(
	ctx context.Context,
	store topoclient.Store,
	shard *multigresv1alpha1.Shard,
	podName string,
	cellName string,
) error

ForceUnregisterPod unregisters a specific pod's pooler from the topology.

func GetBackupLocation

func GetBackupLocation(shard *multigresv1alpha1.Shard) *clustermetadatapb.BackupLocation

GetBackupLocation extracts the backup location from the shard config.

func GetDurabilityPolicy

func GetDurabilityPolicy(shard *multigresv1alpha1.Shard) string

GetDurabilityPolicy extracts the durability policy from the shard config. Falls back to "AT_LEAST_2" if not set (the default materialized by the webhook resolver).

func IsTopoUnavailable

func IsTopoUnavailable(err error) bool

IsTopoUnavailable returns true if the error indicates the topology server is not reachable (e.g., gRPC UNAVAILABLE during startup).

func NewStoreFromCell

func NewStoreFromCell(cell *multigresv1alpha1.Cell) (topoclient.Store, error)

NewStoreFromCell creates a topoclient.Store using the GlobalTopoServer configuration from a Cell resource.

func NewStoreFromRef

NewStoreFromRef creates a topoclient.Store using a GlobalTopoServerRef. This is used by the MultigresCluster controller which already computes the reference via getGlobalTopoRef().

func NewStoreFromShard

func NewStoreFromShard(shard *multigresv1alpha1.Shard) (topoclient.Store, error)

NewStoreFromShard creates a topoclient.Store using the GlobalTopoServer configuration from a Shard resource.

func PodMatchesPooler

func PodMatchesPooler(podName string, p *topoclient.MultiPoolerInfo) bool

PodMatchesPooler checks if the topology pooler record corresponds to the given Kubernetes pod name.

func PruneCells

func PruneCells(
	ctx context.Context,
	store topoclient.Store,
	recorder record.EventRecorder,
	owner runtime.Object,
	specCellNames []string,
) error

PruneCells removes stale cell entries from the topology that are not present in the cluster spec.

func PruneDatabases

func PruneDatabases(
	ctx context.Context,
	store topoclient.Store,
	recorder record.EventRecorder,
	owner runtime.Object,
	specDBNames []string,
) error

PruneDatabases removes stale database entries from the topology that are not present in the cluster spec.

func PrunePoolers

func PrunePoolers(
	ctx context.Context,
	store topoclient.Store,
	shard *multigresv1alpha1.Shard,
	activePodNames map[string]bool,
) (int, error)

PrunePoolers removes topology entries for poolers that have no corresponding running pod. activePodNames should contain the names of all pods currently managed by the shard. Returns the number of pruned entries.

func RegisterCell

func RegisterCell(
	ctx context.Context,
	store topoclient.Store,
	recorder record.EventRecorder,
	cell *multigresv1alpha1.Cell,
) error

RegisterCell registers the cell metadata in the global topology.

func RegisterCellFromSpec

func RegisterCellFromSpec(
	ctx context.Context,
	store topoclient.Store,
	recorder record.EventRecorder,
	owner runtime.Object,
	cellConfig multigresv1alpha1.CellConfig,
	topoRef multigresv1alpha1.GlobalTopoServerRef,
) error

RegisterCellFromSpec registers a cell in the topology using the cluster spec. It uses the GlobalTopoServerRef to build the cell metadata.

func RegisterDatabase

func RegisterDatabase(
	ctx context.Context,
	store topoclient.Store,
	recorder record.EventRecorder,
	shard *multigresv1alpha1.Shard,
) error

RegisterDatabase registers the database metadata in the global topology. It creates the database entry or updates it if it already exists.

func RegisterDatabaseFromSpec

func RegisterDatabaseFromSpec(
	ctx context.Context,
	store topoclient.Store,
	recorder record.EventRecorder,
	owner runtime.Object,
	dbConfig multigresv1alpha1.DatabaseConfig,
	allCellNames []string,
	backup *multigresv1alpha1.BackupConfig,
	clusterDurabilityPolicy string,
) error

RegisterDatabaseFromSpec registers a database in the topology using the cluster spec. It collects cells from all pools across all shards in the database's table groups.

func ShardFilter

ShardFilter builds a GetMultiPoolersByCellOptions filter for a shard.

func UnregisterCell

func UnregisterCell(
	ctx context.Context,
	store topoclient.Store,
	recorder record.EventRecorder,
	cell *multigresv1alpha1.Cell,
) error

UnregisterCell removes the cell metadata from the global topology.

func UnregisterDatabase

func UnregisterDatabase(
	ctx context.Context,
	store topoclient.Store,
	recorder record.EventRecorder,
	shard *multigresv1alpha1.Shard,
) error

UnregisterDatabase removes the database metadata from the global topology.

Types

type PoolerStatusResult

type PoolerStatusResult struct {
	// Roles maps hostname to role string (PRIMARY, REPLICA, DRAINED).
	Roles map[string]string
	// QuerySuccess indicates whether all topology queries succeeded.
	QuerySuccess bool
}

PoolerStatusResult holds the result of querying pooler roles from the topology.

func GetPoolerStatus

func GetPoolerStatus(
	ctx context.Context,
	store topoclient.Store,
	shard *multigresv1alpha1.Shard,
	managedPodNames []string,
) *PoolerStatusResult

GetPoolerStatus queries the topology for all poolers belonging to a shard and returns a map of pod name to role string. managedPodNames is the set of Kubernetes pod names currently managed by the shard controller; topology entries are matched to pods via PodMatchesPooler (FQDN-aware).

Jump to

Keyboard shortcuts

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