shard

package
v1.8.16 Latest Latest
Warning

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

Go to latest
Published: May 27, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IntShardID

type IntShardID struct {
	SrcID   int64
	ShardID int64
	TypeID  int64
	LocalID int64
}

IntShardID is a numeric unique identifier that includes shard information

func BuildIntShardID

func BuildIntShardID(shardID, typeID, localID int64) IntShardID

BuildIntShardID builds an integer ID

func ParseIntShardID

func ParseIntShardID(id int64) IntShardID

ParseIntShardID parses an intID into a ShardID object

type ShardID

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

func NewShardID

func NewShardID(shard, sequence int64) *ShardID

func NewShardIDFromID

func NewShardIDFromID(id int64) *ShardID

func (*ShardID) Hash

func (s *ShardID) Hash() uint32

hash does an FNV1a hash of the string

func (*ShardID) ID

func (s *ShardID) ID() int64

ID returns the id of the shard

func (*ShardID) Sequence

func (s *ShardID) Sequence() int64

func (*ShardID) Shard

func (s *ShardID) Shard() int64

func (*ShardID) String

func (s *ShardID) String() string

func (*ShardID) Timestamp

func (s *ShardID) Timestamp() int64

type Sharder

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

func NewSharder

func NewSharder(numberOfShards int64) *Sharder

func (*Sharder) CurrentShardID

func (s *Sharder) CurrentShardID() int64

func (*Sharder) GetShardFromSubID added in v1.8.8

func (s *Sharder) GetShardFromSubID(subID int64) int64

GetShardFromSubID returns the shard number without incrementing the internal sequence

func (*Sharder) NewFromString

func (s *Sharder) NewFromString(str string) (shardID *ShardID, e error)

NewFromString mods the first N characters of string str against the number of shards Throws an error if str has a length of zero

func (*Sharder) NewFromSubID

func (s *Sharder) NewFromSubID(subID int64) *ShardID

NewFromSubID returns a new ShardID based on some other value (subID) that is taken into account when generating the destination shard Allows for distribution of entries across shards to be dependent on some other value Usage:

// This would group blog entries into shards based on createdByUserID
blogEntryID := s.NewFromSubID(createdByUserID)
blogEntryID2 := s.NewFromSubID(createdByUserID) // Same shard as line above

func (*Sharder) NewRoundRobin

func (s *Sharder) NewRoundRobin() *ShardID

NewRoundRobin returns a new ShardID based on an incrementing sequence integer mod the number of shards Allows for an equal distribution of entries across shards

func (*Sharder) NumberOfShards

func (s *Sharder) NumberOfShards() int64

type StringShardID

type StringShardID struct {
	SrcID   string
	ShardID int64
	TypeID  int64
	LocalID int64
}

StringShardID is a string unique identifier that includes shard information

Jump to

Keyboard shortcuts

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