rule

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultNumberStepper = Stepper{U: Unum, N: 1}

Functions

func RegisterShardComputer

func RegisterShardComputer(typ string, factory ShardComputerFactory)

Types

type AutoIncrement

type AutoIncrement struct {
	Type   string
	Option map[string]string
}

type DatabaseTable

type DatabaseTable struct {
	Database, Table string
}

DatabaseTable represents the pair of database and table.

type DatabaseTables

type DatabaseTables map[string][]string

DatabaseTables represents a bundle of databases and tables. Deprecated: will use Shards instead in the future.

func (DatabaseTables) And

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

func (dt DatabaseTables) Len() int

Len returns amount of tables.

func (DatabaseTables) Or

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

func (ru *Rule) Has(table string) bool

Has return true if the table exists.

func (*Rule) MustVTable

func (ru *Rule) MustVTable(name string) *VTable

MustVTable returns the VTable with given table name, panic if not exist.

func (*Rule) Range

func (ru *Rule) Range(f func(table string, vt *VTable) bool)

Range ranges each VTable

func (*Rule) RemoveVTable

func (ru *Rule) RemoveVTable(table string) bool

RemoveVTable removes the VTable with given table.

func (*Rule) SetVTable

func (ru *Rule) SetVTable(table string, vt *VTable)

SetVTable sets a VTable.

func (*Rule) VTable

func (ru *Rule) VTable(table string) (*VTable, bool)

VTable returns the VTable with given table name.

func (*Rule) VTables

func (ru *Rule) VTables() map[string]*VTable

VTables returns all the VTable

type ShardColumn

type ShardColumn struct {
	Name    string
	Steps   int
	Stepper Stepper
}

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 Shards

type Shards btree.BTree

func IntersectionShards

func IntersectionShards(first, second *Shards, others ...*Shards) *Shards

func NewShards

func NewShards() *Shards

func UnionShards

func UnionShards(first, second *Shards, others ...*Shards) *Shards

func (*Shards) Add

func (sd *Shards) Add(db, table uint32, otherTables ...uint32)

func (*Shards) Each

func (sd *Shards) Each(h func(db, tb uint32) bool)

func (*Shards) Len

func (sd *Shards) Len() int

func (*Shards) Max

func (sd *Shards) Max() (db, tb uint32, ok bool)

func (*Shards) Min

func (sd *Shards) Min() (db, tb uint32, ok bool)

func (*Shards) Remove

func (sd *Shards) Remove(db, table uint32, otherTables ...uint32)

func (*Shards) String

func (sd *Shards) String() string

type StepUnit

type StepUnit int8

StepUnit represents the unit of a Stepper.

const (
	Uhour StepUnit
	Uday
	Uweek
	Umonth
	Uyear
	Unum
	Ustr
)

func (StepUnit) IsTime

func (u StepUnit) IsTime() bool

IsTime returns true if the unit is time.

func (StepUnit) String

func (u StepUnit) String() string

type Stepper

type Stepper struct {
	N int      // N is the step value.
	U StepUnit // U is the step unit.
}

Stepper represents the value stepper in a sharding rule.

func (Stepper) After

func (s Stepper) After(offset interface{}) (interface{}, error)

func (Stepper) Ascend

func (s Stepper) Ascend(offset interface{}, n int) (Range, error)

func (Stepper) Before

func (s Stepper) Before(offset interface{}) (interface{}, error)

func (Stepper) Descend

func (s Stepper) Descend(offset interface{}, n int) (Range, error)

func (Stepper) String

func (s Stepper) String() string

type Topology

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

Topology represents the topology of databases and tables.

func (*Topology) Each

func (to *Topology) Each(onEach func(dbIdx, tbIdx int) (ok bool)) bool

Each enumerates items in current Topology.

func (*Topology) Enumerate

func (to *Topology) Enumerate() DatabaseTables

func (*Topology) EnumerateDatabases

func (to *Topology) EnumerateDatabases() []string

func (*Topology) Exists

func (to *Topology) Exists(dbIdx, tbIdx int) bool

func (*Topology) Largest

func (to *Topology) Largest() (db, tb string, ok bool)

func (*Topology) Len

func (to *Topology) Len() (dbLen int, tblLen int)

Len returns the length of database and table.

func (*Topology) Render

func (to *Topology) Render(dbIdx, tblIdx int) (string, string, bool)

Render renders the name of database and table from indexes.

func (*Topology) SetRender

func (to *Topology) SetRender(dbRender, tbRender func(int) string)

SetRender sets the database/table name render.

func (*Topology) SetTopology

func (to *Topology) SetTopology(db int, tables ...int)

SetTopology sets the topology.

func (*Topology) Smallest

func (to *Topology) Smallest() (db, tb string, ok bool)

type VShard

type VShard struct {
	sync.Once
	DB, Table *ShardMetadata
	// contains filtered or unexported fields
}

func (*VShard) Len

func (vs *VShard) Len() int

func (*VShard) Variables

func (vs *VShard) Variables() []string

type VTable

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

VTable represents a virtual/logical table.

func (*VTable) AddVShards

func (vt *VTable) AddVShards(shard *VShard)

func (*VTable) AllowFullScan

func (vt *VTable) AllowFullScan() bool

func (*VTable) GetAutoIncrement

func (vt *VTable) GetAutoIncrement() *AutoIncrement

func (*VTable) GetShardMetaDataJSON

func (vt *VTable) GetShardMetaDataJSON() (map[string]string, error)

func (*VTable) GetVShards

func (vt *VTable) GetVShards() []*VShard

func (*VTable) HasVShard

func (vt *VTable) HasVShard(keys ...string) bool

func (*VTable) Name

func (vt *VTable) Name() string

func (*VTable) SearchVShard

func (vt *VTable) SearchVShard(keys ...string) (*VShard, bool)

func (*VTable) SetAllowFullScan

func (vt *VTable) SetAllowFullScan(allow bool)

func (*VTable) SetAutoIncrement

func (vt *VTable) SetAutoIncrement(seq *AutoIncrement)

func (*VTable) SetName

func (vt *VTable) SetName(name string)

func (*VTable) SetTopology

func (vt *VTable) SetTopology(topology *Topology)

SetTopology sets the topology.

func (*VTable) Shard

func (vt *VTable) Shard(inputs map[string]proto.Value) (uint32, uint32, error)

Shard returns the shard result.

func (*VTable) Topology

func (vt *VTable) Topology() *Topology

Topology returns the topology of VTable.

Jump to

Keyboard shortcuts

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