Documentation ¶
Index ¶
- Variables
- func RegisterShardComputer(typ string, factory ShardComputerFactory)
- type AutoIncrement
- type DatabaseTable
- type DatabaseTables
- func (dt DatabaseTables) And(other DatabaseTables) DatabaseTables
- func (dt DatabaseTables) IsConfused() bool
- func (dt DatabaseTables) IsEmpty() bool
- func (dt DatabaseTables) IsFullScan() bool
- func (dt DatabaseTables) Largest() (db, tbl string)
- func (dt DatabaseTables) Len() int
- func (dt DatabaseTables) Or(other DatabaseTables) DatabaseTables
- func (dt DatabaseTables) Smallest() (db, tbl string)
- func (dt DatabaseTables) String() string
- type FuncShardComputerFactory
- type Range
- type Rule
- func (ru *Rule) Has(table string) bool
- func (ru *Rule) MustVTable(name string) *VTable
- func (ru *Rule) Range(f func(table string, vt *VTable) bool)
- func (ru *Rule) RemoveVTable(table string) bool
- func (ru *Rule) SetVTable(table string, vt *VTable)
- func (ru *Rule) VTable(table string) (*VTable, bool)
- func (ru *Rule) VTables() map[string]*VTable
- type ShardColumn
- type ShardComputer
- type ShardComputerFactory
- type ShardMetadata
- type Shards
- func (sd *Shards) Add(db, table uint32, otherTables ...uint32)
- func (sd *Shards) Each(h func(db, tb uint32) bool)
- func (sd *Shards) Len() int
- func (sd *Shards) Max() (db, tb uint32, ok bool)
- func (sd *Shards) Min() (db, tb uint32, ok bool)
- func (sd *Shards) Remove(db, table uint32, otherTables ...uint32)
- func (sd *Shards) String() string
- type StepUnit
- type Stepper
- type Topology
- func (to *Topology) Each(onEach func(dbIdx, tbIdx int) (ok bool)) bool
- func (to *Topology) Enumerate() DatabaseTables
- func (to *Topology) EnumerateDatabases() []string
- func (to *Topology) Exists(dbIdx, tbIdx int) bool
- func (to *Topology) Largest() (db, tb string, ok bool)
- func (to *Topology) Len() (dbLen int, tblLen int)
- func (to *Topology) Render(dbIdx, tblIdx int) (string, string, bool)
- func (to *Topology) SetRender(dbRender, tbRender func(int) string)
- func (to *Topology) SetTopology(db int, tables ...int)
- func (to *Topology) Smallest() (db, tb string, ok bool)
- type VShard
- type VTable
- func (vt *VTable) AddVShards(shard *VShard)
- func (vt *VTable) AllowFullScan() bool
- func (vt *VTable) GetAutoIncrement() *AutoIncrement
- func (vt *VTable) GetShardMetaDataJSON() (map[string]string, error)
- func (vt *VTable) GetVShards() []*VShard
- func (vt *VTable) HasVShard(keys ...string) bool
- func (vt *VTable) Name() string
- func (vt *VTable) SearchVShard(keys ...string) (*VShard, bool)
- func (vt *VTable) SetAllowFullScan(allow bool)
- func (vt *VTable) SetAutoIncrement(seq *AutoIncrement)
- func (vt *VTable) SetName(name string)
- func (vt *VTable) SetTopology(topology *Topology)
- func (vt *VTable) Shard(inputs map[string]proto.Value) (uint32, uint32, error)
- func (vt *VTable) Topology() *Topology
Constants ¶
This section is empty.
Variables ¶
var DefaultNumberStepper = Stepper{U: Unum, N: 1}
Functions ¶
func RegisterShardComputer ¶
func RegisterShardComputer(typ string, factory ShardComputerFactory)
Types ¶
type AutoIncrement ¶
type DatabaseTable ¶
type DatabaseTable struct {
Database, Table string
}
DatabaseTable represents the pair of database and table.
type DatabaseTables ¶
DatabaseTables represents a bundle of databases and tables. Deprecated: will use Shards instead in the future.
func (DatabaseTables) And ¶
func (dt DatabaseTables) And(other DatabaseTables) DatabaseTables
And returns the intersection of two DatabaseTables.
func (DatabaseTables) IsConfused ¶
func (dt DatabaseTables) IsConfused() bool
IsConfused returns weather the database tables contains conflicts.
func (DatabaseTables) IsEmpty ¶
func (dt DatabaseTables) IsEmpty() bool
IsEmpty returns true if the current DatabaseTables is empty.
func (DatabaseTables) IsFullScan ¶
func (dt DatabaseTables) IsFullScan() bool
IsFullScan returns true if the current DatabaseTables will cause full scan.
func (DatabaseTables) Largest ¶
func (dt DatabaseTables) Largest() (db, tbl string)
Largest returns the largest pair of database and table.
func (DatabaseTables) Or ¶
func (dt DatabaseTables) Or(other DatabaseTables) DatabaseTables
Or returns the union of two DatabaseTables.
func (DatabaseTables) Smallest ¶
func (dt DatabaseTables) Smallest() (db, tbl string)
Smallest returns the smallest pair of database and table.
func (DatabaseTables) String ¶
func (dt DatabaseTables) String() string
type FuncShardComputerFactory ¶
type FuncShardComputerFactory func([]string, string) (ShardComputer, error)
func (FuncShardComputerFactory) Apply ¶
func (f FuncShardComputerFactory) Apply(columns []string, expr string) (ShardComputer, error)
type Range ¶
type Range interface { // HasNext returns true if Range is not EOF. HasNext() bool // Next returns the next value. Next() interface{} }
Range represents a value range.
type Rule ¶
type Rule struct {
// contains filtered or unexported fields
}
Rule represents sharding rule, a Rule contains multiple logical tables.
func (*Rule) MustVTable ¶
MustVTable returns the VTable with given table name, panic if not exist.
func (*Rule) RemoveVTable ¶
RemoveVTable removes the VTable with given table.
type ShardColumn ¶
ShardColumn represents the shard column.
type ShardComputer ¶
type ShardComputer interface { // Variables returns the variable names. Variables() []string // Compute computes the shard index. Compute(values ...proto.Value) (int, error) }
ShardComputer computes the shard index from an input value.
func NewComputer ¶
func NewComputer(typ string, columns []string, expr string) (ShardComputer, error)
type ShardComputerFactory ¶
type ShardComputerFactory interface {
Apply(columns []string, expr string) (ShardComputer, error)
}
type ShardMetadata ¶
type ShardMetadata struct { ShardColumns []*ShardColumn Computer ShardComputer // compute shards }
ShardMetadata represents the metadata of shards.
func (*ShardMetadata) GetShardColumn ¶
func (sm *ShardMetadata) GetShardColumn(name string) *ShardColumn
type StepUnit ¶
type StepUnit int8
StepUnit represents the unit of a Stepper.
const ( Uhour StepUnit Uday Uweek Umonth Uyear Unum Ustr )
type Topology ¶
type Topology struct {
// contains filtered or unexported fields
}
Topology represents the topology of databases and tables.
func (*Topology) Enumerate ¶
func (to *Topology) Enumerate() DatabaseTables
func (*Topology) EnumerateDatabases ¶
func (*Topology) SetTopology ¶
SetTopology sets the topology.
type VShard ¶
type VShard struct { sync.Once DB, Table *ShardMetadata // contains filtered or unexported fields }
type VTable ¶
type VTable struct {
// contains filtered or unexported fields
}
VTable represents a virtual/logical table.
func (*VTable) AddVShards ¶
func (*VTable) AllowFullScan ¶
func (*VTable) GetAutoIncrement ¶
func (vt *VTable) GetAutoIncrement() *AutoIncrement
func (*VTable) GetShardMetaDataJSON ¶
func (*VTable) GetVShards ¶
func (*VTable) SetAllowFullScan ¶
func (*VTable) SetAutoIncrement ¶
func (vt *VTable) SetAutoIncrement(seq *AutoIncrement)
func (*VTable) SetTopology ¶
SetTopology sets the topology.