router

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2019 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Copyright 2019 The Gaea Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	// MinNumKey min int64
	MinNumKey = math.MinInt64
	// MaxNumKey max int64
	MaxNumKey = math.MaxInt64
)
View Source
const (
	DefaultRuleType         = models.ShardDefault
	GlobalTableRuleType     = models.ShardGlobal
	LinkedTableRuleType     = models.ShardLinked // this type only exists in conf, then transfer to LinkedRule
	HashRuleType            = models.ShardHash
	RangeRuleType           = models.ShardRange
	ModRuleType             = models.ShardMod
	DateYearRuleType        = models.ShardYear
	DateMonthRuleType       = models.ShardMonth
	DateDayRuleType         = models.ShardDay
	MycatModRuleType        = models.ShardMycatMod
	MycatLongRuleType       = models.ShardMycatLong
	MycatStringRuleType     = models.ShardMycatString
	MycatMurmurRuleType     = models.ShardMycatMURMUR
	MycatPaddingModRuleType = models.ShardMycatPaddingMod

	MinMonthDaysCount = 28
	MaxMonthDaysCount = 31
	MonthsCount       = 12
)
View Source
const (
	PaddingModLeftEnd  = 0
	PaddingModRightEnd = 1

	PaddingModDefaultPadFrom   = PaddingModRightEnd
	PaddingModDefaultPadLength = 18
	PaddingModDefaultModBegin  = 10
	PaddingModDefaultModEnd    = 16
	PaddingModDefaultMod       = 2
)

mod padding

View Source
const (
	// PartitionLength length of partition
	PartitionLength = 1024
)

Variables

This section is empty.

Functions

func EncodeValue

func EncodeValue(value interface{}) string

don't use this function like strconv.FormatInt()!!!

func GetString

func GetString(value interface{}) string

func HashValue

func HashValue(value interface{}) uint64

func IsMycatShardingRule

func IsMycatShardingRule(ruleType string) bool

func NumValue

func NumValue(value interface{}) int64

func ParseDayRange

func ParseDayRange(dateRange string) ([]int, error)

ParseDayRange return date of daynumber by order 20151201-20151205 20151201,20151202,20151203,20151204,20151205

func ParseMonthRange

func ParseMonthRange(dateRange string) ([]int, error)

ParseMonthRange return date of month by order 201510-201512 201510,201511,201512

func ParseYearRange

func ParseYearRange(dateRange string) ([]int, error)

ParseYearRange return date of year by order 2013-2015 2013,2014,2015

Types

type BaseRule

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

func NewDefaultRule

func NewDefaultRule(slice string) *BaseRule

func (*BaseRule) FindTableIndex

func (r *BaseRule) FindTableIndex(key interface{}) (int, error)

func (*BaseRule) GetDB

func (r *BaseRule) GetDB() string

func (*BaseRule) GetDatabaseNameByTableIndex

func (r *BaseRule) GetDatabaseNameByTableIndex(index int) (string, error)

func (*BaseRule) GetDatabases

func (r *BaseRule) GetDatabases() []string

func (*BaseRule) GetShard

func (r *BaseRule) GetShard() Shard

func (*BaseRule) GetShardingColumn

func (r *BaseRule) GetShardingColumn() string

func (*BaseRule) GetSlice

func (r *BaseRule) GetSlice(i int) string

The confs should be verified before use to avoid panic.

func (*BaseRule) GetSliceIndexFromTableIndex

func (r *BaseRule) GetSliceIndexFromTableIndex(i int) int

func (*BaseRule) GetSlices

func (r *BaseRule) GetSlices() []string

This is dangerous since the caller can change the value in slices. It is better to return a iterator instead of exposing the origin slices.

func (*BaseRule) GetSubTableIndexes

func (r *BaseRule) GetSubTableIndexes() []int

func (*BaseRule) GetTable

func (r *BaseRule) GetTable() string

func (*BaseRule) GetTableIndexByDatabaseName

func (r *BaseRule) GetTableIndexByDatabaseName(phyDB string) (int, bool)

func (*BaseRule) GetType

func (r *BaseRule) GetType() string

func (*BaseRule) IsLinkedRule

func (r *BaseRule) IsLinkedRule() bool

type DateDayShard

type DateDayShard struct {
}

func (*DateDayShard) FindForKey

func (s *DateDayShard) FindForKey(key interface{}) (int, error)

the format of date is: YYYY-MM-DD HH:MM:SS,YYYY-MM-DD or unix timestamp(int)

type DateMonthShard

type DateMonthShard struct {
}

func (*DateMonthShard) FindForKey

func (s *DateMonthShard) FindForKey(key interface{}) (int, error)

the format of date is: YYYY-MM-DD HH:MM:SS,YYYY-MM-DD or unix timestamp(int)

type DateYearShard

type DateYearShard struct {
}

func (*DateYearShard) FindForKey

func (s *DateYearShard) FindForKey(key interface{}) (int, error)

the format of date is: YYYY-MM-DD HH:MM:SS,YYYY-MM-DD or unix timestamp(int)

type DefaultShard

type DefaultShard struct {
}

func (*DefaultShard) FindForKey

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

type GlobalTableShard

type GlobalTableShard struct {
}

func NewGlobalTableShard

func NewGlobalTableShard() *GlobalTableShard

func (*GlobalTableShard) FindForKey

func (s *GlobalTableShard) FindForKey(key interface{}) (int, error)

type HashShard

type HashShard struct {
	ShardNum int
}

func (*HashShard) FindForKey

func (s *HashShard) FindForKey(key interface{}) (int, error)

type KeyError

type KeyError string

由分片ID找到分片,可用文件中的函数

func NewKeyError

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

func (KeyError) Error

func (ke KeyError) Error() string

type LinkedRule

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

func (*LinkedRule) FindTableIndex

func (l *LinkedRule) FindTableIndex(key interface{}) (int, error)

func (*LinkedRule) GetDB

func (l *LinkedRule) GetDB() string

func (*LinkedRule) GetDatabaseNameByTableIndex

func (l *LinkedRule) GetDatabaseNameByTableIndex(index int) (string, error)

func (*LinkedRule) GetDatabases

func (l *LinkedRule) GetDatabases() []string

func (*LinkedRule) GetParentDB

func (l *LinkedRule) GetParentDB() string

func (*LinkedRule) GetParentTable

func (l *LinkedRule) GetParentTable() string

func (*LinkedRule) GetShard

func (l *LinkedRule) GetShard() Shard

func (*LinkedRule) GetShardingColumn

func (l *LinkedRule) GetShardingColumn() string

func (*LinkedRule) GetSlice

func (l *LinkedRule) GetSlice(i int) string

func (*LinkedRule) GetSliceIndexFromTableIndex

func (l *LinkedRule) GetSliceIndexFromTableIndex(i int) int

func (*LinkedRule) GetSlices

func (l *LinkedRule) GetSlices() []string

func (*LinkedRule) GetSubTableIndexes

func (l *LinkedRule) GetSubTableIndexes() []int

func (*LinkedRule) GetTable

func (l *LinkedRule) GetTable() string

func (*LinkedRule) GetTableIndexByDatabaseName

func (l *LinkedRule) GetTableIndexByDatabaseName(phyDB string) (int, bool)

func (*LinkedRule) GetType

func (l *LinkedRule) GetType() string

func (*LinkedRule) IsLinkedRule

func (l *LinkedRule) IsLinkedRule() bool

type ModShard

type ModShard struct {
	ShardNum int
}

func (*ModShard) FindForKey

func (m *ModShard) FindForKey(key interface{}) (int, error)

type MycatPartitionLongShard

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

MycatPartitionLongShard mycat route algorithm: PartitionByLong

func NewMycatPartitionLongShard

func NewMycatPartitionLongShard(shardNum int, partitionCount, partitionLength string) *MycatPartitionLongShard

NewMycatPartitionLongShard constructor of MycatPartitionLongShard

func (*MycatPartitionLongShard) FindForKey

func (m *MycatPartitionLongShard) FindForKey(key interface{}) (int, error)

FindForKey return MycatPartitionLongShard calculated result

func (*MycatPartitionLongShard) Init

func (m *MycatPartitionLongShard) Init() error

Init init MycatPartitionLongShard

type MycatPartitionModShard

type MycatPartitionModShard struct {
	ShardNum int
}

MycatPartitionModShard mycat route algorithm: PartitionByMod take care: in Mycat, the key is parsed to a BigInteger, not int64.

func NewMycatPartitionModShard

func NewMycatPartitionModShard(shardNum int) *MycatPartitionModShard

NewMycatPartitionModShard constructor of MycatPartitionModShard

func (*MycatPartitionModShard) FindForKey

func (m *MycatPartitionModShard) FindForKey(key interface{}) (int, error)

FindForKey return result of calculated key

type MycatPartitionMurmurHashShard

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

MycatPartitionMurmurHashShard mycat route algorithm: PartitionByMurmurHash

func NewMycatPartitionMurmurHashShard

func NewMycatPartitionMurmurHashShard(seedStr, virtualBucketTimesStr string, count int) (*MycatPartitionMurmurHashShard, error)

NewMycatPartitionMurmurHashShard constructor of MycatPartitionMurmurHashShard

func (*MycatPartitionMurmurHashShard) FindForKey

func (m *MycatPartitionMurmurHashShard) FindForKey(key interface{}) (int, error)

FindForKey return MycatPartitionMurmurHashShard calculated result

func (*MycatPartitionMurmurHashShard) Init

Init init MycatPartitionMurmurHashShard

func (*MycatPartitionMurmurHashShard) SetWeightMapFromFile

func (m *MycatPartitionMurmurHashShard) SetWeightMapFromFile(weightMapPath string) error

SetWeightMapFromFile init weight

type MycatPartitionPaddingModShard

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

MycatPartitionPaddingModShard mcyat partition padding mod

func GetMycatPartitionPaddingModShard

func GetMycatPartitionPaddingModShard(padFromStr, padLengthStr, modBeginStr, modEndStr string, mod int) (shard *MycatPartitionPaddingModShard, err error)

GetMycatPartitionPaddingModShard wrapper newDefaultMycatPartitionPaddingModShard

func (*MycatPartitionPaddingModShard) FindForKey

func (m *MycatPartitionPaddingModShard) FindForKey(key interface{}) (int, error)

FindForKey return MycatPartitionPaddingModShard calculated result

func (*MycatPartitionPaddingModShard) Init

Init init MycatPartitionPaddingModShard and check params

type MycatPartitionStringShard

type MycatPartitionStringShard struct {
	*MycatPartitionLongShard
	// contains filtered or unexported fields
}

MycatPartitionStringShard mycat route algorithm: PartitionByString

func NewMycatPartitionStringShard

func NewMycatPartitionStringShard(shardNum int, partitionCount, partitionLength string, hashSliceStr string) *MycatPartitionStringShard

NewMycatPartitionStringShard constructor of MycatPartitionStringShard

func (*MycatPartitionStringShard) FindForKey

func (m *MycatPartitionStringShard) FindForKey(key interface{}) (int, error)

FindForKey return MycatPartitionStringShard calculated result

func (*MycatPartitionStringShard) Init

func (m *MycatPartitionStringShard) Init() error

Init init NewMycatPartitionStringShard

type MycatRule

type MycatRule interface {
	Rule
	GetDatabases() []string
	GetTableIndexByDatabaseName(phyDB string) (int, bool)
}

type NumKeyRange

type NumKeyRange struct {
	Start int64
	End   int64
}

NumKeyRange [start,end)

func ParseNumSharding

func ParseNumSharding(Locations []int, TableRowLimit int) ([]NumKeyRange, error)

ParseNumSharding parse num shard

func (NumKeyRange) Contains

func (kr NumKeyRange) Contains(i int64) bool

Contains check if range contains i

func (NumKeyRange) MapKey

func (kr NumKeyRange) MapKey() string

MapKey key range

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, error)

type RangeShard

type RangeShard interface {
	Shard
	EqualStart(key interface{}, index int) bool
	EqualStop(key interface{}, index int) bool
}

一个范围的分片,例如[start,end)

type Router

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

func NewRouter

func NewRouter(namespace *models.Namespace) (*Router, error)

NewRouter build router according to the models of namespace

func (*Router) GetRule

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

func (*Router) GetShardRule

func (r *Router) GetShardRule(db, table string) (Rule, bool)

type Rule

type Rule interface {
	GetDB() string
	GetTable() string
	GetShardingColumn() string
	IsLinkedRule() bool
	GetShard() Shard
	FindTableIndex(key interface{}) (int, error)
	GetSlice(i int) string // i is slice index
	GetSliceIndexFromTableIndex(i int) int
	GetSlices() []string
	GetSubTableIndexes() []int
	GetType() string
	GetDatabaseNameByTableIndex(index int) (string, error)
}

type Shard

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

type Uint64Key

type Uint64Key uint64

Uint64Key is a uint64 that can be converted into a KeyspaceId.

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