meta

package
v0.0.0-...-b26f8fd Latest Latest
Warning

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

Go to latest
Published: May 24, 2016 License: Apache-2.0 Imports: 10 Imported by: 5

Documentation

Index

Constants

View Source
const (
	Perfix     = "/rambo"
	ProxyNodes = Perfix + "/proxy_nodes"

	UserInfo = Perfix + "/user_info"
	Password = "/password"
	DB       = "/db"
	Backends = "/backends" // DB's sub dir.   // Scheme   = "/scheme"   // DB's sub dir.
	Config   = "/config"   // DB's sub dir.
	Tables   = "/tables"   // DB's sub dir.

	// MysqlInfo is Mysql backends' config.
	// MysqlInfo is a dir.
	// each backend node's config record in a name which named
	// by the backend's name.
	MysqlInfo = Perfix + "/mysql_info"

	Hash  = "hash"
	Range = "range"
	CHash = "chash"

	DDLInfo    = Perfix + "/ddl_info"
	TaskStatus = "task_status" // DDLInfo/[user]/TaskStatus/[task_id]
	Masters    = "/masters"    // k: user id, v: node addr
	TaskQueue  = "/task_queue" // k: user id, v: ddl excute plan
	Lock       = "/lock"       // k: user/db/table, v: "lock"

	AutoKey = Perfix + "/auto_key"
)
View Source
const (
	NotFound     = 100
	NotEqual     = 101
	AlreadyExist = 105
)

etcd error code

View Source
const (
	Delete = "delete"
	Set    = "set"
	Create = "create"
	Update = "update"
	Expire = "expire"
	Get    = "get"
	CAS    = "compareAndSwap"
	CAD    = "compareAndDelete"
)

etcd action

View Source
const (
	TypeKeyInt = iota
	TypeKeyString
	TypeKeyUnknow
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend struct {
	Seq        int        `json:"seq"`
	Host       string     `json:"host"`
	UserName   string     `json:"user-name"`
	Password   string     `json:"password"`
	Name       string     `json:"name"` // backend's name
	ParentNode *MysqlNode `json:"parent"`
}

Backend is one of user's backends

type Database

type Database struct {
	Name     string     `json:"name"`
	Backends []*Backend `json:"backends"`
}

Database is global database config.

type Election

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

Election is elect leader in etcd

func NewElection

func NewElection(machines []string, dir string, ttl uint64, cb func(key string), localValue string) *Election

func (*Election) GetMaster

func (e *Election) GetMaster(key string) (string, error)

GetMaster get master node if master node is not exist, it will elect new one

func (*Election) Stop

func (e *Election) Stop()

Stop will stop Election

func (*Election) Watch

func (e *Election) Watch()

Watch will watch keys with e.key perfix one instance only will called once

type Info

type Info struct {
	*etcd.Client
}

Info is metaDB's global public instance.

func NewInfo

func NewInfo(machines []string) *Info

NewInfo get a new meta information manage

func (*Info) AddBDatabase

func (m *Info) AddBDatabase(db *Database) error

func (*Info) AddUser

func (m *Info) AddUser(user, password string) error

func (*Info) CheckUser

func (m *Info) CheckUser(user string, auth []byte, salt []byte, db string) bool

func (*Info) CheckUserDirect

func (m *Info) CheckUserDirect(user, password string) bool

func (*Info) CreateAndHeartBeat

func (m *Info) CreateAndHeartBeat(key, value string, ttl uint64, isThrow bool) (stop func(), err error)

CreateAndHeartBeat create a k/v in etcd. And half a ttl, is will refresh the kv's ttl. If fail, will return an error. If error is nil it will return a named Stop function, it will stop the update tick.

func (*Info) GetAllProxyNodes

func (m *Info) GetAllProxyNodes() ([]string, error)

GetAllProxyNodes will get all proxy nodes

func (*Info) GetAutoKey

func (m *Info) GetAutoKey(user, db, table, key string, interval uint64) (uint64, error)

func (*Info) GetDBs

func (m *Info) GetDBs(user, db string) ([]*Backend, error)

GetDBs get all sub backends of specifical dbname

func (*Info) GetMaster

func (d *Info) GetMaster(user string) (master string, err error)

key is user id one user has one master

func (*Info) GetMysqlNodes

func (m *Info) GetMysqlNodes() ([]*MysqlNode, error)

GetMysqlNodes get all mysql backend nodes

func (*Info) GetTable

func (m *Info) GetTable(user, db, table string) (*Table, error)

func (*Info) GetTaskStatus

func (d *Info) GetTaskStatus(user, id string) ([]byte, error)

GetTaskStatus get task's status

func (*Info) GetTasks

func (d *Info) GetTasks(user string) (etcd.Nodes, error)

GetTasks get the user's all tasks

func (*Info) GetUserInfo

func (m *Info) GetUserInfo(user string) (*etcd.Response, error)

func (*Info) IsDBExist

func (m *Info) IsDBExist(user, db string) (bool, error)

func (*Info) IsTableExist

func (m *Info) IsTableExist(user, db, table string) (bool, error)

func (*Info) Lock

func (d *Info) Lock(key string, id string, seq int64) error

func (*Info) SaveCreateDatabase

func (d *Info) SaveCreateDatabase(user, db, tid string, backends []*Backend) error

SaveCreateDatabase save db info into etcd

func (*Info) SaveCreateTable

func (d *Info) SaveCreateTable(user, db, tid string, table *Table) error

SaveCreateTable save table info into etcd

func (*Info) SaveDDLTask

func (d *Info) SaveDDLTask(v interface{}, user string) (string, error)

SaveDDLTask save ddl task, return the task id

func (*Info) SetTaskStatus

func (d *Info) SetTaskStatus(user, id string, data []byte) error

SetTaskStatus set task's status

func (*Info) ShowDatabases

func (m *Info) ShowDatabases(user string) ([]string, error)

func (*Info) ShowTables

func (m *Info) ShowTables(user, db string) ([]string, error)

func (*Info) UnLock

func (d *Info) UnLock(key string, id string, seq int64) error

func (*Info) UpdateTask

func (d *Info) UpdateTask(user, id, value string) error

UpdateTask will update this task

type Key

type Key struct {
	Name  string `json:"name"`
	Type  int    `json:"type"`
	Index int    `json:"index"`
}

type MysqlNode

type MysqlNode struct {
	Host     string `json:"host"`
	UserName string `json:"user-name"`
	Password string `json:"password"`
	Name     string `json:"name"` // node's name
}

MysqlNode is one mysql server.

type SortBackends

type SortBackends []*Backend

func (SortBackends) Len

func (s SortBackends) Len() int

func (SortBackends) Less

func (s SortBackends) Less(i, j int) bool

func (SortBackends) Swap

func (s SortBackends) Swap(i, j int)

type Table

type Table struct {
	Name         string `json:"name"`
	Scheme       string `json:"scheme"` // default is `hash`
	PartitionKey *Key   `json:"partition-key"`
	AutoKeys     []*Key `json:"auto-keys"`
	ColsLen      int    `json:"col-len"`
	AutoIns      []*Key `json:"auto-ins"`
}

Table is mysql table meta info.

Jump to

Keyboard shortcuts

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