shard

package
v0.0.0-...-9345cf8 Latest Latest
Warning

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

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

README

基于etcd的通用分布式分片管理

用于相同服务不同实例之间的分片协调分配,使用场景比如分布式任务扫描。

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

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

注册当前实例 + 监听其它实例 并更新本地分片信息

创建租约 -> 续约租约 监听key -> 更新本地分片信息

func NewManager

func NewManager(
	cli *etcdv3.Client,
	keyPrefix string,
	keyId string,
	opts ...Option,
) *Manager

func (*Manager) GetShard

func (m *Manager) GetShard() Shard

func (*Manager) Start

func (m *Manager) Start(ctx context.Context) error

func (*Manager) Stop

func (m *Manager) Stop()

type Option

type Option func(*option)

func WithKeepaliveRetryWaitSec

func WithKeepaliveRetryWaitSec(sec int64) Option

func WithTTL

func WithTTL(ttlSec int64) Option

type Shard

type Shard struct {
	// 全部实例的key列表
	Keys []string `json:"keys"`

	// 当前实例索引
	Index int `json:"index"`

	// 总实例数量
	Total int `json:"total"`

	// 是否活跃
	Active bool `json:"active"`

	// 当前实例信息的最后更新时间
	LastUpdateAt time.Time `json:"last_update_at"`
}

当前实例的分片信息

func (*Shard) Equal

func (s *Shard) Equal(other *Shard) bool

Jump to

Keyboard shortcuts

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