sharding

package
v0.15.13 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2020 License: Apache-2.0 Imports: 5 Imported by: 5 modules, 32 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDuplicateShards returned when shard set is empty
	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 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

	// 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