Documentation ¶
Index ¶
- Constants
- Variables
- func EncodeValue(value interface{}) string
- func HashValue(value interface{}) uint64
- func IsKeyspaceIdTypeInList(typ KeyspaceIdType, types []KeyspaceIdType) bool
- func KeyRangesIntersect(first, second KeyRange) bool
- func NumValue(value interface{}) int64
- type DefaultShard
- type HashShard
- type HexKeyspaceId
- type JHSHashShard
- type JHSShard
- type KeyError
- type KeyRange
- type KeyRangeShard
- type KeyspaceId
- type KeyspaceIdType
- type NumKeyRange
- type NumRangeShard
- type RangeShard
- type Router
- type Rule
- type RuleConfig
- type Shard
- 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") )
const ( MinNumKey = math.MinInt64 MaxNumKey = math.MaxInt64 )
Variables ¶
var ( NoneRuleType = "none" HashRuleType = "hash" RangeRuleType = "range" )
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 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 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 DefaultShard ¶
type DefaultShard struct { }
func (*DefaultShard) FindForKey ¶
func (s *DefaultShard) FindForKey(key interface{}) int
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 JHSHashShard ¶
func (*JHSHashShard) FindForKey ¶
func (s *JHSHashShard) FindForKey(key interface{}) int
func (*JHSHashShard) JHSFindForKey ¶
func (s *JHSHashShard) JHSFindForKey(key interface{}) (int, int)
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 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.
func (KeyRange) Contains ¶
func (kr KeyRange) Contains(i KeyspaceId) bool
type KeyRangeShard ¶
type KeyRangeShard struct {
Shards []KeyRange
}
func (*KeyRangeShard) EqualStart ¶
func (s *KeyRangeShard) EqualStart(key interface{}, index int) bool
func (*KeyRangeShard) EqualStop ¶
func (s *KeyRangeShard) EqualStop(key interface{}, index int) bool
func (*KeyRangeShard) FindForKey ¶
func (s *KeyRangeShard) FindForKey(key interface{}) 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.
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.
type NumKeyRange ¶
func ParseNumShardingSpec ¶
func ParseNumShardingSpec(spec string) ([]NumKeyRange, 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 (NumKeyRange) Contains ¶
func (kr NumKeyRange) Contains(i int64) bool
func (NumKeyRange) MapKey ¶
func (kr NumKeyRange) MapKey() string
func (NumKeyRange) String ¶
func (kr NumKeyRange) String() string
type NumRangeShard ¶
type NumRangeShard struct {
Shards []NumKeyRange
}
func (*NumRangeShard) EqualStart ¶
func (s *NumRangeShard) EqualStart(key interface{}, index int) bool
func (*NumRangeShard) EqualStop ¶
func (s *NumRangeShard) EqualStop(key interface{}, index int) bool
func (*NumRangeShard) FindForKey ¶
func (s *NumRangeShard) FindForKey(key interface{}) int
type RangeShard ¶
type RuleConfig ¶
type RuleConfig struct {
config.ShardConfig
}