offset

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnroutedProducers = errors.New("unrouted producers detected")

ErrUnroutedProducers is returned by DetectUnroutedProducers when a source offset increases across the monitoring window: evidence of a producer writing directly to the source cluster, bypassing a fenced gateway. Both the AAO (migration) and TBM orchestrators re-export this under their own name (e.g. `var ErrUnroutedProducers = offset.ErrUnroutedProducers`) so their existing errors.Is call sites keep working unchanged.

Functions

func ComputeTotalLag

func ComputeTotalLag(src, dst map[int32]int64) int64

ComputeTotalLag computes the total offset lag across all partitions. For partitions missing from dst, the full source offset counts as lag.

func DetectUnroutedProducers added in v0.11.0

func DetectUnroutedProducers(ctx context.Context, source Provider, reporter Reporter, topics []string, duration time.Duration) (err error)

DetectUnroutedProducers takes two source offset snapshots separated by the given duration. If any partition's offset increases between snapshots, it means a producer is writing directly to the source cluster (bypassing the fenced gateway) and the migration should not proceed. Shared by the AAO (migration) and TBM orchestrators, which otherwise hand-maintained two identical copies — both wrap the same ErrUnroutedProducers, so either package's orchestrator can errors.Is against it.

func FetchSourceAndDestinationOffsets added in v0.11.0

func FetchSourceAndDestinationOffsets(ctx context.Context, source, destination Provider, topics []string) (_, _ map[string]map[int32]int64, err error)

FetchSourceAndDestinationOffsets sweeps both clusters' offsets for the given topics concurrently — the clusters are independent, so a poll tick pays the slower of the two sweeps rather than their sum. Shared by the AAO (migration) and TBM orchestrators, which otherwise hand-maintained two identical copies.

func SortedPartitionIDs

func SortedPartitionIDs(src, dst map[int32]int64) []int32

SortedPartitionIDs returns the union of partition IDs from two offset maps, sorted ascending.

Types

type Provider added in v0.7.1

type Provider interface {
	GetMany(ctx context.Context, topics []string) (map[string]map[int32]int64, error)
}

Provider abstracts offset retrieval for testability.

type Reporter added in v0.11.0

type Reporter interface {
	Detail(format string, args ...any)
}

Reporter is the minimal user-facing output surface DetectUnroutedProducers needs. Both migration's and TBM's own unexported reporter types satisfy this structurally.

type Service

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

Service provides offset operations against a Kafka cluster.

func NewOffsetService

func NewOffsetService(client sarama.Client) *Service

NewOffsetService creates a Service backed by the given Kafka client.

func (*Service) Close

func (t *Service) Close() error

Close closes the underlying Kafka client.

func (*Service) Exists

func (t *Service) Exists(topic string) (bool, error)

Exists checks whether a topic exists on the cluster by refreshing metadata.

func (*Service) Get

func (t *Service) Get(ctx context.Context, topic string) (map[int32]int64, error)

Get fetches the log end offset (LEO) for every partition of a topic. It is a single-topic wrapper over GetMany kept for the package tests and the offsetbench loop-vs-batch contrast; production sweeps call GetMany, which costs one request per broker instead of one per topic.

func (*Service) GetMany added in v0.8.8

func (t *Service) GetMany(ctx context.Context, topics []string) (_ map[string]map[int32]int64, err error)

GetMany fetches the log end offset (LEO) for every partition of every topic in a single sweep. Partitions are grouped by leader broker across all topics and one ListOffsets request is sent per broker (concurrently), so a sweep of N topics costs one round trip instead of N.

Partitions that fail because cached metadata went stale (leader moved, replica unavailable, every broker dropped) or because the leader's connection failed (internal/retry's Retryable) are fetched again within the retry budget: before each retry the failed leaders' connections are closed and their topics' metadata refreshed. A sweep in which any partition failed some other way, such as a failed login or a TLS error, fails at once with that cause. The lag wait and promote also tolerate 2 failed sweeps in a row, so on a cluster that stays unreachable they fail after about three budgets.

func (*Service) WithCluster added in v0.11.0

func (t *Service) WithCluster(cluster string) *Service

WithCluster labels the service's spans with which cluster it reads ("source" or "destination") and returns it.

Jump to

Keyboard shortcuts

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