Documentation ¶
Index ¶
- Variables
- func EncodeValue(value interface{}) string
- func FindShardForKey(key interface{}, tabletKeys []KeyspaceId) (i int, err error)
- func FindShardForValue(value string, tabletKeys []KeyspaceId) int
- func KeyRangesIntersect(first, second KeyRange) bool
- type HexKeyspaceId
- type KeyError
- type KeyRange
- type KeyRangeArray
- type KeyspaceId
- type KeyspaceIdArray
- type Uint64Key
Constants ¶
This section is empty.
Variables ¶
var MaxKey = KeyspaceId("")
MaxKey is bigger than all KeyspaceId (by convention).
var MinKey = KeyspaceId("")
MinKey is smaller than all KeyspaceId (the value really is).
Functions ¶
func EncodeValue ¶
func EncodeValue(value interface{}) string
func FindShardForKey ¶
func FindShardForKey(key interface{}, tabletKeys []KeyspaceId) (i int, err error)
Finds the shard that covers the given interface. The returned index is between 0 and len(tabletKeys)-1). The tabletKeys is an ordered list of the End values of the KeyRange structures for the shards.
func FindShardForValue ¶
func FindShardForValue(value string, tabletKeys []KeyspaceId) int
Finds the shard that covers the given value. The returned index is between 0 and len(tabletKeys)-1). The tabletKeys is an ordered list of the End values of the KeyRange structures for the shards.
This function will not check the value is under the last shard's max (we assume it will be empty, as checked by RebuildKeyspace)
func KeyRangesIntersect ¶
KeyRangesIntersect returns true if some Keyspace values exist in both ranges.
See: http://stackoverflow.com/questions/4879315/what-is-a-tidy-algorithm-to-find-overlapping-intervals two segments defined as (a,b) and (c,d) (with a<b and c<d): intersects = (b > c) && (a < d) overlap = min(b, d) - max(c, a)
Types ¶
type HexKeyspaceId ¶
type HexKeyspaceId string
HexKeyspaceId is the hex represention of a KeyspaceId.
func (HexKeyspaceId) Unhex ¶
func (hkid HexKeyspaceId) Unhex() (KeyspaceId, error)
Unhex converts a HexKeyspaceId into a KeyspaceId (hex decoding).
type KeyRange ¶
type KeyRange struct { Start KeyspaceId End KeyspaceId }
KeyRange is an interval of KeyspaceId values. It contains Start, but excludes End. In other words, it is: [Start, End[
func KeyRangesOverlap ¶
KeyRangesOverlap returns the overlap between two KeyRanges. They need to overlap, otherwise an error is returned.
func ParseKeyRangeParts ¶
Parse a start and end hex values and build a KeyRange
func (KeyRange) Contains ¶
func (kr KeyRange) Contains(i KeyspaceId) bool
func (*KeyRange) MarshalBson ¶
func (kr *KeyRange) MarshalBson(buf *bytes2.ChunkedWriter)
func (*KeyRange) UnmarshalBson ¶
type KeyRangeArray ¶
type KeyRangeArray []KeyRange
KeyRangeArray is an array of KeyRange that can be sorted
func ParseShardingSpec ¶
func ParseShardingSpec(spec string) (KeyRangeArray, error)
ParseShardingSpec parses a string that describes a sharding specification. a-b-c-d will be parsed as a-b, b-c, c-d. The empty string may serve both as the start and end of the keyspace: -a-b- will be parsed as start-a, a-b, b-end.
func (KeyRangeArray) Len ¶
func (p KeyRangeArray) Len() int
func (KeyRangeArray) Less ¶
func (p KeyRangeArray) Less(i, j int) bool
func (KeyRangeArray) Sort ¶
func (p KeyRangeArray) Sort()
func (KeyRangeArray) Swap ¶
func (p KeyRangeArray) Swap(i, j int)
type KeyspaceId ¶
type KeyspaceId string
KeyspaceId is the type we base sharding on.
func (KeyspaceId) Hex ¶
func (kid KeyspaceId) Hex() HexKeyspaceId
Hex prints a KeyspaceId in capital hex.
func (KeyspaceId) MarshalJSON ¶
func (kid KeyspaceId) MarshalJSON() ([]byte, error)
MarshalJSON turns a KeyspaceId into json (using hex encoding).
func (*KeyspaceId) UnmarshalJSON ¶
func (kid *KeyspaceId) UnmarshalJSON(data []byte) (err error)
UnmarshalJSON reads a KeyspaceId from json (hex decoding).
type KeyspaceIdArray ¶
type KeyspaceIdArray []KeyspaceId
KeyspaceIdArray is an array of KeyspaceId that can be sorted
func (KeyspaceIdArray) Len ¶
func (p KeyspaceIdArray) Len() int
func (KeyspaceIdArray) Less ¶
func (p KeyspaceIdArray) Less(i, j int) bool
func (KeyspaceIdArray) Sort ¶
func (p KeyspaceIdArray) Sort()
func (KeyspaceIdArray) Swap ¶
func (p KeyspaceIdArray) Swap(i, j int)