Documentation ¶
Index ¶
- Constants
- Variables
- func EncodeValue(value interface{}) string
- func HashValue(value interface{}) uint64
- func NumValue(value interface{}) int64
- func ParseDayRange(dateRange string) ([]int, error)
- func ParseMonthRange(dateRange string) ([]int, error)
- func ParseYearRange(dateRange string) ([]int, error)
- type DateDayShard
- type DateMonthShard
- type DateYearShard
- type DefaultShard
- type HashShard
- type KeyError
- type NumKeyRange
- type NumRangeShard
- type Plan
- type RangeShard
- type Router
- type Rule
- type Shard
- type Uint64Key
Constants ¶
View Source
const ( MinNumKey = math.MinInt64 MaxNumKey = math.MaxInt64 )
View Source
const ( EID_NODE = iota VALUE_NODE LIST_NODE OTHER_NODE )
Variables ¶
View Source
var ( DefaultRuleType = "default" HashRuleType = "hash" RangeRuleType = "range" DateYearRuleType = "date_year" DateMonthRuleType = "date_month" DateDayRuleType = "date_day" MinMonthDaysCount = 28 MaxMonthDaysCount = 31 MonthsCount = 12 )
Functions ¶
func EncodeValue ¶
func EncodeValue(value interface{}) string
func ParseDayRange ¶
return date of daynumber by order 20151201-20151205 20151201,20151202,20151203,20151204,20151205
func ParseMonthRange ¶
return date of month by order 201510-201512 201510,201511,201512
func ParseYearRange ¶
return date of year by order 2013-2015 2013,2014,2015
Types ¶
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 NumKeyRange ¶
[start,end)
func ParseNumSharding ¶
func ParseNumSharding(Locations []int, TableRowLimit int) ([]NumKeyRange, error)
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, error)
type Plan ¶
type Plan struct { Rule *Rule Criteria sqlparser.SQLNode KeyIndex int //used for insert/replace to find shard key idx //used for insert/replace values,key is table index,and value is //the rows for insert or replace. Rows map[int]sqlparser.Values SubTableValueGroups map[int]sqlparser.ValTuple //按照tableIndex存放ValueExpr InRightToReplace *sqlparser.ComparisonExpr //记录in的右边Expr,用来动态替换不同table in的值 RouteTableIndexs []int RouteNodeIndexs []int RewrittenSqls map[string][]string }
func (*Plan) GetIRKeyIndex ¶
find shard key index in insert or replace SQL plan.Rule cols must not nil
func (*Plan) TindexsToNindexs ¶
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 { DB string Rules map[string]*Rule //key is <table name> DefaultRule *Rule Nodes []string //just for human saw }
func NewRouter ¶
func NewRouter(schemaConfig *config.SchemaConfig) (*Router, error)
build router according to the config file
type Rule ¶
type Rule struct { DB string Table string Key string Type string Nodes []string SubTableIndexs []int //SubTableIndexs store all the index of sharding sub-table TableToNode map[int]int //key is table index, and value is node index Shard Shard }
func NewDefaultRule ¶
func (*Rule) FindNodeIndex ¶
func (*Rule) FindTableIndex ¶
Click to show internal directories.
Click to hide internal directories.