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
- func EncodeValue(value interface{}) string
- func GetString(value interface{}) string
- func HashValue(value interface{}) uint64
- func IsMycatShardingRule(ruleType string) bool
- func NumValue(value interface{}) int64
- func ParseDayRange(dateRange string) ([]int, error)
- func ParseMonthRange(dateRange string) ([]int, error)
- func ParseYearRange(dateRange string) ([]int, error)
- type BaseRule
- func (r *BaseRule) FindTableIndex(key interface{}) (int, error)
- func (r *BaseRule) GetDB() string
- func (r *BaseRule) GetDatabaseNameByTableIndex(index int) (string, error)
- func (r *BaseRule) GetDatabases() []string
- func (r *BaseRule) GetShard() Shard
- func (r *BaseRule) GetShardingColumn() string
- func (r *BaseRule) GetSlice(i int) string
- func (r *BaseRule) GetSliceIndexFromTableIndex(i int) int
- func (r *BaseRule) GetSlices() []string
- func (r *BaseRule) GetSubTableIndexes() []int
- func (r *BaseRule) GetTable() string
- func (r *BaseRule) GetTableIndexByDatabaseName(phyDB string) (int, bool)
- func (r *BaseRule) GetType() string
- func (r *BaseRule) IsLinkedRule() bool
- type DateDayShard
- type DateMonthShard
- type DateYearShard
- type DefaultShard
- type GlobalTableShard
- type HashShard
- type KeyError
- type LinkedRule
- func (l *LinkedRule) FindTableIndex(key interface{}) (int, error)
- func (l *LinkedRule) GetDB() string
- func (l *LinkedRule) GetDatabaseNameByTableIndex(index int) (string, error)
- func (l *LinkedRule) GetDatabases() []string
- func (l *LinkedRule) GetParentDB() string
- func (l *LinkedRule) GetParentTable() string
- func (l *LinkedRule) GetShard() Shard
- func (l *LinkedRule) GetShardingColumn() string
- func (l *LinkedRule) GetSlice(i int) string
- func (l *LinkedRule) GetSliceIndexFromTableIndex(i int) int
- func (l *LinkedRule) GetSlices() []string
- func (l *LinkedRule) GetSubTableIndexes() []int
- func (l *LinkedRule) GetTable() string
- func (l *LinkedRule) GetTableIndexByDatabaseName(phyDB string) (int, bool)
- func (l *LinkedRule) GetType() string
- func (l *LinkedRule) IsLinkedRule() bool
- type ModShard
- type MycatPartitionLongShard
- type MycatPartitionModShard
- type MycatPartitionMurmurHashShard
- type MycatPartitionPaddingModShard
- type MycatPartitionStringShard
- type MycatRule
- type NumKeyRange
- type NumRangeShard
- type RangeShard
- type Router
- type Rule
- type Shard
- type Uint64Key
Constants ¶
const ( // MinNumKey min int64 MinNumKey = math.MinInt64 // MaxNumKey max int64 MaxNumKey = math.MaxInt64 )
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 )
const ( PaddingModLeftEnd = 0 PaddingModRightEnd = 1 PaddingModDefaultPadFrom = PaddingModRightEnd PaddingModDefaultPadLength = 18 PaddingModDefaultModBegin = 10 PaddingModDefaultModEnd = 16 PaddingModDefaultMod = 2 )
mod padding
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 IsMycatShardingRule ¶
func ParseDayRange ¶
ParseDayRange return date of daynumber by order 20151201-20151205 20151201,20151202,20151203,20151204,20151205
func ParseMonthRange ¶
ParseMonthRange return date of month by order 201510-201512 201510,201511,201512
func ParseYearRange ¶
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 (*BaseRule) FindTableIndex ¶
func (*BaseRule) GetDatabaseNameByTableIndex ¶
func (*BaseRule) GetDatabases ¶
func (*BaseRule) GetShardingColumn ¶
func (*BaseRule) GetSliceIndexFromTableIndex ¶
func (*BaseRule) GetSlices ¶
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 (*BaseRule) GetTableIndexByDatabaseName ¶
func (*BaseRule) IsLinkedRule ¶
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 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 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 ¶
func (m *MycatPartitionMurmurHashShard) Init() error
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 ¶
func (m *MycatPartitionPaddingModShard) Init() error
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 NumKeyRange ¶
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) 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
}
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) }