Documentation
¶
Index ¶
- Variables
- func ComputeTotalLag(src, dst map[int32]int64) int64
- func DetectUnroutedProducers(ctx context.Context, source Provider, reporter Reporter, topics []string, ...) (err error)
- func FetchSourceAndDestinationOffsets(ctx context.Context, source, destination Provider, topics []string) (_, _ map[string]map[int32]int64, err error)
- func SortedPartitionIDs(src, dst map[int32]int64) []int32
- type Provider
- type Reporter
- type Service
- func (t *Service) Close() error
- func (t *Service) Exists(topic string) (bool, error)
- func (t *Service) Get(ctx context.Context, topic string) (map[int32]int64, error)
- func (t *Service) GetMany(ctx context.Context, topics []string) (_ map[string]map[int32]int64, err error)
- func (t *Service) WithCluster(cluster string) *Service
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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
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 ¶
NewOffsetService creates a Service backed by the given Kafka client.
func (*Service) Exists ¶
Exists checks whether a topic exists on the cluster by refreshing metadata.
func (*Service) Get ¶
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
WithCluster labels the service's spans with which cluster it reads ("source" or "destination") and returns it.