router

package
v0.0.0-...-b4c1251 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MinNumKey = math.MinInt64
	MaxNumKey = math.MaxInt64
)

Variables

View Source
var (
	DefaultRuleType   = "default"
	HashRuleType      = "hash"
	ModRuleType       = "mod"
	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)

ParseDayRange 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)

FindForKey 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)

FindForKey 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)

FindForKey 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

KeyError /*由分片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 RangeShard

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

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

type Router

type Router struct {
	Rules map[string]*Rule
}

func ParseRouter

func ParseRouter(cfgList []config.TableConfig, cfg *config.SchemaConfig) (router *Router, err error)

func (*Router) FindNodeIndex

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

func (*Router) GetRule

func (r *Router) GetRule(tableName string, defaultNode *config.NodeConfig) *Rule

type Rule

type Rule struct {
	Table string

	Key string

	Type string

	ReferenceTable *config.AssociatedTableConfig
	IsAssociated   bool

	DefaultNode string
	NodeList    []string

	SubTableIndexList []int       //SubTableIndexList store all the index of sharding sub-table,sequential
	TableToNode       map[int]int //key is table index, and value is node index

	Shard Shard
	// contains filtered or unexported fields
}

func NewDefaultRule

func NewDefaultRule(node string) *Rule

func ParseRule

func ParseRule(cfg config.TableConfig, cfgList []config.TableConfig) (*Rule, error)

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