shuffleshard

package
v0.0.0-...-d799a11 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoShardsAvailable = errors.New("no shards available")
View Source
var ErrShardAlreadyExists = errors.New("shard already exists")

Functions

This section is empty.

Types

type ShardStore

type ShardStore interface {
	ShardExists(ctx context.Context, shardHash string) (bool, error)
}

type Sharder

type Sharder[T any] struct {
	// Endpoints are a list of endpoints to generate shuffle shards from
	Endpoints []T

	// ReplicationFactor is the size of an individual shuffle shard
	ReplicationFactor int

	// ShardStore is a storage of all existing shuffle shards.
	// Sharder queries this store to ensure that a shuffle shard isn't allocated twice.
	// ShuffleShards are stored by a unique, deterministic key; a hash of the shard.
	ShardStore ShardStore

	// ShardKeyFunc is a function that receives a shuffle shard & returns a hash of its value.
	// It is used to lookup a shard for existence in the ShardStore.
	// It must not modify the received shuffle shard, instead make a deep copy of the parameter.
	ShardKeyFunc func([]T) (string, error)

	Rand *rand.Rand
}

func (*Sharder[T]) ShuffleShard

func (s *Sharder[T]) ShuffleShard(ctx context.Context) ([]T, error)

Jump to

Keyboard shortcuts

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