router

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2021 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TableTypeSingle  = "single"
	TableTypeGlobal  = "global"
	TableTypeUnknown = "unknown"

	TableTypePartitionHash  = "hash"
	TableTypePartitionList  = "list"
	TableTypePartitionRange = "range"
)
View Source
const (
	NAME_CHAR_LEN     = 64
	TABLE_NAME_SUFFIX = 5 // table name suffix: "_0032"
)
View Source
const (
	// methodTypeHash type.
	MethodTypeHash   = "HASH"
	MethodTypeGlobal = "GLOBAL"
	MethodTypeSingle = "SINGLE"
	MethodTypeList   = "LIST"
)

Variables

View Source
var (
	// MockDefaultConfig config.
	MockDefaultConfig = []*config.PartitionConfig{
		&config.PartitionConfig{
			Table:   "A2",
			Segment: "2-4",
			Backend: "backend2",
		},
		&config.PartitionConfig{
			Table:   "A4",
			Segment: "4-8",
			Backend: "backend4",
		},
	}
)

Functions

func MockNewRouterConfig added in v1.0.3

func MockNewRouterConfig() *config.RouterConfig

MockNewRouterConfig returns the router config.

func MockTable64Config

func MockTable64Config() *config.TableConfig

MockTable64Config config.

func MockTableAConfig

func MockTableAConfig() *config.TableConfig

MockTableAConfig config.

func MockTableBConfig

func MockTableBConfig() *config.TableConfig

MockTableBConfig config.

func MockTableCConfig added in v1.0.8

func MockTableCConfig() *config.TableConfig

MockTableCConfig config.

func MockTableDeadLockConfig added in v1.1.1

func MockTableDeadLockConfig() *config.TableConfig

MockTableDeadLockConfig config.

func MockTableE1Config

func MockTableE1Config() *config.TableConfig

MockTableE1Config config, unsupport shardtype.

func MockTableG1Config added in v1.0.3

func MockTableG1Config() *config.TableConfig

MockTableG1Config config, global shardtype.

func MockTableGConfig added in v1.0.3

func MockTableGConfig() *config.TableConfig

MockTableGConfig config, global shardtype.

func MockTableGreaterThanConfig

func MockTableGreaterThanConfig() *config.TableConfig

MockTableGreaterThanConfig config.

func MockTableInvalidConfig

func MockTableInvalidConfig() *config.TableConfig

MockTableInvalidConfig config.

func MockTableList1Config added in v1.0.8

func MockTableList1Config() *config.TableConfig

MockTableList1Config config, list shardtype.

func MockTableListConfig added in v1.0.8

func MockTableListConfig() *config.TableConfig

MockTableListConfig config, list shardtype.

func MockTableMConfig

func MockTableMConfig() *config.TableConfig

MockTableMConfig config.

func MockTableOverlapConfig

func MockTableOverlapConfig() *config.TableConfig

MockTableOverlapConfig config.

func MockTableRConfig added in v1.0.8

func MockTableRConfig() *config.TableConfig

MockTableRConfig config.

func MockTableSConfig added in v1.0.6

func MockTableSConfig() *config.TableConfig

MockTableSConfig config, single shardtype.

func MockTableSegmentEndErrConfig

func MockTableSegmentEndErrConfig() *config.TableConfig

MockTableSegmentEndErrConfig config.

func MockTableSegmentErr1Config

func MockTableSegmentErr1Config() *config.TableConfig

MockTableSegmentErr1Config config.

func MockTableSegmentStartErrConfig

func MockTableSegmentStartErrConfig() *config.TableConfig

MockTableSegmentStartErrConfig config.

Types

type DatabaseACL

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

DatabaseACL tuple.

func NewDatabaseACL

func NewDatabaseACL() *DatabaseACL

NewDatabaseACL creates new database acl.

func (*DatabaseACL) Allow

func (acl *DatabaseACL) Allow(db string) bool

Allow used to check to see if the db is system database.

func (*DatabaseACL) IsSystemDB added in v1.0.3

func (acl *DatabaseACL) IsSystemDB(db string) bool

IsSystemDB used to check to see if the db is system database.

type Extra added in v1.0.6

type Extra struct {
	AutoIncrement *config.AutoIncrement
}

Extra -- router extra params.

type Global added in v1.0.3

type Global struct {

	// Segments slice.
	Segments []Segment `json:",omitempty"`
	// contains filtered or unexported fields
}

Global for global table router.

func NewGlobal added in v1.0.3

func NewGlobal(log *xlog.Log, conf *config.TableConfig) *Global

NewGlobal creates new global.

func (*Global) Build added in v1.0.3

func (g *Global) Build() error

Build used to build Segments from schema config.

func (*Global) GetIndex added in v1.0.5

func (g *Global) GetIndex(sqlval *sqlparser.SQLVal) (int, error)

GetIndex returns index based on sqlval.

func (*Global) GetSegment added in v1.0.7

func (g *Global) GetSegment(index int) (Segment, error)

func (*Global) GetSegments added in v1.0.5

func (g *Global) GetSegments() []Segment

GetSegments returns Segments based on index.

func (*Global) Lookup added in v1.0.3

func (g *Global) Lookup(start *sqlparser.SQLVal, end *sqlparser.SQLVal) ([]Segment, error)

Lookup used to lookup partition(s). Global table returns all partitions.

func (*Global) Type added in v1.0.3

func (g *Global) Type() MethodType

Type returns the global type.

type GlobalRange added in v1.0.3

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

GlobalRange for Segment.Range.

func (*GlobalRange) Less added in v1.0.3

func (r *GlobalRange) Less(b KeyRange) bool

Less impl.

func (*GlobalRange) String added in v1.0.3

func (r *GlobalRange) String() string

String returns ”.

type Hash

type Hash struct {
	Segments []Segment `json:",omitempty"`
	// contains filtered or unexported fields
}

Hash tuple.

func NewHash

func NewHash(log *xlog.Log, slots int, conf *config.TableConfig) *Hash

NewHash creates new hash.

func (*Hash) Build

func (h *Hash) Build() error

Build used to build hash bitmap from schema config

func (*Hash) Clear

func (h *Hash) Clear() error

Clear used to clean hash partitions

func (*Hash) GetIndex added in v1.0.5

func (h *Hash) GetIndex(sqlval *sqlparser.SQLVal) (int, error)

GetIndex returns index based on sqlval.

func (*Hash) GetSegment added in v1.0.7

func (h *Hash) GetSegment(index int) (Segment, error)

func (*Hash) GetSegments added in v1.0.5

func (h *Hash) GetSegments() []Segment

GetSegments returns Segments based on index.

func (*Hash) Lookup

func (h *Hash) Lookup(start *sqlparser.SQLVal, end *sqlparser.SQLVal) ([]Segment, error)

Lookup used to lookup partition(s) through the sharding-key range Hash.Lookup only supports the type uint64/string

func (*Hash) Type

func (h *Hash) Type() MethodType

Type returns the hash type.

type HashRange

type HashRange struct {
	Start int
	End   int
}

HashRange tuple. [Start, End)

func (*HashRange) Less

func (r *HashRange) Less(b KeyRange) bool

Less impl.

func (*HashRange) String

func (r *HashRange) String() string

String returns start-end info.

type KeyRange

type KeyRange interface {
	String() string
	Less(KeyRange) bool
}

KeyRange tuple.

type List added in v1.0.8

type List struct {

	// Partition map
	Segments []Segment `json:",omitempty"`
	// contains filtered or unexported fields
}

List ...

func NewList added in v1.0.8

func NewList(log *xlog.Log, conf *config.TableConfig) *List

NewList creates new list.

func (*List) Build added in v1.0.8

func (list *List) Build() error

Build used to build list bitmap from schema config.

func (*List) Clear added in v1.0.8

func (list *List) Clear() error

Clear used to clean partitions.

func (*List) GetIndex added in v1.0.8

func (list *List) GetIndex(sqlval *sqlparser.SQLVal) (int, error)

GetIndex returns index based on sqlval.

func (*List) GetSegment added in v1.0.8

func (list *List) GetSegment(index int) (Segment, error)

GetSegment ...

func (*List) GetSegments added in v1.0.8

func (list *List) GetSegments() []Segment

GetSegments returns Segments based on index.

func (*List) Lookup added in v1.0.8

func (list *List) Lookup(start *sqlparser.SQLVal, end *sqlparser.SQLVal) ([]Segment, error)

Lookup used to lookup partition(s) through the sharding-key range List.Lookup only supports the type uint64/string.

func (*List) Type added in v1.0.8

func (list *List) Type() MethodType

Type returns the list type.

type ListRange added in v1.0.8

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

ListRange for Segment.Range.

func (*ListRange) Less added in v1.0.8

func (r *ListRange) Less(b KeyRange) bool

Less impl.

func (*ListRange) String added in v1.0.8

func (r *ListRange) String() string

String returns start-end info.

type MethodType

type MethodType string

MethodType type.

type Partition

type Partition interface {
	Build() error
	Type() MethodType
	Lookup(start *sqlparser.SQLVal, end *sqlparser.SQLVal) ([]Segment, error)
	GetIndex(sqlval *sqlparser.SQLVal) (int, error)
	GetSegments() []Segment
	GetSegment(index int) (Segment, error)
}

Partition interface.

type RDatabase

type RDatabase struct {
	DB     string
	Tables []*Table
}

RDatabase tuple.

type Router

type Router struct {

	// schemas map, key is database name
	Schemas map[string]*Schema `json:",omitempty"`
	// contains filtered or unexported fields
}

Router tuple.

func MockNewRouter

func MockNewRouter(log *xlog.Log) (*Router, func())

MockNewRouter mocks router.

func NewRouter

func NewRouter(log *xlog.Log, metadir string, conf *config.RouterConfig) *Router

NewRouter creates the new router.

func (*Router) AddForTest

func (r *Router) AddForTest(db string, confs ...*config.TableConfig) error

AddForTest used to add table config for test.

func (*Router) CheckDatabase added in v1.0.8

func (r *Router) CheckDatabase(db string) error

CheckDatabase is used to check the Database exist.

func (*Router) CheckTable added in v1.0.8

func (r *Router) CheckTable(database string, tableName string) (isExist bool, err error)

CheckTable is used to check the table exist.

func (*Router) CreateDatabase added in v1.0.6

func (r *Router) CreateDatabase(db string) error

func (*Router) CreateHashTable added in v1.0.9

func (r *Router) CreateHashTable(db, table, shardKey string, tableType string, backends []string, partitionNum *sqlparser.SQLVal, extra *Extra) error

CreateHashTable used to add a hash table to router and flush the schema to disk.

func (*Router) CreateListTable added in v1.0.8

func (r *Router) CreateListTable(db, table, shardKey string, tableType string,
	partitionDef sqlparser.PartitionDefinitions, extra *Extra) error

CreateListTable used to add a list table to router and flush the schema to disk.

func (*Router) CreateNonPartTable added in v1.0.9

func (r *Router) CreateNonPartTable(db, table, tableType string, backends []string, extra *Extra) error

CreateNonPartTable used to add a non-partitioned table to router and flush the schema to disk. Lock.

func (*Router) DatabaseACL

func (r *Router) DatabaseACL(database string) error

DatabaseACL used to check whether the database is a system database.

func (*Router) DropDatabase

func (r *Router) DropDatabase(db string) error

DropDatabase used to remove a database-schema from the schemas and remove all the table-schema files who belongs to this database.

func (*Router) DropTable

func (r *Router) DropTable(db, table string) error

DropTable used to remove a table from router and remove the schema file from disk.

func (*Router) GetIndex added in v1.0.5

func (r *Router) GetIndex(database, tableName string, sqlval *sqlparser.SQLVal) (int, error)

GetIndex returns index based on sqlval.

func (*Router) GetSegments added in v1.0.5

func (r *Router) GetSegments(database, tableName string, indexes []int) ([]Segment, error)

GetSegments returns Segments based on indexes.

func (*Router) GlobalUniform added in v1.0.3

func (r *Router) GlobalUniform(table string, backends []string) (*config.TableConfig, error)

GlobalUniform used to uniform the global table to backends.

func (*Router) HashUniform

func (r *Router) HashUniform(table, shardkey string, backends []string, partitionNum *sqlparser.SQLVal) (*config.TableConfig, error)

HashUniform used to uniform the hash slots to backends.

func (*Router) IsPartitionHash added in v1.0.8

func (r *Router) IsPartitionHash(partitionType MethodType) bool

IsPartitionHash used to check whether the partitionType is hash.

func (*Router) IsSystemDB added in v1.0.3

func (r *Router) IsSystemDB(database string) bool

IsSystemDB used to check whether the database is a system database.

func (*Router) JSON

func (r *Router) JSON() string

JSON returns the info of router.

func (*Router) ListUniform added in v1.0.8

func (r *Router) ListUniform(table string, shardkey string, partitionDef sqlparser.PartitionDefinitions) (*config.TableConfig, error)

ListUniform used to uniform the list table to backends.

func (*Router) LoadConfig

func (r *Router) LoadConfig() error

LoadConfig used to load all schemas stored in metadir. When an IO error occurs during the file reading, panic me.

func (*Router) Lookup

func (r *Router) Lookup(database string, tableName string, startKey *sqlparser.SQLVal, endKey *sqlparser.SQLVal) ([]Segment, error)

Lookup used to lookup a router(partition table name and backend) through db&table

func (*Router) PartitionRuleShift

func (r *Router) PartitionRuleShift(fromBackend string, toBackend string, database string, partitionTable string) error

PartitionRuleShift used to shift a rule from backend to another. The processes as: 1. change the backend in memory. 2. flush the table config to disk. 3. reload the config to memory. Note: If the reload fails, panic it since the config is in chaos.

func (*Router) PartitionType added in v1.0.8

func (r *Router) PartitionType(database string, tableName string) (MethodType, error)

PartitionType used to get PartitionType from given database and table name.

func (*Router) ReLoad

func (r *Router) ReLoad() error

ReLoad used to re-load the config files from disk to cache.

func (*Router) RefreshTable

func (r *Router) RefreshTable(db, table string) error

RefreshTable used to re-update the table from file. Lock.

func (*Router) RenameTable added in v1.0.8

func (r *Router) RenameTable(db, fromTable, toTable string) error

RenameTable used to rename a table from router and update the schema file on disk.

func (*Router) Rules

func (r *Router) Rules() *Rule

Rules returns router's schemas.

func (*Router) ShardKey

func (r *Router) ShardKey(database string, tableName string) (string, error)

ShardKey used to lookup shardkey from given database and table name.

func (*Router) SingleUniform added in v1.0.6

func (r *Router) SingleUniform(table string, backends []string) (*config.TableConfig, error)

SingleUniform used to uniform the single table to backends.

func (*Router) TableConfig

func (r *Router) TableConfig(database string, tableName string) (*config.TableConfig, error)

TableConfig returns the config by database and tableName.

func (*Router) Tables

func (r *Router) Tables() map[string][]string

Tables returns all the tables.

type Rule

type Rule struct {
	Schemas []RDatabase
}

Rule tuple.

type Schema

type Schema struct {
	// database name
	DB string `json:",omitempty"`
	// tables map, key is table name
	Tables map[string]*Table `json:",omitempty"`
}

Schema tuple.

type Segment

type Segment struct {
	// Segment table name.
	Table string `json:",omitempty"`
	// Segment backend name.
	Backend string `json:",omitempty"`
	// key range of this segment.
	Range KeyRange `json:",omitempty"`

	// partition list value.
	ListValue string `json:",omitempty"`
}

Segment tuple.

type Segments

type Segments []Segment

Segments slice.

func (Segments) Len

func (q Segments) Len() int

Len impl.

func (Segments) Less

func (q Segments) Less(i, j int) bool

Less impl.

func (Segments) Swap

func (q Segments) Swap(i, j int)

Segments impl.

type Single added in v1.0.6

type Single struct {

	// Segments slice.
	Segments []Segment `json:",omitempty"`
	// contains filtered or unexported fields
}

Single for single table router.

func NewSingle added in v1.0.6

func NewSingle(log *xlog.Log, conf *config.TableConfig) *Single

NewSingle creates new global.

func (*Single) Build added in v1.0.6

func (s *Single) Build() error

Build used to build Segments from schema config.

func (*Single) GetIndex added in v1.0.6

func (s *Single) GetIndex(sqlval *sqlparser.SQLVal) (int, error)

GetIndex returns index based on sqlval.

func (*Single) GetSegment added in v1.0.7

func (s *Single) GetSegment(index int) (Segment, error)

func (*Single) GetSegments added in v1.0.6

func (s *Single) GetSegments() []Segment

GetSegments returns Segments based on index.

func (*Single) Lookup added in v1.0.6

func (s *Single) Lookup(start *sqlparser.SQLVal, end *sqlparser.SQLVal) ([]Segment, error)

Lookup used to lookup partition(s).

func (*Single) Type added in v1.0.6

func (s *Single) Type() MethodType

Type returns the global type.

type SingleRange added in v1.0.6

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

SingleRange for Segment.Range.

func (*SingleRange) Less added in v1.0.6

func (r *SingleRange) Less(b KeyRange) bool

Less impl.

func (*SingleRange) String added in v1.0.6

func (r *SingleRange) String() string

String returns ”.

type Table

type Table struct {
	// Table name
	Name string `json:",omitempty"`
	// Shard key
	ShardKey string `json:",omitempty"`
	// partition method
	Partition Partition `json:",omitempty"`
	// table config.
	TableConfig *config.TableConfig `json:"-"`
}

Table tuple.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL