router

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

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 HashValue

func HashValue(value interface{}) uint64

func NumValue

func NumValue(value interface{}) int64

func ParseDayRange

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

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

func ParseMonthRange

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

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

func ParseYearRange

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

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 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 NumKeyRange

type NumKeyRange struct {
	Start int64
	End   int64
}

[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

func (plan *Plan) GetIRKeyIndex(cols sqlparser.Columns) error

find shard key index in insert or replace SQL plan.Rule cols must not nil

func (*Plan) TindexsToNindexs

func (plan *Plan) TindexsToNindexs(tableIndexs []int) []int

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 {
	//map[db]map[table_name]*Rule
	Rules       map[string]map[string]*Rule
	DefaultRule *Rule
	Nodes       []string //just for human saw
}

func NewRouter

func NewRouter(schemaConfig *config.SchemaConfig) (*Router, error)

NewRouter build router according to the config file

func (*Router) BuildPlan

func (r *Router) BuildPlan(db string, statement sqlparser.Statement) (*Plan, error)

build a router plan

func (*Router) GetRule

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

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,sequential
	TableToNode    map[int]int //key is table index, and value is node index
	Shard          Shard
}

func NewDefaultRule

func NewDefaultRule(node string) *Rule

func (*Rule) FindNode

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

func (*Rule) FindNodeIndex

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

func (*Rule) FindTableIndex

func (r *Rule) FindTableIndex(key interface{}) (int, 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