model

package
v0.0.0-...-17b9906 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2014 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NodeUpStatus   = "up"
	NodeDownStatus = "down"
)
View Source
const (
	NodeMasterType = "master"
	NodeSlaveType  = "slave"
)
View Source
const (
	GroupUpStatus   = "up"
	GroupDownStatus = "down"
)
View Source
const (
	ProxyStatusUp   = "up"
	ProxyStatusDown = "down"
)
View Source
const (
	RouteTypeHash  = "hash"
	RouteTypeRange = "range"
)

Variables

This section is empty.

Functions

func Hash

func Hash(name string, data []byte) uint32

func RegisterHashFunc

func RegisterHashFunc(name string, fn HashFunc)

Types

type Action

type Action struct {
}

type Group

type Group struct {
	ID     int    `json:"id"`
	Status string `json:"status"`
	Nodes  []Node `json:"-"`
}

Group includes one or more MySQL instances A group must have a master, none or more slaves

type HashFunc

type HashFunc func([]byte) uint32

type Node

type Node struct {
	GroupID int    `json:"group_id"`
	Addr    string `json:"addr"`
	Type    string `json:"type"`
	Status  string `json:"status"`
	Weight  int    `json:"weight"`
}

Node is a MySQL instance

type NodeSlice

type NodeSlice []Node

func (NodeSlice) Len

func (ns NodeSlice) Len() int

func (NodeSlice) Less

func (ns NodeSlice) Less(i, j int) bool

master node is at the beginning for same type, higher weight is in front

func (NodeSlice) Swap

func (ns NodeSlice) Swap(i, j int)

type Proxy

type Proxy struct {
	// For MySQL protocol communication
	Addr string `json:"addr"`

	// Proxy HTTP communication
	HttpAddr string `json:"http_addr"`

	Status string `json:"status"`
}

Proxy is proxy server

type Route

type Route struct {
	DB     string `json:"db"`
	Table  string `json:"table"`
	Column string `json:"column"`
	Type   string `json:"type"`

	// For hash type
	// crc32, adler32, or you can use your own hash function if registered
	// default is crc32
	Hash string `json:"hash"`

	// For range type
	// key format 1-10000, left close and right open
	// value is sub table id
	// e.g, if the ranges is {"0-100" : 0, "100-200" : 1}
	// if a key is 50, we may know that the data will be saved in table_0
	Ranges map[string]int `json:"ranges"`
}

We will route to let a SQL exexuted in the exact group

type Schema

type Schema struct {
	Name string `json:"name"`

	GroupIDs []int `json:"group_ids"`

	// The default group for the table stored
	DefaultGroupID int `json:"default_group_id"`

	// Later use, todo, maybe for migrate
	Status string `json:"status"`
}

Schema is MySQL database, and can be stored in one or more groups.

type Table

type Table struct {
	DB string `json:"db"`

	Name string `json:"name"`

	// If the table is not splitted, it will be stored in this group
	GroupID int `json:"group_id"`

	// If the table is splitted, e.g. a user table, may be splitted into 1024,
	// so the real table may be stored in different groups
	// like user_0 stored in group_0, user_1 stored in group_1
	// the sub table id must start from 0, so we can use a slice to map
	// the table id -> group id
	SubTables []int `json:"sub_tables"`

	// Later use, todo, maybe for migrate
	Status string `json:"status"`
}

Jump to

Keyboard shortcuts

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