router

package
v0.0.0-...-4b09fe0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2016 License: MIT Imports: 11 Imported by: 2

Documentation

Index

Constants

View Source
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")
)
View Source
const (
	MinNumKey = math.MinInt64
	MaxNumKey = math.MaxInt64
)

Variables

View Source
var (
	NoneRuleType  = "none"
	HashRuleType  = "hash"
	RangeRuleType = "range"
)
View Source
var AllKeyspaceIdTypes = []KeyspaceIdType{
	KIT_UNSET,
	KIT_UINT64,
	KIT_BYTES,
}
View Source
var MaxKey = KeyspaceId("")

MaxKey is bigger than all KeyspaceId (by convention).

View Source
var MinKey = KeyspaceId("")

MinKey is smaller than all KeyspaceId (the value really is).

Functions

func EncodeValue

func EncodeValue(value interface{}) string

func HashValue

func HashValue(value interface{}) uint64

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

func KeyRangesIntersect(first, second KeyRange) bool

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)

func NumValue

func NumValue(value interface{}) int64

Types

type DefaultShard

type DefaultShard struct {
}

func (*DefaultShard) FindForKey

func (s *DefaultShard) FindForKey(key interface{}) int

type HashShard

type HashShard struct {
	ShardNum int
}

func (*HashShard) FindForKey

func (s *HashShard) 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

type JHSHashShard struct {
	NodeShardNum  int
	TableShardNum int
}

func (*JHSHashShard) FindForKey

func (s *JHSHashShard) FindForKey(key interface{}) int

func (*JHSHashShard) JHSFindForKey

func (s *JHSHashShard) JHSFindForKey(key interface{}) (int, int)

type JHSShard

type JHSShard interface {
	JHSFindForKey(key interface{}) (int, int)
	FindForKey(key interface{}) int
}

type KeyError

type KeyError string

func NewKeyError

func NewKeyError(format string, args ...interface{}) KeyError

func (KeyError) Error

func (ke KeyError) Error() string

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

func KeyRangesOverlap(first, second KeyRange) (KeyRange, error)

KeyRangesOverlap returns the overlap between two KeyRanges. They need to overlap, otherwise an error is returned.

func ParseKeyRangeParts

func ParseKeyRangeParts(start, end string) (KeyRange, error)

Parse a start and end hex values and build a KeyRange

func ParseShardingSpec

func ParseShardingSpec(spec string) ([]KeyRange, 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 (KeyRange) Contains

func (kr KeyRange) Contains(i KeyspaceId) bool

func (KeyRange) IsPartial

func (kr KeyRange) IsPartial() bool

Returns true if the KeyRange does not cover the entire space.

func (KeyRange) MapKey

func (kr KeyRange) MapKey() string

func (KeyRange) String

func (kr KeyRange) String() string

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

type NumKeyRange struct {
	Start int64
	End   int64
}

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 RangeShard interface {
	Shard
	EqualStart(key interface{}, index int) bool
	EqualStop(key interface{}, index int) bool
}

type Router

type Router struct {
	Rules       map[string]*Rule //key is <table name>
	DefaultRule *Rule
}

func NewRouter

func NewRouter(rules map[string]*Rule, rule *Rule) *Router

func (*Router) GetRule

func (r *Router) GetRule(table string) *Rule

type Rule

type Rule struct {
	Table string
	Key   string

	Type string

	Nodes []string
	//by mian
	Shard JHSShard
}

func NewDefaultRule

func NewDefaultRule(node string) *Rule

func (*Rule) FindNode

func (r *Rule) FindNode(key interface{}) string

func (*Rule) FindNodeIndex

func (r *Rule) FindNodeIndex(key interface{}) int

func (*Rule) JHSFindNodeIndex

func (r *Rule) JHSFindNodeIndex(key interface{}) (int, int)

by mian

func (*Rule) String

func (r *Rule) String() string

type RuleConfig

type RuleConfig struct {
	config.ShardConfig
}

func (*RuleConfig) ParseRule

func (c *RuleConfig) ParseRule(db string) (*Rule, error)

type Shard

type Shard interface {
	FindForKey(key interface{}) int
}

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.

func (Uint64Key) String

func (i Uint64Key) String() string

Jump to

Keyboard shortcuts

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