Documentation
¶
Index ¶
- Variables
- func NewNoopRehasher() *noopRehasher
- func OldShardIndex(key string, mask uint32) uint32
- func Register(name string, factory RehasherFactory) error
- type BatchRehasher
- func (r *BatchRehasher) IsRehashing() bool
- func (r *BatchRehasher) Name() string
- func (r *BatchRehasher) OldShard(key string) Shard
- func (r *BatchRehasher) OldShards() []Shard
- func (r *BatchRehasher) Start(oldShards []Shard, oldMask uint32)
- func (r *BatchRehasher) Step(newShards []Shard, indexFunc func(key string) uint32) (done bool, justCompleted bool)
- func (r *BatchRehasher) Stop()
- type IncrementalRehasher
- func (r *IncrementalRehasher) IsRehashing() bool
- func (r *IncrementalRehasher) Name() string
- func (r *IncrementalRehasher) OldShard(key string) Shard
- func (r *IncrementalRehasher) OldShards() []Shard
- func (r *IncrementalRehasher) Start(oldShards []Shard, oldMask uint32)
- func (r *IncrementalRehasher) Step(newShards []Shard, indexFunc func(key string) uint32) (done bool, justCompleted bool)
- func (r *IncrementalRehasher) Stop()
- type Item
- type Rehasher
- type RehasherFactory
- type Shard
Constants ¶
This section is empty.
Variables ¶
var ErrUnknownRehasher = errors.New("unknown rehasher")
Functions ¶
func NewNoopRehasher ¶
func NewNoopRehasher() *noopRehasher
NewNoopRehasher creates a no-op rehasher.
func OldShardIndex ¶
OldShardIndex computes the shard index for a key using the given mask.
func Register ¶
func Register(name string, factory RehasherFactory) error
Register adds a custom rehasher factory under the given name.
Types ¶
type BatchRehasher ¶
type BatchRehasher struct {
// contains filtered or unexported fields
}
BatchRehasher migrates all remaining entries in a single Step call. This causes a one-time latency spike but avoids prolonged double-table overhead. Useful when downtime or brief pauses are acceptable.
func NewBatchRehasher ¶
func NewBatchRehasher() *BatchRehasher
NewBatchRehasher creates a batch rehasher.
func (*BatchRehasher) IsRehashing ¶
func (r *BatchRehasher) IsRehashing() bool
func (*BatchRehasher) Name ¶
func (r *BatchRehasher) Name() string
func (*BatchRehasher) OldShard ¶
func (r *BatchRehasher) OldShard(key string) Shard
func (*BatchRehasher) OldShards ¶
func (r *BatchRehasher) OldShards() []Shard
func (*BatchRehasher) Start ¶
func (r *BatchRehasher) Start(oldShards []Shard, oldMask uint32)
func (*BatchRehasher) Stop ¶
func (r *BatchRehasher) Stop()
type IncrementalRehasher ¶
type IncrementalRehasher struct {
// contains filtered or unexported fields
}
IncrementalRehasher performs migration gradually, moving a fixed batch of entries on each Step call (Redis-style). This minimizes latency spikes but spreads migration overhead across normal operations.
func NewIncrementalRehasher ¶
func NewIncrementalRehasher() *IncrementalRehasher
NewIncrementalRehasher creates an incremental rehasher with a default batch size of 16 entries per step.
func (*IncrementalRehasher) IsRehashing ¶
func (r *IncrementalRehasher) IsRehashing() bool
func (*IncrementalRehasher) Name ¶
func (r *IncrementalRehasher) Name() string
func (*IncrementalRehasher) OldShard ¶
func (r *IncrementalRehasher) OldShard(key string) Shard
func (*IncrementalRehasher) OldShards ¶
func (r *IncrementalRehasher) OldShards() []Shard
func (*IncrementalRehasher) Start ¶
func (r *IncrementalRehasher) Start(oldShards []Shard, oldMask uint32)
func (*IncrementalRehasher) Stop ¶
func (r *IncrementalRehasher) Stop()
type Rehasher ¶
type Rehasher interface {
Name() string
// Start begins a rehash with the old shard table and mask.
Start(oldShards []Shard, oldMask uint32)
// Step executes one migration step into newShards using indexFunc to locate
// the destination shard. It returns (done, justCompleted) where done is true
// if the rehash is fully complete, and justCompleted is true only when this
// specific call caused the rehash to finish.
Step(newShards []Shard, indexFunc func(key string) uint32) (done bool, justCompleted bool)
// IsRehashing reports whether a rehash is currently in progress.
IsRehashing() bool
// OldShard returns the shard in the old table responsible for key, or nil.
OldShard(key string) Shard
// OldShards returns the full old shard table, or nil if not rehashing.
// Callers must not modify the returned shards.
OldShards() []Shard
// Stop forcibly aborts the rehash and releases old state.
Stop()
}
Rehasher defines a pluggable strategy for migrating data from an old shard layout to a new one. Implementations control the pacing and granularity of the migration.
type RehasherFactory ¶
type RehasherFactory func() Rehasher
RehasherFactory creates a fresh Rehasher instance.
func GetFactory ¶
func GetFactory(name string) (RehasherFactory, error)
GetFactory retrieves a rehasher factory by name.