Documentation ¶
Index ¶
- Constants
- Variables
- func MockNewRouterConfig() *config.RouterConfig
- func MockTable64Config() *config.TableConfig
- func MockTableAConfig() *config.TableConfig
- func MockTableBConfig() *config.TableConfig
- func MockTableCConfig() *config.TableConfig
- func MockTableDeadLockConfig() *config.TableConfig
- func MockTableE1Config() *config.TableConfig
- func MockTableG1Config() *config.TableConfig
- func MockTableGConfig() *config.TableConfig
- func MockTableGreaterThanConfig() *config.TableConfig
- func MockTableInvalidConfig() *config.TableConfig
- func MockTableList1Config() *config.TableConfig
- func MockTableListConfig() *config.TableConfig
- func MockTableMConfig() *config.TableConfig
- func MockTableOverlapConfig() *config.TableConfig
- func MockTableRConfig() *config.TableConfig
- func MockTableSConfig() *config.TableConfig
- func MockTableSegmentEndErrConfig() *config.TableConfig
- func MockTableSegmentErr1Config() *config.TableConfig
- func MockTableSegmentStartErrConfig() *config.TableConfig
- type DatabaseACL
- type Extra
- type Global
- func (g *Global) Build() error
- func (g *Global) GetIndex(sqlval *sqlparser.SQLVal) (int, error)
- func (g *Global) GetSegment(index int) (Segment, error)
- func (g *Global) GetSegments() []Segment
- func (g *Global) Lookup(start *sqlparser.SQLVal, end *sqlparser.SQLVal) ([]Segment, error)
- func (g *Global) Type() MethodType
- type GlobalRange
- type Hash
- func (h *Hash) Build() error
- func (h *Hash) Clear() error
- func (h *Hash) GetIndex(sqlval *sqlparser.SQLVal) (int, error)
- func (h *Hash) GetSegment(index int) (Segment, error)
- func (h *Hash) GetSegments() []Segment
- func (h *Hash) Lookup(start *sqlparser.SQLVal, end *sqlparser.SQLVal) ([]Segment, error)
- func (h *Hash) Type() MethodType
- type HashRange
- type KeyRange
- type List
- func (list *List) Build() error
- func (list *List) Clear() error
- func (list *List) GetIndex(sqlval *sqlparser.SQLVal) (int, error)
- func (list *List) GetSegment(index int) (Segment, error)
- func (list *List) GetSegments() []Segment
- func (list *List) Lookup(start *sqlparser.SQLVal, end *sqlparser.SQLVal) ([]Segment, error)
- func (list *List) Type() MethodType
- type ListRange
- type MethodType
- type Partition
- type RDatabase
- type Router
- func (r *Router) AddForTest(db string, confs ...*config.TableConfig) error
- func (r *Router) CheckDatabase(db string) error
- func (r *Router) CheckTable(database string, tableName string) (isExist bool, err error)
- func (r *Router) CreateDatabase(db string) error
- func (r *Router) CreateHashTable(db, table, shardKey string, tableType string, backends []string, ...) error
- func (r *Router) CreateListTable(db, table, shardKey string, tableType string, ...) error
- func (r *Router) CreateNonPartTable(db, table, tableType string, backends []string, extra *Extra) error
- func (r *Router) DatabaseACL(database string) error
- func (r *Router) DropDatabase(db string) error
- func (r *Router) DropTable(db, table string) error
- func (r *Router) GetIndex(database, tableName string, sqlval *sqlparser.SQLVal) (int, error)
- func (r *Router) GetSegments(database, tableName string, indexes []int) ([]Segment, error)
- func (r *Router) GlobalUniform(table string, backends []string) (*config.TableConfig, error)
- func (r *Router) HashUniform(table, shardkey string, backends []string, partitionNum *sqlparser.SQLVal) (*config.TableConfig, error)
- func (r *Router) IsPartitionHash(partitionType MethodType) bool
- func (r *Router) IsSystemDB(database string) bool
- func (r *Router) JSON() string
- func (r *Router) ListUniform(table string, shardkey string, partitionDef sqlparser.PartitionDefinitions) (*config.TableConfig, error)
- func (r *Router) LoadConfig() error
- func (r *Router) Lookup(database string, tableName string, startKey *sqlparser.SQLVal, ...) ([]Segment, error)
- func (r *Router) PartitionRuleShift(fromBackend string, toBackend string, database string, partitionTable string) error
- func (r *Router) PartitionType(database string, tableName string) (MethodType, error)
- func (r *Router) ReLoad() error
- func (r *Router) RefreshTable(db, table string) error
- func (r *Router) RenameTable(db, fromTable, toTable string) error
- func (r *Router) Rules() *Rule
- func (r *Router) ShardKey(database string, tableName string) (string, error)
- func (r *Router) SingleUniform(table string, backends []string) (*config.TableConfig, error)
- func (r *Router) TableConfig(database string, tableName string) (*config.TableConfig, error)
- func (r *Router) Tables() map[string][]string
- type Rule
- type Schema
- type Segment
- type Segments
- type Single
- func (s *Single) Build() error
- func (s *Single) GetIndex(sqlval *sqlparser.SQLVal) (int, error)
- func (s *Single) GetSegment(index int) (Segment, error)
- func (s *Single) GetSegments() []Segment
- func (s *Single) Lookup(start *sqlparser.SQLVal, end *sqlparser.SQLVal) ([]Segment, error)
- func (s *Single) Type() MethodType
- type SingleRange
- type Table
Constants ¶
const ( TableTypeSingle = "single" TableTypeGlobal = "global" TableTypeUnknown = "unknown" TableTypePartitionHash = "hash" TableTypePartitionList = "list" TableTypePartitionRange = "range" )
const ( NAME_CHAR_LEN = 64 TABLE_NAME_SUFFIX = 5 // table name suffix: "_0032" )
const ( // methodTypeHash type. MethodTypeHash = "HASH" MethodTypeGlobal = "GLOBAL" MethodTypeSingle = "SINGLE" MethodTypeList = "LIST" )
Variables ¶
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 ¶
func MockNewRouterConfig() *config.RouterConfig
MockNewRouterConfig returns the router config.
func MockTableDeadLockConfig ¶
func MockTableDeadLockConfig() *config.TableConfig
MockTableDeadLockConfig config.
func MockTableE1Config ¶
func MockTableE1Config() *config.TableConfig
MockTableE1Config config, unsupport shardtype.
func MockTableG1Config ¶
func MockTableG1Config() *config.TableConfig
MockTableG1Config config, global shardtype.
func MockTableGConfig ¶
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 ¶
func MockTableList1Config() *config.TableConfig
MockTableList1Config config, list shardtype.
func MockTableListConfig ¶
func MockTableListConfig() *config.TableConfig
MockTableListConfig config, list shardtype.
func MockTableOverlapConfig ¶
func MockTableOverlapConfig() *config.TableConfig
MockTableOverlapConfig config.
func MockTableSConfig ¶
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 (*DatabaseACL) Allow ¶
func (acl *DatabaseACL) Allow(db string) bool
Allow used to check to see if the db is system database.
func (*DatabaseACL) IsSystemDB ¶
func (acl *DatabaseACL) IsSystemDB(db string) bool
IsSystemDB used to check to see if the db is system database.
type Extra ¶
type Extra struct {
AutoIncrement *config.AutoIncrement
}
Extra -- router extra params.
type Global ¶
type Global struct { // Segments slice. Segments []Segment `json:",omitempty"` // contains filtered or unexported fields }
Global for global table router.
func NewGlobal ¶
func NewGlobal(log *xlog.Log, conf *config.TableConfig) *Global
NewGlobal creates new global.
func (*Global) GetSegments ¶
GetSegments returns Segments based on index.
type GlobalRange ¶
type GlobalRange struct {
// contains filtered or unexported fields
}
GlobalRange for Segment.Range.
type Hash ¶
type Hash struct { Segments []Segment `json:",omitempty"` // contains filtered or unexported fields }
Hash tuple.
func (*Hash) GetSegments ¶
GetSegments returns Segments based on index.
type List ¶
type List struct { // Partition map Segments []Segment `json:",omitempty"` // contains filtered or unexported fields }
List ...
func NewList ¶
func NewList(log *xlog.Log, conf *config.TableConfig) *List
NewList creates new list.
func (*List) GetSegments ¶
GetSegments returns Segments based on index.
type ListRange ¶
type ListRange struct {
// contains filtered or unexported fields
}
ListRange for Segment.Range.
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 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 ¶
MockNewRouter mocks 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 ¶
CheckDatabase is used to check the Database exist.
func (*Router) CheckTable ¶
CheckTable is used to check the table exist.
func (*Router) CreateDatabase ¶
func (*Router) CreateHashTable ¶
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 ¶
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 ¶
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 ¶
DatabaseACL used to check whether the database is a system database.
func (*Router) DropDatabase ¶
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 ¶
DropTable used to remove a table from router and remove the schema file from disk.
func (*Router) GetSegments ¶
GetSegments returns Segments based on indexes.
func (*Router) GlobalUniform ¶
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 ¶
func (r *Router) IsPartitionHash(partitionType MethodType) bool
IsPartitionHash used to check whether the partitionType is hash.
func (*Router) IsSystemDB ¶
IsSystemDB used to check whether the database is a system database.
func (*Router) ListUniform ¶
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 ¶
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 ¶
func (r *Router) PartitionType(database string, tableName string) (MethodType, error)
PartitionType used to get PartitionType from given database and table name.
func (*Router) RefreshTable ¶
RefreshTable used to re-update the table from file. Lock.
func (*Router) RenameTable ¶
RenameTable used to rename a table from router and update the schema file on disk.
func (*Router) SingleUniform ¶
SingleUniform used to uniform the single table to backends.
func (*Router) TableConfig ¶
TableConfig returns the config by database and tableName.
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 Single ¶
type Single struct { // Segments slice. Segments []Segment `json:",omitempty"` // contains filtered or unexported fields }
Single for single table router.
func NewSingle ¶
func NewSingle(log *xlog.Log, conf *config.TableConfig) *Single
NewSingle creates new global.
func (*Single) GetSegments ¶
GetSegments returns Segments based on index.
type SingleRange ¶
type SingleRange struct {
// contains filtered or unexported fields
}
SingleRange for Segment.Range.