Documentation ¶
Index ¶
- Constants
- Variables
- func EncodeValue(value interface{}) string
- func FindShardForKey(key interface{}, tabletKeys []KeyspaceId) (i int, err error)
- func FindShardForValue(value string, tabletKeys []KeyspaceId) int
- func IsKeyspaceIdTypeInList(typ KeyspaceIdType, types []KeyspaceIdType) bool
- func KeyRangeContains(kr *pb.KeyRange, id []byte) bool
- func KeyRangeEndEqual(left, right *pb.KeyRange) bool
- func KeyRangeEqual(left, right *pb.KeyRange) bool
- func KeyRangeIsPartial(kr *pb.KeyRange) bool
- func KeyRangeStartEqual(left, right *pb.KeyRange) bool
- func KeyRangeString(k *pb.KeyRange) string
- func KeyRangeToProto(k KeyRange) *pb.KeyRange
- func KeyRangesIntersect(first, second *pb.KeyRange) bool
- func KeyRangesOverlap(first, second *pb.KeyRange) (*pb.KeyRange, error)
- func KeyRangesToProto(ks []KeyRange) []*pb.KeyRange
- func KeyspaceIdTypeToProto(k KeyspaceIdType) pb.KeyspaceIdType
- func KeyspaceIdsToProto(l []KeyspaceId) [][]byte
- func ParseKeyRangeParts(start, end string) (*pb.KeyRange, error)
- func ParseKeyspaceIDType(param string) (pb.KeyspaceIdType, error)
- func ParseShardingSpec(spec string) ([]*pb.KeyRange, error)
- type HexKeyspaceId
- type KeyError
- type KeyRange
- type KeyRangeArray
- type KeyspaceId
- func (kid KeyspaceId) Hex() HexKeyspaceId
- func (keyspaceId KeyspaceId) MarshalBson(buf *bytes2.ChunkedWriter, key string)
- func (kid KeyspaceId) MarshalJSON() ([]byte, error)
- func (kid KeyspaceId) String() string
- func (keyspaceId *KeyspaceId) UnmarshalBson(buf *bytes.Buffer, kind byte)
- func (kid *KeyspaceId) UnmarshalJSON(data []byte) (err error)
- type KeyspaceIdArray
- type KeyspaceIdType
- type Uint64Key
Constants ¶
const ( // unset - no type for this KeyspaceId KIT_UNSET = KeyspaceIdType("") // uint64 - a uint64 value is used // this is represented as 'unsigned bigint' in mysql KIT_UINT64 = KeyspaceIdType("uint64") // bytes - a string of bytes is used // this is represented as 'varbinary' in mysql KIT_BYTES = KeyspaceIdType("bytes") )
Variables ¶
var AllKeyspaceIdTypes = []KeyspaceIdType{ KIT_UNSET, KIT_UINT64, KIT_BYTES, }
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 IsKeyspaceIdTypeInList ¶
func IsKeyspaceIdTypeInList(typ KeyspaceIdType, types []KeyspaceIdType) bool
IsKeyspaceIdTypeInList returns true if the given type is in the list. Use it with AllKeyspaceIdTypes for instance.
func KeyRangeContains ¶
KeyRangeContains returns true if the provided id is in the keyrange.
func KeyRangeEndEqual ¶
KeyRangeEndEqual returns true if both key ranges have the same end
func KeyRangeEqual ¶
KeyRangeEqual returns true if both key ranges cover the same area
func KeyRangeIsPartial ¶
KeyRangeIsPartial returns true if the KeyRange does not cover the entire space.
func KeyRangeStartEqual ¶
KeyRangeStartEqual returns true if both key ranges have the same start
func KeyRangeString ¶
KeyRangeString prints a pb.KeyRange
func KeyRangeToProto ¶
KeyRangeToProto translates a KeyRange to proto, or panics
func KeyRangesIntersect ¶
KeyRangesIntersect returns true if some Keyspace values exist in both ranges.
func KeyRangesOverlap ¶
KeyRangesOverlap returns the overlap between two KeyRanges. They need to overlap, otherwise an error is returned.
func KeyRangesToProto ¶
KeyRangesToProto translates an array of KeyRange to proto
func KeyspaceIdTypeToProto ¶
func KeyspaceIdTypeToProto(k KeyspaceIdType) pb.KeyspaceIdType
KeyspaceIdTypeToProto translates a KeyspaceIdType to proto, or panics
func KeyspaceIdsToProto ¶
func KeyspaceIdsToProto(l []KeyspaceId) [][]byte
KeyspaceIdsToProto translates an array of KeyspaceId to proto
func ParseKeyRangeParts ¶
ParseKeyRangeParts parses a start and end hex values and build a proto KeyRange
func ParseKeyspaceIDType ¶
func ParseKeyspaceIDType(param string) (pb.KeyspaceIdType, error)
ParseKeyspaceIDType parses the keyspace id type into the enum
func ParseShardingSpec ¶
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.
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 ProtoToKeyRange ¶
ProtoToKeyRange translates a proto KeyRange, or panics
func ProtoToKeyRanges ¶
ProtoToKeyRanges translates a proto into an array of KeyRanges
func (KeyRange) Contains ¶
func (kr KeyRange) Contains(i KeyspaceId) bool
func (*KeyRange) MarshalBson ¶
func (keyRange *KeyRange) MarshalBson(buf *bytes2.ChunkedWriter, key string)
MarshalBson bson-encodes KeyRange.
type KeyRangeArray ¶
type KeyRangeArray []KeyRange
KeyRangeArray is an array of KeyRange that can be sorted We use it only if we need to sort []KeyRange
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 ProtoToKeyspaceIds ¶
func ProtoToKeyspaceIds(l [][]byte) []KeyspaceId
ProtoToKeyspaceIds translates a proto into an array of KeyspaceIds
func (KeyspaceId) Hex ¶
func (kid KeyspaceId) Hex() HexKeyspaceId
Hex prints a KeyspaceId in lower case hex.
func (KeyspaceId) MarshalBson ¶
func (keyspaceId KeyspaceId) MarshalBson(buf *bytes2.ChunkedWriter, key string)
MarshalBson bson-encodes KeyspaceId.
func (KeyspaceId) MarshalJSON ¶
func (kid KeyspaceId) MarshalJSON() ([]byte, error)
MarshalJSON turns a KeyspaceId into json (using hex encoding).
func (KeyspaceId) String ¶
func (kid KeyspaceId) String() string
func (*KeyspaceId) UnmarshalBson ¶
func (keyspaceId *KeyspaceId) UnmarshalBson(buf *bytes.Buffer, kind byte)
UnmarshalBson bson-decodes into KeyspaceId.
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 We use it only if we need to sort []KeyspaceId
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)
type KeyspaceIdType ¶
type KeyspaceIdType string
KeyspaceIdType represents the type of the KeyspaceId. Usually we don't care, but some parts of the code will need that info.
func ProtoToKeyspaceIdType ¶
func ProtoToKeyspaceIdType(k pb.KeyspaceIdType) KeyspaceIdType
ProtoToKeyspaceIdType translates a proto KeyspaceIdType, or panics
func (KeyspaceIdType) MarshalBson ¶
func (keyspaceIdType KeyspaceIdType) MarshalBson(buf *bytes2.ChunkedWriter, key string)
MarshalBson bson-encodes KeyspaceIdType.
func (*KeyspaceIdType) UnmarshalBson ¶
func (keyspaceIdType *KeyspaceIdType) UnmarshalBson(buf *bytes.Buffer, kind byte)
UnmarshalBson bson-decodes into KeyspaceIdType.
type Uint64Key ¶
type Uint64Key uint64
Uint64Key is a uint64 that can be converted into a KeyspaceId.
func (Uint64Key) KeyspaceId ¶
func (i Uint64Key) KeyspaceId() KeyspaceId
KeyspaceId returns the KeyspaceId associated with a Uint64Key.