server

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2018 License: Apache-2.0 Imports: 52 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultHttpPort    = 8080
	DefaultLockRpcPort = 8090
	DefaultSqlPort     = 6060

	DefaultServerName = "gateway"

	DefaultInsertSlowLog = 20 * time.Millisecond
	DefaultSelectSlowLog = 100 * time.Millisecond
	DefaultDeleteSlowLog = 20 * time.Millisecond

	DefaultMaxWorkNum      = 100
	DefaultMaxTaskQueueLen = 10000
	DefaultGrpcPoolSize    = 3
	DefaultGrpcInitWinSize = 64 * 1024
	DefaultMaxSlowLogLen   = 10

	DefaultMaxRawCount = 10000
)
View Source
const (
	Master = "master"
	Slave  = "slave"

	ServerRegion = "server"
	NodeRegion   = "node"

	//op
	ADMIN_OPT_ADD     = "add"
	ADMIN_OPT_DEL     = "del"
	ADMIN_OPT_UP      = "up"
	ADMIN_OPT_DOWN    = "down"
	ADMIN_OPT_SHOW    = "show"
	ADMIN_OPT_CHANGE  = "change"
	ADMIN_SAVE_CONFIG = "save"

	ADMIN_PROXY         = "proxy"
	ADMIN_NODE          = "node"
	ADMIN_SCHEMA        = "schema"
	ADMIN_LOG_SQL       = "log_sql"
	ADMIN_SLOW_LOG_TIME = "slow_log_time"
	ADMIN_ALLOW_IP      = "allow_ip"
	ADMIN_BLACK_SQL     = "black_sql"

	ADMIN_CONFIG = "config"
	ADMIN_STATUS = "status"
)
View Source
const (
	MasterComment    = "/*master*/"
	SumFunc          = "sum"
	CountFunc        = "count"
	MaxFunc          = "max"
	MinFunc          = "min"
	LastInsertIdFunc = "last_insert_id"
	FUNC_EXIST       = 1
)
View Source
const (
	LOCK_OK = iota
	LOCK_EXIST_ERROR
	LOCK_NOT_EXIST_ERROR
	LOCK_NOT_OWNER_ERROR
	LOCK_FORCE_UNLOCK_ERROR
	LOCK_STORE_ERROR
	LOCK_EPOCH_ERROR
	LOCK_NAMESPACE_NO_EXIST
	LOCK_NETWORK_ERROR
	LOCK_NO_SUPPORT_FORCE_UNLOCK
)
View Source
const (
	Offline = iota
	Online
	Unknown
)
View Source
const DefaultConfig = `` /* 1031-byte string literal not displayed */

Variables

View Source
var (
	ErrInternalError    = errors.New("internal error")
	ErrNotExistDatabase = errors.New("database not exist")
	ErrNotExistTable    = errors.New("table not exist")
	ErrNotExistNode     = errors.New("node not exist")
	ErrNotExistRange    = errors.New("range not exist")
	ErrNotExistPeer     = errors.New("range peer not exist")
	ErrInvalidColumn    = errors.New("invalid column")
	ErrNoRoute          = errors.New("no route")
	ErrExceedMaxLimit   = errors.New("exceeding the maximum limit")
	ErrEmptyRow         = errors.New("empty row")
	ErrHttpCmdUnknown   = errors.New("invalid command")
	ErrHttpCmdParse     = errors.New("parse error")
	ErrHttpCmdRun       = errors.New("run error")
	ErrHttpCmdEmpty     = errors.New("command empty")

	ErrAffectRows     = errors.New("affect rows is not equal")
	ErrCreateDatabase = errors.New(" create database err")
	ErrCreateTable    = errors.New("create table err")
)
View Source
var (
	Lock_exist_error            string = "lock exist"
	Lock_not_exist_error        string = "lock not exist"
	Lock_not_owner_error        string = "not lock owner"
	Lock_force_unlock_error     string = "force unlock ing"
	Lock_store_error            string = "raft store error"
	Lock_epoch_error            string = "range epoch error"
	Lock_namespace_no_exist     string = "namespace not exist"
	Lock_network_error          string = "network exception"
	Lock_no_suport_force_unlock string = "no support force unlock"
)

Functions

func CloseMock added in v0.6.3

func CloseMock(p *Proxy)

func CodeToErr

func CodeToErr(code int) error

func ComposeTS

func ComposeTS(physical, logical int64) uint64

ComposeTS creates a ts from physical and logical parts.

func ExtractPhysical

func ExtractPhysical(ts uint64) int64

ExtractPhysical returns a ts's physical part.

func LimitListener

func LimitListener(l net.Listener, n int) net.Listener

LimitListener returns a Listener that accepts at most n simultaneous connections from the provided Listener.

func PutInsertTask

func PutInsertTask(task *InsertTask)

func PutSelectTask

func PutSelectTask(task *SelectTask)

func UpdateConfig added in v0.6.3

func UpdateConfig(addr string) error

Types

type And

type And struct {
	Field  *Field_ `json:"field"`
	Relate string  `json:"relate"`
	Or     []*Or   `json:"or"`
}

type BenchMarkConfig

type BenchMarkConfig struct {
	Type    int    `toml:"type,omitempty" json:"type"`
	DataLen int    `toml:"data-len,omitempty" json:"data-len"`
	SendNum int    `toml:"send-num,omitempty" json:"send-num"`
	Threads int    `toml:"threads,omitempty" json:"threads"`
	DB      string `toml:"db,omitempty" json:"db"`
	Table   string `toml:"table,omitempty" json:"table"`
	Batch   int    `toml:"batch,omitempty" json:"batch"`
	Scope   int    `toml:"scope,omitempty" json:"scope"`
}

type BlacklistSqls

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

type ClientConn

type ClientConn struct {
	sync.Mutex
	// contains filtered or unexported fields
}

client <-> proxy

func (*ClientConn) AddDatabase

func (c *ClientConn) AddDatabase(nodeName string, role string, addr string) error

func (*ClientConn) Close

func (c *ClientConn) Close() error

func (*ClientConn) DeleteDatabase

func (c *ClientConn) DeleteDatabase(nodeName string, role string, addr string) error

func (*ClientConn) DownDatabase

func (c *ClientConn) DownDatabase(nodeName string, role string, addr string) error

func (*ClientConn) Handshake

func (c *ClientConn) Handshake() error

func (*ClientConn) IsAllowConnect

func (c *ClientConn) IsAllowConnect() bool

func (*ClientConn) Run

func (c *ClientConn) Run()

func (*ClientConn) UpDatabase

func (c *ClientConn) UpDatabase(nodeName string, role string, addr string) error

type ClusterConfig

type ClusterConfig struct {
	ID         uint64   `toml:"id,omitempty" json:"id"`
	ServerAddr []string `toml:"address,omitempty" json:"address"`
	Token      string   `toml:"token,omitempty" json:"token"`
}

type Column

type Column struct {
	Name       string `json:"name"`
	DataType   string `json:"datatype"`
	PrimaryKey bool   `json:"primarykey"`
	Unsigned   bool   `json:"unsigned"`
}

type Command

type Command struct {
	Version string          `json:"version"`
	Type    string          `json:"type"`
	Field   []string        `json:"field"`
	Values  [][]interface{} `json:"values"`
	Filter  *Filter_        `json:"filter"`
	PKs     [][]*And        `json:"pks"`
}

type Config

type Config struct {
	HttpPort    int `toml:"http-port,omitempty" json:"http-port"`
	LockRpcPort int `toml:"lock-port,omitempty" json:"lock-port"`
	SqlPort     int `toml:"mysql-port,omitempty" json:"mysql-port"`

	MaxClients int    `toml:"max-clients,omitempty" json:"max-clients"`
	MaxLimit   uint64 `toml:"max-record-limit,omitempty" json:"max-record-limit"`

	User     string `toml:"user,omitempty" json:"user"`
	Password string `toml:"password,omitempty" json:"password"`
	Charset  string `toml:"charset,omitempty" json:"charset"`

	Performance PerformConfig `toml:"performance,omitempty" json:"performance"`
	Cluster     ClusterConfig `toml:"cluster,omitempty" json:"cluster"`
	Log         LogConfig     `toml:"log,omitempty" json:"log"`
	Metric      MetricConfig  `toml:"metric,omitempty" json:"metric"`

	BenchConfig BenchMarkConfig `toml:"benchmark,omitempty" json:"benchmark"`
}

func (*Config) LoadConfig

func (c *Config) LoadConfig(configFileName *string)

type Counter

type Counter struct {
	OldClientQPS    int64
	OldErrLogTotal  int64
	OldSlowLogTotal int64

	ClientConns  int64
	ClientQPS    int64
	ErrLogTotal  int64
	SlowLogTotal int64
}

func (*Counter) DecrClientConns

func (counter *Counter) DecrClientConns()

func (*Counter) FlushCounter

func (counter *Counter) FlushCounter()

flush the count per second

func (*Counter) IncrClientConns

func (counter *Counter) IncrClientConns()

func (*Counter) IncrClientQPS

func (counter *Counter) IncrClientQPS()

func (*Counter) IncrErrLogTotal

func (counter *Counter) IncrErrLogTotal()

func (*Counter) IncrSlowLogTotal

func (counter *Counter) IncrSlowLogTotal()

type CreateDatabase

type CreateDatabase struct {
	Sign         string `json:"sign"`
	DatabaseName string `json:"databasename"`
}

type CreateTable

type CreateTable struct {
	Sign         string    `json:"sign"`
	DatabaseName string    `json:"databasename"`
	TableName    string    `json:"tablename"`
	Columns      []*Column `json:"columns"`
}

type DataBase

type DataBase struct {
	*metapb.DataBase
	// contains filtered or unexported fields
}

func NewDataBase

func NewDataBase(db *metapb.DataBase, cli client.Client) *DataBase

func (*DataBase) AddTable

func (d *DataBase) AddTable(t *Table)

func (*DataBase) DbId

func (d *DataBase) DbId() uint64

func (*DataBase) DbName

func (d *DataBase) DbName() string

func (*DataBase) FindTable

func (d *DataBase) FindTable(tableName string) *Table

type ExecuteDB

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

type Field

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

type Field_

type Field_ struct {
	Column string      `json:"column"`
	Value  interface{} `json:"value"`
}

type Filter

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

type Filter_

type Filter_ struct {
	And   []*And   `json:"and"`
	Scope *Scope   `json:"scope"`
	Limit *Limit_  `json:"limit"`
	Order []*Order `json:"order"`
}

type InsertResult

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

func (*InsertResult) GetAffected

func (r *InsertResult) GetAffected() uint64

func (*InsertResult) GetDuplicateKey

func (r *InsertResult) GetDuplicateKey() []byte

type InsertRowValue

type InsertRowValue []SQLValue

type InsertTask

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

func GetInsertTask

func GetInsertTask() *InsertTask

func (*InsertTask) Do

func (it *InsertTask) Do()

func (*InsertTask) Reset

func (it *InsertTask) Reset()

func (*InsertTask) Wait

func (it *InsertTask) Wait() error

type KvParisSlice

type KvParisSlice []*kvrpcpb.KeyValue

func (KvParisSlice) Len

func (p KvParisSlice) Len() int

func (KvParisSlice) Less

func (p KvParisSlice) Less(i int, j int) bool

func (KvParisSlice) Swap

func (p KvParisSlice) Swap(i int, j int)

type Limit

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

type Limit_

type Limit_ struct {
	Offset   uint64 `json:"offset"`
	RowCount uint64 `json:"rowcount"`
}

type LogConfig

type LogConfig struct {
	Dir    string `toml:"dir,omitempty" json:"dir"`
	Module string `toml:"module,omitempty" json:"module"`
	Level  string `toml:"level,omitempty" json:"level"`
}

type Match

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

type MatchType

type MatchType int
var (
	Invalid       MatchType = 0
	Equal         MatchType = 1
	NotEqual      MatchType = 2
	Less          MatchType = 3
	LessOrEqual   MatchType = 4
	Larger        MatchType = 5
	LargerOrEqual MatchType = 6
)

type MetricConfig

type MetricConfig struct {
	Interval util.Duration `toml:"interval,omitempty" json:"interval"`
	Address  string        `toml:"address,omitempty" json:"address"`
}

type Or

type Or struct {
	Field  *Field_   `json:"field"`
	Relate MatchType `json:"relate"`
	And    []*And    `json:"and"`
}

type Order

type Order struct {
	By   string `json:"by"`
	Desc bool   `json:"desc"`
}

type PerformConfig

type PerformConfig struct {
	MaxWorkNum      uint64 `toml:"max-work-num,omitempty" json:"max-work-num"`
	MaxTaskQueueLen uint64 `toml:"max-task-queue-len,omitempty" json:"max-task-queue-len"`
	GrpcPoolSize    int    `toml:"grpc-pool-size,omitempty" json:"grpc-pool-size"`
	GrpcInitWinSize int    `toml:"grpc-win-size,omitempty" json:"grpc-win-size"`

	InsertSlowLog util.Duration `toml:"slow-insert,omitempty" json:"slow-insert"`
	SelectSlowLog util.Duration `toml:"slow-select,omitempty" json:"slow-select"`
	DeleteSlowLog util.Duration `toml:"slow-delete,omitempty" json:"slow-delete"`
	SlowLogMaxLen uint64        `toml:"slow-log-max-len,omitempty" json:"slow-log-max-len"`
}

type Proxy

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

func NewProxy

func NewProxy(msAddrs []string, config *Config) *Proxy

func (*Proxy) Close

func (p *Proxy) Close()

func (*Proxy) EncodeRow

func (p *Proxy) EncodeRow(t *Table, colMap map[string]int, rowValue InsertRowValue) (*kvrpcpb.KeyValue, error)

EncodeRow 编码一行

func (*Proxy) HandleAdmin

func (p *Proxy) HandleAdmin(db string, cmd string, args []string) (*mysql.Result, error)

func (*Proxy) HandleDelete

func (p *Proxy) HandleDelete(db string, stmt *sqlparser.Delete, args []interface{}) (*mysql.Result, error)

HandleDelete handle delete

func (*Proxy) HandleDescribe

func (p *Proxy) HandleDescribe(db string, stmt *sqlparser.Describe) (*mysql.Result, error)

HandleDescribe decribe table

func (*Proxy) HandleInsert

func (p *Proxy) HandleInsert(db string, stmt *sqlparser.Insert, args []interface{}) (*mysql.Result, error)

func (*Proxy) HandleSelect

func (p *Proxy) HandleSelect(db string, stmt *sqlparser.Select, args []interface{}) (*mysql.Result, error)

func (*Proxy) HandleTruncate

func (p *Proxy) HandleTruncate(db string, stmt *sqlparser.Truncate) (*mysql.Result, error)

HandleTruncate truncate table

func (*Proxy) Lock

func (p *Proxy) Lock(dbName, tableName string, lockName string, userCondition []byte, uuid string, deleteTime int64, userName string) (*kvrpcpb.LockResponse, error)

func (*Proxy) LockScan added in v0.6.3

func (p *Proxy) LockScan(dbName, tableName string, startKey, endKey string, number uint32) (*kvrpcpb.LockScanResponse, error)

func (*Proxy) LockUpdate

func (p *Proxy) LockUpdate(dbName, tableName string, lockName string, uuid string, condition []byte) (*kvrpcpb.LockResponse, error)

func (*Proxy) RawDelete

func (p *Proxy) RawDelete(dbName, tableName string, key []byte) error

delete in range split, we need delete key in src range and dst range

func (*Proxy) RawGet

func (p *Proxy) RawGet(dbName, tableName string, key []byte) ([]byte, error)

get in range split, first get from dst range, if no value, we need get from src range again

func (*Proxy) RawPut

func (p *Proxy) RawPut(dbName, tableName string, key, value []byte) error

TODO timestamp to ensure the order of put

func (*Proxy) Submit

func (p *Proxy) Submit(t Task) error

func (*Proxy) Unlock

func (p *Proxy) Unlock(dbName, tableName string, lockName, uuid, userName string) (*kvrpcpb.LockResponse, error)

func (*Proxy) UnlockForce

func (p *Proxy) UnlockForce(dbName, tableName string, lockName, userName string) (*kvrpcpb.LockResponse, error)

func (*Proxy) UpdateCondition

func (p *Proxy) UpdateCondition(dbName, tableName string, lockName string, userCondition []byte) (*kvrpcpb.LockResponse, error)

type Query

type Query struct {
	Sign         string   `json:"sign"`
	DatabaseName string   `json:"databasename"`
	TableName    string   `json:"tablename"`
	Command      *Command `json:"command"`
}

type Reply

type Reply struct {
	Code         int             `json:"code"`
	RowsAffected uint64          `json:"rowsaffected"`
	Values       [][]interface{} `json:"values"`
	Message      string          `json:"message"`
}

type Response

type Response struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
}

type ResultRow

type ResultRow struct {
	Value   []interface{}
	RowData mysql.RowData
}

type Router

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

func NewRouter

func NewRouter(cli client.Client) *Router

func (*Router) FindColumn

func (rr *Router) FindColumn(db, table, clo string) *metapb.Column

func (*Router) FindDB

func (rr *Router) FindDB(dbname string) *DataBase

func (*Router) FindTable

func (rr *Router) FindTable(dbName, tableName string) *Table

func (*Router) GetAllColumns

func (rr *Router) GetAllColumns(db, table string) []*metapb.Column

type Row

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

type SQLValue

type SQLValue []byte

type Scope

type Scope struct {
	Start []byte `json:"start"`
	End   []byte `json:"end"`
}

type SelColumn

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

SelColumn select fields

type SelectResult

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

type SelectTask

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

func GetSelectTask

func GetSelectTask() *SelectTask

func (*SelectTask) Do

func (it *SelectTask) Do()

func (*SelectTask) Reset

func (it *SelectTask) Reset()

func (*SelectTask) Wait

func (it *SelectTask) Wait() error

type Server

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

func NewServer

func NewServer(cfg *Config) (*Server, error)

func (*Server) ChangeProxy

func (s *Server) ChangeProxy(v string) error

func (*Server) Close

func (s *Server) Close()

func (*Server) DoHeartbeat

func (service *Server) DoHeartbeat(ctx context.Context, req *lockrpcpb.LockHeartbeatRequest) (*lockrpcpb.DLockResponse, error)

func (*Server) ForceUnLock

func (service *Server) ForceUnLock(ctx context.Context, req *lockrpcpb.ForceUnLockRequest) (*lockrpcpb.DLockResponse, error)

func (*Server) GetCfg

func (s *Server) GetCfg() *Config

func (*Server) Lock

func (service *Server) Lock(ctx context.Context, req *lockrpcpb.LockRequest) (*lockrpcpb.DLockResponse, error)

func (*Server) Run

func (s *Server) Run() error

func (*Server) Status

func (s *Server) Status() string

func (*Server) UnLock

func (service *Server) UnLock(ctx context.Context, req *lockrpcpb.UnLockRequest) (*lockrpcpb.DLockResponse, error)

func (*Server) UpdateCondition

func (service *Server) UpdateCondition(ctx context.Context, req *lockrpcpb.UpdateConditionRequest) (*lockrpcpb.DLockResponse, error)

type Session

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

func NewSession

func NewSession(id uint64, conn net.Conn) *Session

func (*Session) Close

func (s *Session) Close()

func (*Session) ID

func (s *Session) ID() uint64

func (*Session) IsClosed

func (s *Session) IsClosed() bool

func (*Session) Process

func (s *Session) Process()

type SharkStoreApi

type SharkStoreApi struct {
}

func (*SharkStoreApi) Delete

func (api *SharkStoreApi) Delete(s *Server, dbName string, tableName string, fields []string, pks map[string]interface{}) *Reply

func (*SharkStoreApi) Insert

func (api *SharkStoreApi) Insert(s *Server, dbName string, tableName string, fields []string, values [][]interface{}) *Reply

func (*SharkStoreApi) MultSelect added in v0.7.2

func (api *SharkStoreApi) MultSelect(s *Server, dbName string, tableName string, fields []string, pkMults []map[string]interface{}, limit_ *Limit_) *Reply

func (*SharkStoreApi) Select

func (api *SharkStoreApi) Select(s *Server, dbName string, tableName string, fields []string, pks map[string]interface{}, limit_ *Limit_) *Reply

type SortRoutes

type SortRoutes []*metapb.Route

func (SortRoutes) Len

func (s SortRoutes) Len() int

func (SortRoutes) Less

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

func (SortRoutes) Swap

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

type Stmt

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

func (*Stmt) ResetParams

func (s *Stmt) ResetParams()

type StmtParser

type StmtParser struct {
}

type Table

type Table struct {
	*metapb.Table
	// contains filtered or unexported fields
}

func NewTable

func NewTable(table *metapb.Table, cli client.Client, ttl time.Duration) *Table

func (*Table) AddColumn

func (t *Table) AddColumn(c *metapb.Column)

func (*Table) AllIndexs

func (t *Table) AllIndexs() []uint64

func (*Table) AllRoutes

func (t *Table) AllRoutes() []*dskv.KeyLocation

TODO 需要返回有序的route列表

func (*Table) DbName

func (t *Table) DbName() string

func (*Table) DeleteColumn

func (t *Table) DeleteColumn(columnName string)

func (*Table) FindColumn

func (t *Table) FindColumn(columnName string) *metapb.Column

func (*Table) FindColumnById

func (t *Table) FindColumnById(columnId uint64) *metapb.Column

func (*Table) GetAllColumns

func (t *Table) GetAllColumns() []*metapb.Column

func (*Table) ID

func (t *Table) ID() uint64

func (*Table) Name

func (t *Table) Name() string

func (*Table) PKS

func (t *Table) PKS() []string

func (*Table) PkDupCheck

func (t *Table) PkDupCheck() bool

type Task

type Task interface {
	Do()
	Wait() error
	Reset()
}

Jump to

Keyboard shortcuts

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