sharding

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: Apache-2.0 Imports: 7 Imported by: 32

Documentation

Overview

Package sharding is a generated GoMock package.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDuplicateShards returned when shard set contains duplicate shards
	ErrDuplicateShards = errors.New("duplicate shards")

	// ErrInvalidShardID is returned on an invalid shard ID
	ErrInvalidShardID = errors.New("no shard with given ID")
)

Functions

func IDs

func IDs(shards []shard.Shard) []uint32

IDs returns a new slice of shard IDs for a set of shards

func NewShards

func NewShards(ids []uint32, state shard.State) []shard.Shard

NewShards returns a new slice of shards with a specified state

Types

type HashFn

type HashFn func(id ident.ID) uint32

HashFn is a sharding hash function.

func DefaultHashFn

func DefaultHashFn(length int) HashFn

DefaultHashFn generates a HashFn based on murmur32

func NewHashFn

func NewHashFn(length int, seed uint32) HashFn

NewHashFn generates a HashFN based on murmur32 with a given seed

type HashGen

type HashGen func(length int) HashFn

HashGen generates HashFn based on the length of shards.

func NewHashGenWithSeed

func NewHashGenWithSeed(seed uint32) HashGen

NewHashGenWithSeed generates a HashFnGen based on murmur32 with a given seed

type MockShardSet added in v1.6.0

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

MockShardSet is a mock of ShardSet interface.

func NewMockShardSet added in v1.6.0

func NewMockShardSet(ctrl *gomock.Controller) *MockShardSet

NewMockShardSet creates a new mock instance.

func (*MockShardSet) All added in v1.6.0

func (m *MockShardSet) All() []shard.Shard

All mocks base method.

func (*MockShardSet) AllIDs added in v1.6.0

func (m *MockShardSet) AllIDs() []uint32

AllIDs mocks base method.

func (*MockShardSet) EXPECT added in v1.6.0

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockShardSet) HashFn added in v1.6.0

func (m *MockShardSet) HashFn() HashFn

HashFn mocks base method.

func (*MockShardSet) Lookup added in v1.6.0

func (m *MockShardSet) Lookup(id ident.ID) uint32

Lookup mocks base method.

func (*MockShardSet) LookupShard added in v1.6.0

func (m *MockShardSet) LookupShard(id uint32) (shard.Shard, error)

LookupShard mocks base method.

func (*MockShardSet) LookupStateByID added in v1.6.0

func (m *MockShardSet) LookupStateByID(shardID uint32) (shard.State, error)

LookupStateByID mocks base method.

func (*MockShardSet) Max added in v1.6.0

func (m *MockShardSet) Max() uint32

Max mocks base method.

func (*MockShardSet) Min added in v1.6.0

func (m *MockShardSet) Min() uint32

Min mocks base method.

type MockShardSetMockRecorder added in v1.6.0

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

MockShardSetMockRecorder is the mock recorder for MockShardSet.

func (*MockShardSetMockRecorder) All added in v1.6.0

All indicates an expected call of All.

func (*MockShardSetMockRecorder) AllIDs added in v1.6.0

func (mr *MockShardSetMockRecorder) AllIDs() *gomock.Call

AllIDs indicates an expected call of AllIDs.

func (*MockShardSetMockRecorder) HashFn added in v1.6.0

func (mr *MockShardSetMockRecorder) HashFn() *gomock.Call

HashFn indicates an expected call of HashFn.

func (*MockShardSetMockRecorder) Lookup added in v1.6.0

func (mr *MockShardSetMockRecorder) Lookup(id interface{}) *gomock.Call

Lookup indicates an expected call of Lookup.

func (*MockShardSetMockRecorder) LookupShard added in v1.6.0

func (mr *MockShardSetMockRecorder) LookupShard(id interface{}) *gomock.Call

LookupShard indicates an expected call of LookupShard.

func (*MockShardSetMockRecorder) LookupStateByID added in v1.6.0

func (mr *MockShardSetMockRecorder) LookupStateByID(shardID interface{}) *gomock.Call

LookupStateByID indicates an expected call of LookupStateByID.

func (*MockShardSetMockRecorder) Max added in v1.6.0

Max indicates an expected call of Max.

func (*MockShardSetMockRecorder) Min added in v1.6.0

Min indicates an expected call of Min.

type ShardSet

type ShardSet interface {
	// All returns a slice to the shards in this set.
	All() []shard.Shard

	// AllIDs returns a slice to the shard IDs in this set.
	AllIDs() []uint32

	// Lookup will return a shard for a given identifier.
	Lookup(id ident.ID) uint32

	// LookupShard will return a shard for a given shard id.
	LookupShard(id uint32) (shard.Shard, error)

	// LookupStateByID returns the state of the shard with a given ID.
	LookupStateByID(shardID uint32) (shard.State, error)

	// Min returns the smallest shard owned by this shard set.
	Min() uint32

	// Max returns the largest shard owned by this shard set.
	Max() uint32

	// HashFn returns the sharding hash function.
	HashFn() HashFn
}

ShardSet contains a sharding function and a set of shards, this interface allows for potentially out of order shard sets.

func NewEmptyShardSet

func NewEmptyShardSet(fn HashFn) ShardSet

NewEmptyShardSet creates a new sharding scheme with an empty set of shards

func NewShardSet

func NewShardSet(shards []shard.Shard, fn HashFn) (ShardSet, error)

NewShardSet creates a new sharding scheme with a set of shards

Jump to

Keyboard shortcuts

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