Documentation
¶
Index ¶
- Constants
- Variables
- func BrokerRegistrationKey(brokerID string) string
- func CommitConsumerOffsetIfGroupExists(ctx context.Context, store Store, group string, createRevision int64, ...) error
- func CommitMemberConsumerOffsetIfGroupExists(ctx context.Context, store Store, group string, createRevision int64, ...) error
- func CommitSimpleConsumerOffset(ctx context.Context, store Store, group, topic string, partition int32, ...) error
- func ConsumerGroupIndexKey(groupID string) string
- func ConsumerGroupKey(groupID string) string
- func ConsumerGroupPrefix() string
- func ConsumerOffsetKey(groupID, topic string, partition int32) string
- func DecodeConsumerGroup(data []byte) (*metadatapb.ConsumerGroup, error)
- func DecodePartitionState(data []byte) (*metadatapb.PartitionState, error)
- func DecodeTopicConfig(data []byte) (*metadatapb.TopicConfig, error)
- func DeleteConsumerGroupAndOffsets(ctx context.Context, store Store, groupID string) error
- func DeletedTopicKey(topic string, generation int64) string
- func EncodeConsumerGroup(group *metadatapb.ConsumerGroup) ([]byte, error)
- func EncodePartitionState(state *metadatapb.PartitionState) ([]byte, error)
- func EncodeTopicConfig(cfg *metadatapb.TopicConfig) ([]byte, error)
- func EtcdClientConfig(cfg clientv3.Config) clientv3.Config
- func FetchConsumerGroupRevision(ctx context.Context, store Store, groupID string) (*metadatapb.ConsumerGroup, int64, error)
- func GroupLeasePrefix() string
- func NewTopicID() [16]byte
- func ParseConsumerGroupID(key string) (string, bool)
- func ParseConsumerOffsetKey(key string) (string, string, int32, bool)
- func PartitionAssignmentKey(topic string, partition int32) string
- func PartitionLeasePrefix() string
- func PartitionStateKey(topic string, partition int32) string
- func PutConsumerGroupRevision(ctx context.Context, store Store, group *metadatapb.ConsumerGroup) (int64, error)
- func TopicConfigKey(topic string) string
- func TopicGenerationKey(topic string) string
- func TopicIDForName(name string) [16]byte
- func TopicStorageName(topic string, generation int64) string
- func ValidateTopicName(name string) error
- type AcquireResult
- type ClusterMetadata
- type ConsumerGroupDeleter
- type ConsumerGroupMemberOffsetCommitter
- type ConsumerGroupOffsetCommitter
- type ConsumerGroupRetainer
- type ConsumerGroupRetentionLister
- type ConsumerGroupRevisioner
- type ConsumerGroupSimpleOffsetCommitter
- type ConsumerOffset
- type DeletedTopic
- type EtcdStore
- func (s *EtcdStore) AllocateProducerID(ctx context.Context) (int64, error)
- func (s *EtcdStore) Available() bool
- func (s *EtcdStore) CheckReadiness(ctx context.Context) error
- func (s *EtcdStore) Close() error
- func (s *EtcdStore) CommitConsumerOffset(ctx context.Context, group, topic string, partition int32, offset int64, ...) error
- func (s *EtcdStore) CommitConsumerOffsetIfGroupExists(ctx context.Context, group string, createRevision int64, topic string, ...) error
- func (s *EtcdStore) CommitMemberConsumerOffset(ctx context.Context, group string, createRevision int64, memberID string, ...) error
- func (s *EtcdStore) CommitSimpleConsumerOffset(ctx context.Context, group, topic string, partition int32, offset int64, ...) error
- func (s *EtcdStore) CreatePartitions(ctx context.Context, topic string, partitionCount int32) error
- func (s *EtcdStore) CreateTopic(ctx context.Context, spec TopicSpec) (*protocol.MetadataTopic, error)
- func (s *EtcdStore) DeleteConsumerGroup(ctx context.Context, groupID string) error
- func (s *EtcdStore) DeleteConsumerGroupAndOffsets(ctx context.Context, groupID string) error
- func (s *EtcdStore) DeleteTopic(ctx context.Context, name string) error
- func (s *EtcdStore) EtcdClient() *clientv3.Client
- func (s *EtcdStore) ExpireConsumerGroup(ctx context.Context, id string, cutoff, now time.Time) (bool, error)
- func (s *EtcdStore) FetchConsumerGroup(ctx context.Context, groupID string) (*metadatapb.ConsumerGroup, error)
- func (s *EtcdStore) FetchConsumerGroupRevision(ctx context.Context, groupID string) (*metadatapb.ConsumerGroup, int64, error)
- func (s *EtcdStore) FetchConsumerOffset(ctx context.Context, group, topic string, partition int32) (int64, string, error)
- func (s *EtcdStore) FetchTopicConfig(ctx context.Context, topic string) (*metadatapb.TopicConfig, error)
- func (s *EtcdStore) ListConsumerGroups(ctx context.Context) ([]*metadatapb.ConsumerGroup, error)
- func (s *EtcdStore) ListConsumerGroupsForRetention(ctx context.Context, full bool) ([]*metadatapb.ConsumerGroup, error)
- func (s *EtcdStore) ListConsumerOffsets(ctx context.Context) ([]ConsumerOffset, error)
- func (s *EtcdStore) ListGroupConsumerOffsets(ctx context.Context, group string) ([]ConsumerOffset, error)
- func (s *EtcdStore) Metadata(ctx context.Context, topics []string) (*ClusterMetadata, error)
- func (s *EtcdStore) NextOffset(ctx context.Context, topic string, partition int32) (int64, error)
- func (s *EtcdStore) PutConsumerGroup(ctx context.Context, group *metadatapb.ConsumerGroup) error
- func (s *EtcdStore) PutConsumerGroupRevision(ctx context.Context, group *metadatapb.ConsumerGroup) (int64, error)
- func (s *EtcdStore) RefreshSnapshot(ctx context.Context) error
- func (s *EtcdStore) RetireTopic(ctx context.Context, name, namespace string) error
- func (s *EtcdStore) TopicGeneration(ctx context.Context, topic string) (int64, error)
- func (s *EtcdStore) UpdateOffsets(ctx context.Context, topic string, partition int32, lastOffset int64) error
- func (s *EtcdStore) UpdateOffsetsForLease(ctx context.Context, topic string, partition int32, lastOffset int64, ...) error
- func (s *EtcdStore) UpdateOffsetsForStorage(ctx context.Context, topic string, partition int32, lastOffset int64, ...) error
- func (s *EtcdStore) UpdateTopicConfig(ctx context.Context, cfg *metadatapb.TopicConfig) error
- type EtcdStoreConfig
- type GroupConsumerOffsetLister
- type GroupLeaseConfig
- type GroupLeaseManager
- func (m *GroupLeaseManager) Acquire(ctx context.Context, groupID string) error
- func (m *GroupLeaseManager) CurrentOwner(ctx context.Context, groupID string) (string, error)
- func (m *GroupLeaseManager) EtcdClient() *clientv3.Client
- func (m *GroupLeaseManager) Owns(groupID string) bool
- func (m *GroupLeaseManager) Release(groupID string)
- func (m *GroupLeaseManager) ReleaseAll()
- type GroupRoute
- type GroupRouter
- type InMemoryStore
- func (s *InMemoryStore) AllocateProducerID(ctx context.Context) (int64, error)
- func (s *InMemoryStore) CommitConsumerOffset(ctx context.Context, group, topic string, partition int32, offset int64, ...) error
- func (s *InMemoryStore) CommitConsumerOffsetIfGroupExists(ctx context.Context, group string, _ int64, topic string, partition int32, ...) error
- func (s *InMemoryStore) CommitMemberConsumerOffset(ctx context.Context, group string, _ int64, memberID string, generation int32, ...) error
- func (s *InMemoryStore) CommitSimpleConsumerOffset(ctx context.Context, group, topic string, partition int32, offset int64, ...) error
- func (s *InMemoryStore) CreatePartitions(ctx context.Context, topic string, partitionCount int32) error
- func (s *InMemoryStore) CreateTopic(ctx context.Context, spec TopicSpec) (*protocol.MetadataTopic, error)
- func (s *InMemoryStore) DeleteConsumerGroup(ctx context.Context, groupID string) error
- func (s *InMemoryStore) DeleteConsumerGroupAndOffsets(ctx context.Context, groupID string) error
- func (s *InMemoryStore) DeleteTopic(ctx context.Context, name string) error
- func (s *InMemoryStore) ExpireConsumerGroup(ctx context.Context, id string, cutoff, now time.Time) (bool, error)
- func (s *InMemoryStore) FetchConsumerGroup(ctx context.Context, groupID string) (*metadatapb.ConsumerGroup, error)
- func (s *InMemoryStore) FetchConsumerOffset(ctx context.Context, group, topic string, partition int32) (int64, string, error)
- func (s *InMemoryStore) FetchTopicConfig(ctx context.Context, topic string) (*metadatapb.TopicConfig, error)
- func (s *InMemoryStore) ListConsumerGroups(ctx context.Context) ([]*metadatapb.ConsumerGroup, error)
- func (s *InMemoryStore) ListConsumerOffsets(ctx context.Context) ([]ConsumerOffset, error)
- func (s *InMemoryStore) ListGroupConsumerOffsets(ctx context.Context, group string) ([]ConsumerOffset, error)
- func (s *InMemoryStore) Metadata(ctx context.Context, topics []string) (*ClusterMetadata, error)
- func (s *InMemoryStore) NextOffset(ctx context.Context, topic string, partition int32) (int64, error)
- func (s *InMemoryStore) PutConsumerGroup(ctx context.Context, group *metadatapb.ConsumerGroup) error
- func (s *InMemoryStore) Update(state ClusterMetadata)
- func (s *InMemoryStore) UpdateOffsets(ctx context.Context, topic string, partition int32, lastOffset int64) error
- func (s *InMemoryStore) UpdateTopicConfig(ctx context.Context, cfg *metadatapb.TopicConfig) error
- type LeaseManager
- func (m *LeaseManager) Acquire(ctx context.Context, resourceID string) error
- func (m *LeaseManager) CurrentOwner(ctx context.Context, resourceID string) (string, error)
- func (m *LeaseManager) EtcdClient() *clientv3.Client
- func (m *LeaseManager) OwnershipToken(resourceID string) uint64
- func (m *LeaseManager) Owns(resourceID string) bool
- func (m *LeaseManager) Prefix() string
- func (m *LeaseManager) Release(resourceID string)
- func (m *LeaseManager) ReleaseAll()
- type LeaseManagerConfig
- type LeaseManagerOptions
- type PartitionID
- type PartitionLeaseConfig
- type PartitionLeaseManager
- func (m *PartitionLeaseManager) Acquire(ctx context.Context, topic string, partition int32) error
- func (m *PartitionLeaseManager) AcquireAll(ctx context.Context, partitions []PartitionID) []AcquireResult
- func (m *PartitionLeaseManager) CurrentOwner(ctx context.Context, topic string, partition int32) (string, error)
- func (m *PartitionLeaseManager) CurrentOwners(ctx context.Context) (map[PartitionID]string, error)
- func (m *PartitionLeaseManager) EtcdClient() *clientv3.Client
- func (m *PartitionLeaseManager) Handover(topic string, partition int32, holdDuration time.Duration)
- func (m *PartitionLeaseManager) OwnershipToken(topic string, partition int32) uint64
- func (m *PartitionLeaseManager) Owns(topic string, partition int32) bool
- func (m *PartitionLeaseManager) Release(topic string, partition int32)
- func (m *PartitionLeaseManager) ReleaseAll()
- type PartitionLeaseOptions
- type PartitionRoute
- type PartitionRouter
- func (r *PartitionRouter) AllRoutes() []PartitionRoute
- func (r *PartitionRouter) Invalidate(topic string, partition int32)
- func (r *PartitionRouter) LookupOwner(topic string, partition int32) string
- func (r *PartitionRouter) Refresh(ctx context.Context, topic string, partition int32) error
- func (r *PartitionRouter) Stop()
- type ProducerIDAllocator
- type Store
- type TopicSpec
Examples ¶
Constants ¶
const ( TopicGenerationPrefix = "/kafscale/topic-generations/" DeletedTopicPrefix = "/kafscale/deleted-topics/" )
Variables ¶
var ( // ErrNotOwner is returned when a broker tries to write to a partition it does not own. ErrNotOwner = errors.New("broker does not own this partition") // ErrShuttingDown is returned when a lease acquisition is attempted after // ReleaseAll has been called. Callers should treat this the same as // ErrNotOwner — the broker is draining and should not accept new writes. ErrShuttingDown = errors.New("lease manager is shut down") )
var ( // ErrTopicExists indicates the topic is already present. ErrTopicExists = errors.New("topic already exists") // ErrInvalidTopic indicates the topic specification is invalid. ErrInvalidTopic = errors.New("invalid topic configuration") // ErrUnknownTopic indicates the topic does not exist. ErrUnknownTopic = errors.New("unknown topic") )
var ErrConsumerGroupChanged = errors.New("consumer group changed during deletion; retry")
var ErrConsumerGroupDeleted = errors.New("consumer group deleted")
var ErrConsumerGroupGenerationChanged = errors.New("consumer group generation changed")
var ErrConsumerGroupMemberGone = errors.New("consumer group member not found")
var ErrConsumerGroupNotEmpty = errors.New("consumer group has active members")
var ( ErrStoreUnavailable = errors.New("metadata store unavailable") )
var ErrTopicGenerationChanged = errors.New("topic generation changed")
Functions ¶
func BrokerRegistrationKey ¶
BrokerRegistrationKey returns the etcd key for broker liveness data.
func ConsumerGroupIndexKey ¶
func ConsumerGroupKey ¶
ConsumerGroupKey returns the etcd key for a consumer group metadata blob.
func ConsumerGroupPrefix ¶
func ConsumerGroupPrefix() string
ConsumerGroupPrefix returns the etcd prefix for consumer groups.
func ConsumerOffsetKey ¶
ConsumerOffsetKey returns the etcd key holding the committed offset for a partition.
func DecodeConsumerGroup ¶
func DecodeConsumerGroup(data []byte) (*metadatapb.ConsumerGroup, error)
DecodeConsumerGroup parses bytes into a ConsumerGroup struct.
func DecodePartitionState ¶
func DecodePartitionState(data []byte) (*metadatapb.PartitionState, error)
DecodePartitionState parses bytes into a PartitionState.
func DecodeTopicConfig ¶
func DecodeTopicConfig(data []byte) (*metadatapb.TopicConfig, error)
DecodeTopicConfig parses bytes into a TopicConfig object.
func DeletedTopicKey ¶
func EncodeConsumerGroup ¶
func EncodeConsumerGroup(group *metadatapb.ConsumerGroup) ([]byte, error)
EncodeConsumerGroup serializes a ConsumerGroup.
func EncodePartitionState ¶
func EncodePartitionState(state *metadatapb.PartitionState) ([]byte, error)
EncodePartitionState serializes a PartitionState into bytes.
func EncodeTopicConfig ¶
func EncodeTopicConfig(cfg *metadatapb.TopicConfig) ([]byte, error)
EncodeTopicConfig serializes a TopicConfig into etcd-ready bytes.
func FetchConsumerGroupRevision ¶
func FetchConsumerGroupRevision(ctx context.Context, store Store, groupID string) (*metadatapb.ConsumerGroup, int64, error)
func GroupLeasePrefix ¶
func GroupLeasePrefix() string
GroupLeasePrefix returns the etcd prefix for watching group leases.
func NewTopicID ¶ added in v2.1.0
func NewTopicID() [16]byte
NewTopicID allocates a random UUID for a new topic incarnation.
func ParseConsumerGroupID ¶
ParseConsumerGroupID extracts a group ID from a metadata key.
func ParseConsumerOffsetKey ¶
ParseConsumerOffsetKey extracts group, topic, and partition from an offset key.
func PartitionAssignmentKey ¶
PartitionAssignmentKey returns the etcd key for the current leader assignment.
func PartitionLeasePrefix ¶
func PartitionLeasePrefix() string
PartitionLeasePrefix returns the etcd prefix for watching partition leases.
func PartitionStateKey ¶
PartitionStateKey returns the etcd key for a partition state object.
func PutConsumerGroupRevision ¶
func PutConsumerGroupRevision(ctx context.Context, store Store, group *metadatapb.ConsumerGroup) (int64, error)
func TopicConfigKey ¶
TopicConfigKey returns the etcd key for a topic configuration object.
func TopicGenerationKey ¶
func TopicIDForName ¶
TopicIDForName returns the legacy name-derived ID. It is retained only for existing snapshots without an explicit ID; new topics use NewTopicID.
func TopicStorageName ¶
func ValidateTopicName ¶
Types ¶
type AcquireResult ¶
type AcquireResult struct {
Partition PartitionID
Err error
}
AcquireResult holds the outcome of a single partition lease acquisition.
type ClusterMetadata ¶
type ClusterMetadata struct {
Brokers []protocol.MetadataBroker
ControllerID int32
Topics []protocol.MetadataTopic
ClusterName *string
ClusterID *string
// TopicResourceUIDs identifies operator-managed Kubernetes resource incarnations.
// It is persisted atomically with topic IDs, never exposed in Kafka responses.
TopicResourceUIDs map[string]string `json:",omitempty"`
}
ClusterMetadata describes the Kafka-visible cluster state.
type ConsumerGroupDeleter ¶
type ConsumerGroupDeleter interface {
DeleteConsumerGroupAndOffsets(context.Context, string) error
}
ConsumerGroupDeleter is an optional capability for atomic group deletion. Store implementations predating this capability remain source compatible.
Example ¶
var store Store = NewInMemoryStore(ClusterMetadata{})
_, supportsAtomicDeletion := store.(ConsumerGroupDeleter)
fmt.Println(supportsAtomicDeletion)
Output: true
type ConsumerGroupOffsetCommitter ¶
type ConsumerGroupOffsetCommitter interface {
CommitConsumerOffsetIfGroupExists(ctx context.Context, group string, createRevision int64, topic string, partition int32, offset int64, metadata string) error
}
ConsumerGroupOffsetCommitter is an optional capability that refuses offset commits for a group whose metadata was deleted.
type ConsumerGroupRetainer ¶
type ConsumerGroupRetainer interface {
ExpireConsumerGroup(context.Context, string, time.Time, time.Time) (bool, error)
}
ConsumerGroupRetainer is optional: automatic expiry requires a store that can fence deletion against concurrent membership and offset changes.
type ConsumerGroupRetentionLister ¶
type ConsumerGroupRetentionLister interface {
ListConsumerGroupsForRetention(ctx context.Context, full bool) ([]*metadatapb.ConsumerGroup, error)
}
type ConsumerGroupRevisioner ¶
type ConsumerGroupRevisioner interface {
FetchConsumerGroupRevision(context.Context, string) (*metadatapb.ConsumerGroup, int64, error)
PutConsumerGroupRevision(context.Context, *metadatapb.ConsumerGroup) (int64, error)
}
type ConsumerOffset ¶
type ConsumerOffset struct {
Group string
Topic string
Partition int32
Offset int64
Metadata string
}
ConsumerOffset captures a committed offset entry.
func ListGroupConsumerOffsets ¶
func ListGroupConsumerOffsets(ctx context.Context, store Store, group string) ([]ConsumerOffset, error)
ListGroupConsumerOffsets uses a group-scoped lookup when available. Older Stores are adapted by filtering ListConsumerOffsets, preserving offset metadata and propagating errors. The fallback scans all groups and can be more expensive.
type DeletedTopic ¶
type EtcdStore ¶
type EtcdStore struct {
// contains filtered or unexported fields
}
EtcdStore uses etcd for offset persistence while delegating metadata to an in-memory snapshot.
func NewEtcdStore ¶
func NewEtcdStore(ctx context.Context, snapshot ClusterMetadata, cfg EtcdStoreConfig) (*EtcdStore, error)
NewEtcdStore initializes a store backed by etcd.
func (*EtcdStore) AllocateProducerID ¶ added in v2.1.0
AllocateProducerID uses a linearizable CAS. An ambiguous commit can waste an ID, but no response may expose an ID unless its allocation was confirmed.
func (*EtcdStore) CheckReadiness ¶
CheckReadiness checks live etcd access with a linearizable read. It does not rely on cached metadata or require maintenance permissions. The caller must supply a deadline; an absent snapshot is valid for an uninitialized cluster.
func (*EtcdStore) CommitConsumerOffset ¶
func (s *EtcdStore) CommitConsumerOffset(ctx context.Context, group, topic string, partition int32, offset int64, metadata string) error
CommitConsumerOffset implements Store.CommitConsumerOffset.
func (*EtcdStore) CommitConsumerOffsetIfGroupExists ¶
func (*EtcdStore) CommitMemberConsumerOffset ¶
func (*EtcdStore) CommitSimpleConsumerOffset ¶
func (*EtcdStore) CreatePartitions ¶
CreatePartitions expands a topic using the authoritative snapshot. Each batch publishes its partition states atomically with the matching snapshot revision.
func (*EtcdStore) CreateTopic ¶
func (s *EtcdStore) CreateTopic(ctx context.Context, spec TopicSpec) (*protocol.MetadataTopic, error)
CreateTopic applies only the requested creation to the latest etcd snapshot.
func (*EtcdStore) DeleteConsumerGroup ¶
DeleteConsumerGroup removes only keys owned by this group, including offsets. Batches are retryable if a store error interrupts deletion of a large group.
func (*EtcdStore) DeleteConsumerGroupAndOffsets ¶
DeleteConsumerGroupAndOffsets atomically removes only this group's keys.
func (*EtcdStore) DeleteTopic ¶
DeleteTopic updates the local snapshot so admin APIs behave consistently.
func (*EtcdStore) EtcdClient ¶
func (*EtcdStore) ExpireConsumerGroup ¶
func (*EtcdStore) FetchConsumerGroup ¶
func (s *EtcdStore) FetchConsumerGroup(ctx context.Context, groupID string) (*metadatapb.ConsumerGroup, error)
FetchConsumerGroup loads consumer group metadata from etcd.
func (*EtcdStore) FetchConsumerGroupRevision ¶
func (s *EtcdStore) FetchConsumerGroupRevision(ctx context.Context, groupID string) (*metadatapb.ConsumerGroup, int64, error)
func (*EtcdStore) FetchConsumerOffset ¶
func (s *EtcdStore) FetchConsumerOffset(ctx context.Context, group, topic string, partition int32) (int64, string, error)
FetchConsumerOffset implements Store.FetchConsumerOffset.
func (*EtcdStore) FetchTopicConfig ¶
func (s *EtcdStore) FetchTopicConfig(ctx context.Context, topic string) (*metadatapb.TopicConfig, error)
FetchTopicConfig loads topic configuration from etcd or falls back to defaults.
func (*EtcdStore) ListConsumerGroups ¶
func (s *EtcdStore) ListConsumerGroups(ctx context.Context) ([]*metadatapb.ConsumerGroup, error)
ListConsumerGroups discovers groups from keys without reading every offset value.
func (*EtcdStore) ListConsumerGroupsForRetention ¶
func (s *EtcdStore) ListConsumerGroupsForRetention(ctx context.Context, full bool) ([]*metadatapb.ConsumerGroup, error)
func (*EtcdStore) ListConsumerOffsets ¶
func (s *EtcdStore) ListConsumerOffsets(ctx context.Context) ([]ConsumerOffset, error)
ListConsumerOffsets returns all committed offsets stored in etcd.
func (*EtcdStore) ListGroupConsumerOffsets ¶
func (s *EtcdStore) ListGroupConsumerOffsets(ctx context.Context, group string) ([]ConsumerOffset, error)
ListGroupConsumerOffsets reads only the requested group's offset prefix.
func (*EtcdStore) Metadata ¶
Metadata delegates to the snapshot captured at startup (operator keeps it fresh).
func (*EtcdStore) NextOffset ¶
NextOffset reads the last committed offset from etcd and returns the next offset to assign.
func (*EtcdStore) PutConsumerGroup ¶
func (s *EtcdStore) PutConsumerGroup(ctx context.Context, group *metadatapb.ConsumerGroup) error
PutConsumerGroup persists consumer group metadata in etcd.
func (*EtcdStore) PutConsumerGroupRevision ¶
func (s *EtcdStore) PutConsumerGroupRevision(ctx context.Context, group *metadatapb.ConsumerGroup) (int64, error)
func (*EtcdStore) RefreshSnapshot ¶
RefreshSnapshot reloads cluster metadata from etcd. Callers use this to recover when the initial snapshot read failed or the watch stream was interrupted.
func (*EtcdStore) RetireTopic ¶
func (*EtcdStore) TopicGeneration ¶
func (*EtcdStore) UpdateOffsets ¶
func (s *EtcdStore) UpdateOffsets(ctx context.Context, topic string, partition int32, lastOffset int64) error
UpdateOffsets stores the next offset (last + 1) so future producers pick up from there.
func (*EtcdStore) UpdateOffsetsForLease ¶
func (s *EtcdStore) UpdateOffsetsForLease(ctx context.Context, topic string, partition int32, lastOffset int64, storageTopic string, revision uint64) error
UpdateOffsetsForLease rejects callbacks from an earlier partition acquisition.
func (*EtcdStore) UpdateOffsetsForStorage ¶
func (s *EtcdStore) UpdateOffsetsForStorage(ctx context.Context, topic string, partition int32, lastOffset int64, storageTopic string) error
UpdateOffsetsForStorage fences callbacks from logs belonging to a retired topic.
func (*EtcdStore) UpdateTopicConfig ¶
func (s *EtcdStore) UpdateTopicConfig(ctx context.Context, cfg *metadatapb.TopicConfig) error
UpdateTopicConfig commits settings against the same snapshot revision used by expansion. A delayed writer retries with the current partition count.
type EtcdStoreConfig ¶
type EtcdStoreConfig struct {
Endpoints []string
Username string
Password string
DialTimeout time.Duration
StorageNamespace string
}
EtcdStoreConfig defines how we connect to etcd for metadata/offsets.
type GroupConsumerOffsetLister ¶
type GroupConsumerOffsetLister interface {
ListGroupConsumerOffsets(context.Context, string) ([]ConsumerOffset, error)
}
GroupConsumerOffsetLister is an optional efficient group-scoped lookup. Implementations predating it remain valid Stores.
type GroupLeaseConfig ¶
GroupLeaseConfig configures the group lease manager.
type GroupLeaseManager ¶
type GroupLeaseManager struct {
// contains filtered or unexported fields
}
GroupLeaseManager uses etcd leases to ensure exclusive group coordination ownership. It delegates to the generic LeaseManager.
func NewGroupLeaseManager ¶
func NewGroupLeaseManager(client *clientv3.Client, cfg GroupLeaseConfig) *GroupLeaseManager
NewGroupLeaseManager creates a group lease manager backed by the given etcd client.
func (*GroupLeaseManager) Acquire ¶
func (m *GroupLeaseManager) Acquire(ctx context.Context, groupID string) error
Acquire tries to grab the group coordination lease. If this broker already owns it, it returns nil immediately. If another broker owns it, it returns ErrNotOwner.
func (*GroupLeaseManager) CurrentOwner ¶
CurrentOwner queries etcd to find the current owner of a group. Returns the broker ID of the owner, or empty string if unowned.
func (*GroupLeaseManager) EtcdClient ¶
func (m *GroupLeaseManager) EtcdClient() *clientv3.Client
EtcdClient returns the underlying etcd client.
func (*GroupLeaseManager) Owns ¶
func (m *GroupLeaseManager) Owns(groupID string) bool
Owns returns true if this broker currently holds the lease for the group.
func (*GroupLeaseManager) Release ¶
func (m *GroupLeaseManager) Release(groupID string)
Release explicitly gives up ownership of a single group.
func (*GroupLeaseManager) ReleaseAll ¶
func (m *GroupLeaseManager) ReleaseAll()
ReleaseAll releases all group leases. Called during graceful shutdown.
type GroupRoute ¶
GroupRoute maps a group ID to the broker that currently coordinates it.
type GroupRouter ¶
type GroupRouter struct {
// contains filtered or unexported fields
}
GroupRouter watches etcd group lease keys and maintains an in-memory routing table. The proxy uses this to send group coordination requests to the correct broker without round-tripping to etcd on every request.
func NewGroupRouter ¶
func NewGroupRouter(ctx context.Context, client *clientv3.Client, logger *slog.Logger) (*GroupRouter, error)
NewGroupRouter creates a router and starts watching etcd for group lease changes.
func (*GroupRouter) AllRoutes ¶
func (r *GroupRouter) AllRoutes() []GroupRoute
AllRoutes returns a snapshot of the current routing table.
func (*GroupRouter) Invalidate ¶
func (r *GroupRouter) Invalidate(groupID string)
Invalidate removes a group from the routing table. Called when the proxy discovers (via NOT_COORDINATOR) that the cached route is stale. The next watch event will repopulate it with the correct owner.
func (*GroupRouter) LookupOwner ¶
func (r *GroupRouter) LookupOwner(groupID string) string
LookupOwner returns the broker ID that coordinates a group, or "" if unknown/unowned.
type InMemoryStore ¶
type InMemoryStore struct {
// contains filtered or unexported fields
}
InMemoryStore is a simple Store backed by in-process state. Useful for early development and tests.
func NewInMemoryStore ¶
func NewInMemoryStore(state ClusterMetadata) *InMemoryStore
NewInMemoryStore builds an in-memory metadata store with the provided state.
func (*InMemoryStore) AllocateProducerID ¶ added in v2.1.0
func (s *InMemoryStore) AllocateProducerID(ctx context.Context) (int64, error)
func (*InMemoryStore) CommitConsumerOffset ¶
func (s *InMemoryStore) CommitConsumerOffset(ctx context.Context, group, topic string, partition int32, offset int64, metadata string) error
CommitConsumerOffset implements Store.CommitConsumerOffset.
func (*InMemoryStore) CommitConsumerOffsetIfGroupExists ¶
func (*InMemoryStore) CommitMemberConsumerOffset ¶
func (*InMemoryStore) CommitSimpleConsumerOffset ¶
func (*InMemoryStore) CreatePartitions ¶
func (s *InMemoryStore) CreatePartitions(ctx context.Context, topic string, partitionCount int32) error
CreatePartitions implements Store.CreatePartitions.
func (*InMemoryStore) CreateTopic ¶
func (s *InMemoryStore) CreateTopic(ctx context.Context, spec TopicSpec) (*protocol.MetadataTopic, error)
CreateTopic implements Store.CreateTopic.
func (*InMemoryStore) DeleteConsumerGroup ¶
func (s *InMemoryStore) DeleteConsumerGroup(ctx context.Context, groupID string) error
DeleteConsumerGroup implements Store.DeleteConsumerGroup.
func (*InMemoryStore) DeleteConsumerGroupAndOffsets ¶
func (s *InMemoryStore) DeleteConsumerGroupAndOffsets(ctx context.Context, groupID string) error
DeleteConsumerGroupAndOffsets is used only for an explicit group deletion.
func (*InMemoryStore) DeleteTopic ¶
func (s *InMemoryStore) DeleteTopic(ctx context.Context, name string) error
DeleteTopic implements Store.DeleteTopic.
func (*InMemoryStore) ExpireConsumerGroup ¶
func (*InMemoryStore) FetchConsumerGroup ¶
func (s *InMemoryStore) FetchConsumerGroup(ctx context.Context, groupID string) (*metadatapb.ConsumerGroup, error)
FetchConsumerGroup implements Store.FetchConsumerGroup.
func (*InMemoryStore) FetchConsumerOffset ¶
func (s *InMemoryStore) FetchConsumerOffset(ctx context.Context, group, topic string, partition int32) (int64, string, error)
FetchConsumerOffset implements Store.FetchConsumerOffset.
func (*InMemoryStore) FetchTopicConfig ¶
func (s *InMemoryStore) FetchTopicConfig(ctx context.Context, topic string) (*metadatapb.TopicConfig, error)
FetchTopicConfig implements Store.FetchTopicConfig.
func (*InMemoryStore) ListConsumerGroups ¶
func (s *InMemoryStore) ListConsumerGroups(ctx context.Context) ([]*metadatapb.ConsumerGroup, error)
ListConsumerGroups implements Store.ListConsumerGroups.
func (*InMemoryStore) ListConsumerOffsets ¶
func (s *InMemoryStore) ListConsumerOffsets(ctx context.Context) ([]ConsumerOffset, error)
ListConsumerOffsets implements Store.ListConsumerOffsets.
func (*InMemoryStore) ListGroupConsumerOffsets ¶
func (s *InMemoryStore) ListGroupConsumerOffsets(ctx context.Context, group string) ([]ConsumerOffset, error)
ListGroupConsumerOffsets implements GroupConsumerOffsetLister.
func (*InMemoryStore) Metadata ¶
func (s *InMemoryStore) Metadata(ctx context.Context, topics []string) (*ClusterMetadata, error)
Metadata implements Store.
func (*InMemoryStore) NextOffset ¶
func (s *InMemoryStore) NextOffset(ctx context.Context, topic string, partition int32) (int64, error)
NextOffset implements Store.NextOffset.
func (*InMemoryStore) PutConsumerGroup ¶
func (s *InMemoryStore) PutConsumerGroup(ctx context.Context, group *metadatapb.ConsumerGroup) error
PutConsumerGroup implements Store.PutConsumerGroup.
func (*InMemoryStore) Update ¶
func (s *InMemoryStore) Update(state ClusterMetadata)
Update swaps the cluster metadata atomically.
func (*InMemoryStore) UpdateOffsets ¶
func (s *InMemoryStore) UpdateOffsets(ctx context.Context, topic string, partition int32, lastOffset int64) error
UpdateOffsets implements Store.UpdateOffsets.
func (*InMemoryStore) UpdateTopicConfig ¶
func (s *InMemoryStore) UpdateTopicConfig(ctx context.Context, cfg *metadatapb.TopicConfig) error
UpdateTopicConfig implements Store.UpdateTopicConfig.
type LeaseManager ¶
type LeaseManager struct {
// contains filtered or unexported fields
}
LeaseManager uses etcd leases to ensure exclusive ownership of named resources.
All lease keys are attached to a single shared etcd session/lease, so the keepalive cost is O(1) regardless of resource count. When the session dies (broker crash, network partition), etcd expires all keys after the TTL and the manager bulk-clears its local ownership map.
Concurrent Acquire calls for the same resource are deduplicated via singleflight to avoid redundant etcd round-trips and session leaks.
func NewLeaseManager ¶
func NewLeaseManager(client *clientv3.Client, cfg LeaseManagerConfig) *LeaseManager
NewLeaseManager creates a lease manager backed by the given etcd client.
func NewLeaseManagerWithOptions ¶
func NewLeaseManagerWithOptions(client *clientv3.Client, cfg LeaseManagerOptions) *LeaseManager
NewLeaseManagerWithOptions constructs a manager with ownership callbacks.
func (*LeaseManager) Acquire ¶
func (m *LeaseManager) Acquire(ctx context.Context, resourceID string) error
Acquire tries to grab the lease for the named resource. If this broker already owns it, it returns nil immediately. If another broker owns it, it returns ErrNotOwner.
func (*LeaseManager) CurrentOwner ¶
CurrentOwner queries etcd to find the current owner of a resource. Returns the broker ID of the owner, or empty string if unowned.
func (*LeaseManager) EtcdClient ¶
func (m *LeaseManager) EtcdClient() *clientv3.Client
EtcdClient returns the underlying etcd client. Used by routers that need to watch the same prefix.
func (*LeaseManager) OwnershipToken ¶
func (m *LeaseManager) OwnershipToken(resourceID string) uint64
OwnershipToken identifies one uninterrupted acquisition, or zero if not owned. Check session.Done directly so callers never depend on monitor scheduling.
func (*LeaseManager) Owns ¶
func (m *LeaseManager) Owns(resourceID string) bool
Owns returns true if this broker currently holds a live lease.
func (*LeaseManager) Prefix ¶
func (m *LeaseManager) Prefix() string
Prefix returns the etcd prefix for watching leases.
func (*LeaseManager) Release ¶
func (m *LeaseManager) Release(resourceID string)
Release explicitly gives up ownership of a single resource.
func (*LeaseManager) ReleaseAll ¶
func (m *LeaseManager) ReleaseAll()
ReleaseAll releases all leases. Called during graceful shutdown.
type LeaseManagerConfig ¶
type LeaseManagerConfig struct {
BrokerID string
Prefix string // etcd key prefix, e.g. "/kafscale/partition-leases"
LeaseTTLSeconds int
Logger *slog.Logger
ResourceKind string // used in log messages, e.g. "partition" or "group"
}
LeaseManagerConfig configures a generic lease manager.
type LeaseManagerOptions ¶
type LeaseManagerOptions struct {
LeaseManagerConfig
// OnLost runs under the ownership lock; it must not call back into this manager.
OnLost func(resourceID string, token uint64)
}
LeaseManagerOptions adds ownership callbacks without changing the published config.
type PartitionID ¶
PartitionID identifies a topic-partition pair.
type PartitionLeaseConfig ¶
type PartitionLeaseConfig struct {
// BrokerID identifies this broker in lease keys.
BrokerID string
// LeaseTTLSeconds controls how long a lease persists after the broker stops refreshing.
LeaseTTLSeconds int
// Logger for operational messages.
Logger *slog.Logger
}
PartitionLeaseConfig configures the lease manager.
type PartitionLeaseManager ¶
type PartitionLeaseManager struct {
// contains filtered or unexported fields
}
PartitionLeaseManager uses etcd leases to ensure exclusive partition ownership. It delegates to the generic LeaseManager, translating topic+partition pairs into string resource IDs.
func NewPartitionLeaseManager ¶
func NewPartitionLeaseManager(client *clientv3.Client, cfg PartitionLeaseConfig) *PartitionLeaseManager
NewPartitionLeaseManager creates a lease manager backed by the given etcd client.
func NewPartitionLeaseManagerWithOptions ¶
func NewPartitionLeaseManagerWithOptions(client *clientv3.Client, cfg PartitionLeaseOptions) *PartitionLeaseManager
NewPartitionLeaseManagerWithOptions constructs a manager with ownership callbacks.
func (*PartitionLeaseManager) Acquire ¶
Acquire tries to grab the partition lease. If this broker already owns it, it returns nil immediately. If another broker owns it, it returns ErrNotOwner.
func (*PartitionLeaseManager) AcquireAll ¶
func (m *PartitionLeaseManager) AcquireAll(ctx context.Context, partitions []PartitionID) []AcquireResult
AcquireAll attempts to acquire leases for all given partitions concurrently. Partitions already owned by this broker are skipped (no etcd round-trip). Returns a result per partition; callers should check each Err.
func (*PartitionLeaseManager) CurrentOwner ¶
func (m *PartitionLeaseManager) CurrentOwner(ctx context.Context, topic string, partition int32) (string, error)
CurrentOwner queries etcd to find the current owner of a partition. Returns the broker ID of the owner, or empty string if unowned.
func (*PartitionLeaseManager) CurrentOwners ¶
func (m *PartitionLeaseManager) CurrentOwners(ctx context.Context) (map[PartitionID]string, error)
CurrentOwners reads one authoritative snapshot for a broker Metadata response.
func (*PartitionLeaseManager) EtcdClient ¶
func (m *PartitionLeaseManager) EtcdClient() *clientv3.Client
EtcdClient returns the underlying etcd client.
func (*PartitionLeaseManager) Handover ¶
func (m *PartitionLeaseManager) Handover(topic string, partition int32, holdDuration time.Duration)
Handover releases a partition and prevents reacquisition for the hold duration.
func (*PartitionLeaseManager) OwnershipToken ¶
func (m *PartitionLeaseManager) OwnershipToken(topic string, partition int32) uint64
OwnershipToken identifies the current uninterrupted partition acquisition.
func (*PartitionLeaseManager) Owns ¶
func (m *PartitionLeaseManager) Owns(topic string, partition int32) bool
Owns returns true if this broker currently holds the lease for the partition.
func (*PartitionLeaseManager) Release ¶
func (m *PartitionLeaseManager) Release(topic string, partition int32)
Release explicitly gives up ownership of a single partition.
func (*PartitionLeaseManager) ReleaseAll ¶
func (m *PartitionLeaseManager) ReleaseAll()
ReleaseAll releases all partition leases. Called during graceful shutdown.
type PartitionLeaseOptions ¶
type PartitionLeaseOptions struct {
PartitionLeaseConfig
// OnLost invalidates state for an expired or released acquisition. It must not call this manager.
OnLost func(topic string, partition int32, token uint64)
// OnHandover runs after new acquisitions are blocked. It must finish active
// writes and invoke release before returning. It runs without ownership locks.
OnHandover func(topic string, partition int32, release func())
}
PartitionLeaseOptions adds callbacks without changing the published config.
type PartitionRoute ¶
PartitionRoute maps a topic/partition to the broker that currently owns it.
type PartitionRouter ¶
type PartitionRouter struct {
// contains filtered or unexported fields
}
PartitionRouter watches etcd partition lease keys and maintains an in-memory routing table. The proxy uses this to send produce requests to the correct broker without round-tripping to etcd on every request.
The routing table is best-effort: it can be briefly stale after a lease change. The broker's own ownership check is the authoritative guard.
func NewPartitionRouter ¶
func NewPartitionRouter(ctx context.Context, client *clientv3.Client, logger *slog.Logger) (*PartitionRouter, error)
NewPartitionRouter creates a router and starts watching etcd for lease changes.
func (*PartitionRouter) AllRoutes ¶
func (r *PartitionRouter) AllRoutes() []PartitionRoute
AllRoutes returns a snapshot of the current routing table.
func (*PartitionRouter) Invalidate ¶
func (r *PartitionRouter) Invalidate(topic string, partition int32)
Invalidate removes a partition from the routing table. Called when the proxy discovers (via NOT_LEADER_OR_FOLLOWER) that the cached route is stale. The next watch event will repopulate it with the correct owner.
func (*PartitionRouter) LookupOwner ¶
func (r *PartitionRouter) LookupOwner(topic string, partition int32) string
LookupOwner returns the broker ID that owns a partition, or "" if unknown/unowned.
func (*PartitionRouter) Stop ¶
func (r *PartitionRouter) Stop()
Stop terminates the background watcher.
type ProducerIDAllocator ¶ added in v2.1.0
ProducerIDAllocator is optional so existing Store implementations remain valid. Every nontransactional InitProducerId allocates a fresh ID with epoch zero.
type Store ¶
type Store interface {
// Metadata returns brokers, controller ID, and topics. When topics is non-empty,
// the implementation should filter to that subset and omit missing topics.
Metadata(ctx context.Context, topics []string) (*ClusterMetadata, error)
// NextOffset returns the next offset to assign for a topic/partition.
NextOffset(ctx context.Context, topic string, partition int32) (int64, error)
// UpdateOffsets records the last persisted offset so future appends continue from there.
UpdateOffsets(ctx context.Context, topic string, partition int32, lastOffset int64) error
// CommitConsumerOffset persists a consumer group offset.
CommitConsumerOffset(ctx context.Context, group, topic string, partition int32, offset int64, metadata string) error
// FetchConsumerOffset retrieves the committed offset for a consumer group partition.
FetchConsumerOffset(ctx context.Context, group, topic string, partition int32) (int64, string, error)
// ListConsumerOffsets returns all committed consumer offsets.
ListConsumerOffsets(ctx context.Context) ([]ConsumerOffset, error)
// PutConsumerGroup persists consumer group metadata.
PutConsumerGroup(ctx context.Context, group *metadatapb.ConsumerGroup) error
// FetchConsumerGroup retrieves consumer group metadata.
FetchConsumerGroup(ctx context.Context, groupID string) (*metadatapb.ConsumerGroup, error)
// ListConsumerGroups returns group metadata, including Empty groups discovered from offset keys.
ListConsumerGroups(ctx context.Context) ([]*metadatapb.ConsumerGroup, error)
// DeleteConsumerGroup removes consumer group metadata and all committed offsets.
DeleteConsumerGroup(ctx context.Context, groupID string) error
// FetchTopicConfig returns the stored topic configuration.
FetchTopicConfig(ctx context.Context, topic string) (*metadatapb.TopicConfig, error)
// UpdateTopicConfig persists topic configuration updates.
UpdateTopicConfig(ctx context.Context, cfg *metadatapb.TopicConfig) error
// CreatePartitions expands a topic's partition count.
CreatePartitions(ctx context.Context, topic string, partitionCount int32) error
// CreateTopic creates a new topic with the provided specification.
CreateTopic(ctx context.Context, spec TopicSpec) (*protocol.MetadataTopic, error)
// DeleteTopic removes a topic and associated offsets.
DeleteTopic(ctx context.Context, name string) error
}
Store exposes read-only access to cluster metadata used by Kafka protocol handlers.
Source Files
¶
- codec.go
- consumer_group_delete.go
- consumer_group_index.go
- consumer_group_retention.go
- consumer_group_writer.go
- etcd_client.go
- etcd_store.go
- group_lease.go
- group_offsets.go
- group_router.go
- lease_manager.go
- partition_lease.go
- partition_router.go
- producer_id.go
- readiness.go
- snapshot_mutation.go
- store.go
- topic_generation.go
- topic_name.go
- topicid.go