server

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2019 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RespOK means OK message
	RespOK = iota
	// RespResult means Result message
	RespResult
	// RespError means error message
	RespError
	// RespFieldList means field list message
	RespFieldList
	// RespPrepare prepare response message
	RespPrepare
	// RespEOF means EOF message
	RespEOF
	// RespNoop means empty message
	RespNoop
)

Variables

DefaultCapability means default capability

Functions

func NewProxyInfo

func NewProxyInfo(cfg *models.Proxy, addr string) (*models.ProxyInfo, error)

NewProxyInfo create proxy information

Types

type AdminServer

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

AdminServer means admin server

func NewAdminServer

func NewAdminServer(proxy *Server, cfg *models.Proxy) (*AdminServer, error)

NewAdminServer create new admin server

func (*AdminServer) Close

func (s *AdminServer) Close() error

Close close admin server

func (*AdminServer) Run

func (s *AdminServer) Run()

Run run admin server

type ClientConn

type ClientConn struct {
	*mysql.Conn
	// contains filtered or unexported fields
}

ClientConn session client connection

func NewClientConn

func NewClientConn(c *mysql.Conn, manager *Manager) *ClientConn

NewClientConn constructor of ClientConn

type HandshakeResponseInfo

type HandshakeResponseInfo struct {
	CollationID  mysql.CollationID
	User         string
	AuthResponse []byte
	Salt         []byte
	Database     string
}

HandshakeResponseInfo handshake response information

type Manager

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

Manager contains namespace manager and user manager

func CreateManager

func CreateManager(cfg *models.Proxy, namespaceConfigs map[string]*models.Namespace) (*Manager, error)

CreateManager create manager

func LoadAndCreateManager

func LoadAndCreateManager(cfg *models.Proxy) (*Manager, error)

LoadAndCreateManager load namespace config, and create manager

func NewManager

func NewManager() *Manager

NewManager return empty Manager

func (*Manager) CheckPassword

func (m *Manager) CheckPassword(user string, salt, auth []byte) (bool, string)

CheckPassword check if right password with specific user

func (*Manager) CheckUser

func (m *Manager) CheckUser(user string) bool

CheckUser check if user in users

func (*Manager) Close

func (m *Manager) Close()

Close close manager

func (*Manager) ConfigFingerprint

func (m *Manager) ConfigFingerprint() string

ConfigFingerprint return config fingerprint

func (*Manager) DeleteNamespace

func (m *Manager) DeleteNamespace(name string) error

DeleteNamespace delete namespace

func (*Manager) GetNamespace

func (m *Manager) GetNamespace(name string) *Namespace

GetNamespace return specific namespace

func (*Manager) GetNamespaceByUser

func (m *Manager) GetNamespaceByUser(userName, password string) string

GetNamespaceByUser return namespace by user

func (*Manager) GetStatisticManager

func (m *Manager) GetStatisticManager() *StatisticManager

GetStatisticManager return proxy status to record status

func (*Manager) RecordBackendSQLMetrics

func (m *Manager) RecordBackendSQLMetrics(reqCtx *util.RequestContext, namespace string, sql, backendAddr string, startTime time.Time, err error)

RecordBackendSQLMetrics record backend SQL metrics, like response time, error

func (*Manager) RecordSessionSQLMetrics

func (m *Manager) RecordSessionSQLMetrics(reqCtx *util.RequestContext, namespace string, sql string, startTime time.Time, err error)

RecordSessionSQLMetrics record session SQL metrics, like response time, error

func (*Manager) ReloadNamespaceCommit

func (m *Manager) ReloadNamespaceCommit(name string) error

ReloadNamespaceCommit commit config

func (*Manager) ReloadNamespacePrepare

func (m *Manager) ReloadNamespacePrepare(namespaceConfig *models.Namespace) error

ReloadNamespacePrepare prepare commit

type Namespace

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

Namespace is struct driected used by server

func NewNamespace

func NewNamespace(namespaceConfig *models.Namespace) (*Namespace, error)

NewNamespace init namespace

func (*Namespace) Close

func (n *Namespace) Close(delay bool)

Close recycle resources of namespace

func (*Namespace) DumpToJSON

func (n *Namespace) DumpToJSON() []byte

DumpToJSON means easy encode json

func (*Namespace) GetAllowedDBs

func (n *Namespace) GetAllowedDBs() []string

GetAllowedDBs return all allowed databases

func (*Namespace) GetBackendErrorSQLFingerprint

func (n *Namespace) GetBackendErrorSQLFingerprint(md5 string) (string, bool)

GetBackendErrorSQLFingerprint return backedn error sql fingerprint

func (*Namespace) GetBackendErrorSQLFingerprints

func (n *Namespace) GetBackendErrorSQLFingerprints() map[string]string

GetBackendErrorSQLFingerprints return all backend error sql fingerprints

func (*Namespace) GetBackendSlowSQLFingerprint

func (n *Namespace) GetBackendSlowSQLFingerprint(md5 string) (string, bool)

GetBackendSlowSQLFingerprint return backend slow sql fingerprint

func (*Namespace) GetBackendSlowSQLFingerprints

func (n *Namespace) GetBackendSlowSQLFingerprints() map[string]string

GetBackendSlowSQLFingerprints return all backend slow sql fingerprints

func (*Namespace) GetCachedPlan

func (n *Namespace) GetCachedPlan(db, sql string) (plan.Plan, bool)

GetCachedPlan get plan in cache

func (*Namespace) GetDefaultCharset

func (n *Namespace) GetDefaultCharset() string

GetDefaultCharset return default charset

func (*Namespace) GetDefaultCollationID

func (n *Namespace) GetDefaultCollationID() mysql.CollationID

GetDefaultCollationID return default collation id

func (*Namespace) GetDefaultPhyDB

func (n *Namespace) GetDefaultPhyDB(dbname string) (string, error)

GetDefaultPhyDB return default real database

func (*Namespace) GetErrorSQLFingerprint

func (n *Namespace) GetErrorSQLFingerprint(md5 string) (string, bool)

GetErrorSQLFingerprint return error sql fingerprint

func (*Namespace) GetErrorSQLFingerprints

func (n *Namespace) GetErrorSQLFingerprints() map[string]string

GetErrorSQLFingerprints return all error sql fingerprints

func (*Namespace) GetName

func (n *Namespace) GetName() string

GetName return namespace of namespace

func (*Namespace) GetRouter

func (n *Namespace) GetRouter() *router.Router

GetRouter return router of namespace

func (*Namespace) GetSequences

func (n *Namespace) GetSequences() *sequence.SequenceManager

func (*Namespace) GetSlice

func (n *Namespace) GetSlice(name string) *backend.Slice

GetSlice return slice of namespace

func (*Namespace) GetSlowSQLFingerprint

func (n *Namespace) GetSlowSQLFingerprint(md5 string) (string, bool)

GetSlowSQLFingerprint return slow sql fingerprint

func (*Namespace) GetSlowSQLFingerprints

func (n *Namespace) GetSlowSQLFingerprints() map[string]string

GetSlowSQLFingerprints return slow sql fingerprints

func (*Namespace) GetUserProperty

func (n *Namespace) GetUserProperty(user string) int

GetUserProperty return user information

func (*Namespace) IsAllowWrite

func (n *Namespace) IsAllowWrite(user string) bool

IsAllowWrite check if user allow to write

func (*Namespace) IsAllowedDB

func (n *Namespace) IsAllowedDB(dbname string) bool

IsAllowedDB if allowed database

func (*Namespace) IsClientIPAllowed

func (n *Namespace) IsClientIPAllowed(clientIP net.IP) bool

IsClientIPAllowed check ip

func (*Namespace) IsRWSplit

func (n *Namespace) IsRWSplit(user string) bool

IsRWSplit chekc if read write split

func (*Namespace) IsSQLAllowed

func (n *Namespace) IsSQLAllowed(reqCtx *util.RequestContext, sql string) bool

IsSQLAllowed check black sql

func (*Namespace) IsStatisticUser

func (n *Namespace) IsStatisticUser(user string) bool

IsStatisticUser check if user is used to statistic

func (*Namespace) SetBackendErrorSQLFingerprint

func (n *Namespace) SetBackendErrorSQLFingerprint(md5, fingerprint string)

SetBackendErrorSQLFingerprint store backend error sql fingerprint

func (*Namespace) SetBackendSlowSQLFingerprint

func (n *Namespace) SetBackendSlowSQLFingerprint(md5, fingerprint string)

SetBackendSlowSQLFingerprint store backend slow sql fingerprint

func (*Namespace) SetCachedPlan

func (n *Namespace) SetCachedPlan(db, sql string, p plan.Plan)

SetCachedPlan set plan in cache

func (*Namespace) SetErrorSQLFingerprint

func (n *Namespace) SetErrorSQLFingerprint(md5, fingerprint string)

SetErrorSQLFingerprint store error sql fingerprint

func (*Namespace) SetSlowSQLFingerprint

func (n *Namespace) SetSlowSQLFingerprint(md5, fingerprint string)

SetSlowSQLFingerprint store slow sql fingerprint

type NamespaceManager

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

NamespaceManager is the manager that holds all namespaces

func CreateNamespaceManager

func CreateNamespaceManager(namespaceConfigs map[string]*models.Namespace) *NamespaceManager

CreateNamespaceManager create NamespaceManager

func NewNamespaceManager

func NewNamespaceManager() *NamespaceManager

NewNamespaceManager constructor of NamespaceManager

func ShallowCopyNamespaceManager

func ShallowCopyNamespaceManager(nsMgr *NamespaceManager) *NamespaceManager

ShallowCopyNamespaceManager copy NamespaceManager

func (*NamespaceManager) ConfigFingerprint

func (n *NamespaceManager) ConfigFingerprint() string

ConfigFingerprint return config fingerprint

func (*NamespaceManager) DeleteNamespace

func (n *NamespaceManager) DeleteNamespace(ns string)

DeleteNamespace delete namespace

func (*NamespaceManager) GetNamespace

func (n *NamespaceManager) GetNamespace(namespace string) *Namespace

GetNamespace get namespace in NamespaceManager

func (*NamespaceManager) GetNamespaces

func (n *NamespaceManager) GetNamespaces() map[string]*Namespace

GetNamespaces return all namespaces in NamespaceManager

func (*NamespaceManager) RebuildNamespace

func (n *NamespaceManager) RebuildNamespace(config *models.Namespace) error

RebuildNamespace rebuild namespace

type Response

type Response struct {
	RespType int
	Status   uint16
	Data     interface{}
}

Response response info

func CreateEOFResponse

func CreateEOFResponse(status uint16) Response

CreateEOFResponse create eof response

func CreateErrorResponse

func CreateErrorResponse(status uint16, err error) Response

CreateErrorResponse create error response

func CreateFieldListResponse

func CreateFieldListResponse(status uint16, fl []*mysql.Field) Response

CreateFieldListResponse create field list response

func CreateNoopResponse

func CreateNoopResponse() Response

CreateNoopResponse no op response, for ComStmtClose

func CreateOKResponse

func CreateOKResponse(status uint16) Response

CreateOKResponse create ok response

func CreatePrepareResponse

func CreatePrepareResponse(status uint16, stmt *Stmt) Response

CreatePrepareResponse create prepare response

func CreateResultResponse

func CreateResultResponse(status uint16, result *mysql.Result) Response

CreateResultResponse create result response

type SQLFingerprint

type SQLFingerprint struct {
	SlowSQL  map[string]string `json:"slow_sql"`
	ErrorSQL map[string]string `json:"error_sql"`
}

SQLFingerprint sql fingerprint

type Server

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

Server means proxy that serve client request

func NewServer

func NewServer(cfg *models.Proxy, manager *Manager) (*Server, error)

NewServer create new server

func (*Server) Close

func (s *Server) Close() error

Close close proxy server

func (*Server) DeleteNamespace

func (s *Server) DeleteNamespace(name string) error

DeleteNamespace delete namespace in namespace manager

func (*Server) Listener

func (s *Server) Listener() net.Listener

Listener return proxy's listener

func (*Server) ReloadNamespaceCommit

func (s *Server) ReloadNamespaceCommit(name string) error

ReloadNamespaceCommit config change commit phase commit namespace does not need lock

func (*Server) ReloadNamespacePrepare

func (s *Server) ReloadNamespacePrepare(name string, client models.Client) error

ReloadNamespacePrepare config change prepare phase

func (*Server) Run

func (s *Server) Run() error

Run proxy run and serve client request

type Session

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

Session means session between client and proxy

func (*Session) Close

func (cc *Session) Close()

Close close session with it's resources

func (*Session) Handshake

func (cc *Session) Handshake() error

Handshake with client step1: server send plain handshake packets to client step2: client send handshake response packets to server step3: server send ok/err packets to client

func (*Session) IsAllowConnect

func (cc *Session) IsAllowConnect() bool

IsAllowConnect check if allow to connect

func (*Session) IsClosed

func (cc *Session) IsClosed() bool

IsClosed check if closed

func (*Session) Run

func (cc *Session) Run()

Run start session to server client request packets

type SessionExecutor

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

SessionExecutor is bound to a session, so requests are serializable

func (*SessionExecutor) ExecuteCommand

func (se *SessionExecutor) ExecuteCommand(cmd byte, data []byte) Response

ExecuteCommand execute command

func (*SessionExecutor) ExecuteSQL

func (se *SessionExecutor) ExecuteSQL(reqCtx *util.RequestContext, slice, db, sql string) (*mysql.Result, error)

ExecuteSQL execute sql

func (*SessionExecutor) ExecuteSQLs

func (se *SessionExecutor) ExecuteSQLs(reqCtx *util.RequestContext, sqls map[string]map[string][]string) ([]*mysql.Result, error)

ExecuteSQLs len(sqls) must not be 0, or return error

func (*SessionExecutor) GetCharset

func (se *SessionExecutor) GetCharset() string

GetCharset return charset

func (*SessionExecutor) GetCollationID

func (se *SessionExecutor) GetCollationID() mysql.CollationID

GetCollationID return collation id

func (*SessionExecutor) GetDatabase

func (se *SessionExecutor) GetDatabase() string

GetDatabase return database in session

func (*SessionExecutor) GetLastInsertID

func (se *SessionExecutor) GetLastInsertID() uint64

GetLastInsertID return last_inert_id

func (*SessionExecutor) GetNamespace

func (se *SessionExecutor) GetNamespace() *Namespace

GetNamespace return namespace in session

func (*SessionExecutor) GetStatus

func (se *SessionExecutor) GetStatus() uint16

GetStatus return session status

func (*SessionExecutor) GetVariables

func (se *SessionExecutor) GetVariables() *mysql.SessionVariables

GetVariables return variables in session

func (*SessionExecutor) Parse

func (se *SessionExecutor) Parse(sql string) (ast.StmtNode, error)

Parse parse sql

func (*SessionExecutor) SetCharset

func (se *SessionExecutor) SetCharset(charset string)

SetCharset set session charset

func (*SessionExecutor) SetCollationID

func (se *SessionExecutor) SetCollationID(id mysql.CollationID)

SetCollationID store collation id

func (*SessionExecutor) SetDatabase

func (se *SessionExecutor) SetDatabase(db string)

SetDatabase set session database

func (*SessionExecutor) SetLastInsertID

func (se *SessionExecutor) SetLastInsertID(id uint64)

SetLastInsertID store last_insert_id

func (SessionExecutor) SetNamespaceDefaultCharset

func (se SessionExecutor) SetNamespaceDefaultCharset()

SetNamespaceDefaultCharset set session default charset

func (*SessionExecutor) SetNamespaceDefaultCollationID

func (se *SessionExecutor) SetNamespaceDefaultCollationID()

SetNamespaceDefaultCollationID store default collation id

func (*SessionExecutor) SetStatus

func (se *SessionExecutor) SetStatus(status uint16)

SetStatus store status

type StatisticManager

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

StatisticManager statistics manager

func CreateStatisticManager

func CreateStatisticManager(cfg *models.Proxy, manager *Manager) (*StatisticManager, error)

CreateStatisticManager create StatisticManager

func NewStatisticManager

func NewStatisticManager() *StatisticManager

NewStatisticManager return empty StatisticManager

func (*StatisticManager) AddReadFlowCount

func (s *StatisticManager) AddReadFlowCount(namespace string, byteCount int)

AddReadFlowCount add read flow count

func (*StatisticManager) AddWriteFlowCount

func (s *StatisticManager) AddWriteFlowCount(namespace string, byteCount int)

AddWriteFlowCount add write flow count

func (*StatisticManager) Close

func (s *StatisticManager) Close()

Close close proxy stats

func (*StatisticManager) DescSessionCount

func (s *StatisticManager) DescSessionCount(namespace string)

DescSessionCount decr session count

func (*StatisticManager) GetHandlers

func (s *StatisticManager) GetHandlers() map[string]http.Handler

GetHandlers return specific handler of stats

func (*StatisticManager) IncrSessionCount

func (s *StatisticManager) IncrSessionCount(namespace string)

IncrSessionCount incr session count

func (*StatisticManager) Init

func (s *StatisticManager) Init(cfg *models.Proxy) error

Init init StatisticManager

func (*StatisticManager) RecordSQLForbidden

func (s *StatisticManager) RecordSQLForbidden(fingerprint, namespace string)

RecordSQLForbidden record forbidden sql

type Stmt

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

Stmt prepare statement struct

func (*Stmt) GetParamTypes added in v1.1.0

func (s *Stmt) GetParamTypes() []byte

func (*Stmt) GetRewriteSQL

func (s *Stmt) GetRewriteSQL() (string, error)

GetRewriteSQL get rewrite sql

func (*Stmt) ResetParams

func (s *Stmt) ResetParams()

ResetParams reset args

func (*Stmt) SetParamTypes added in v1.1.0

func (s *Stmt) SetParamTypes(paramTypes []byte)

type UserManager

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

UserManager means user for auth username+password是全局唯一的, 而username可以对应多个namespace

func CloneUserManager

func CloneUserManager(user *UserManager) *UserManager

CloneUserManager close UserManager

func CreateUserManager

func CreateUserManager(namespaceConfigs map[string]*models.Namespace) (*UserManager, error)

CreateUserManager create UserManager

func NewUserManager

func NewUserManager() *UserManager

NewUserManager constructor of UserManager

func (*UserManager) CheckPassword

func (u *UserManager) CheckPassword(user string, salt, auth []byte) (bool, string)

CheckPassword check if right password with specific user

func (*UserManager) CheckUser

func (u *UserManager) CheckUser(user string) bool

CheckUser check if user in users

func (*UserManager) ClearNamespaceUsers

func (u *UserManager) ClearNamespaceUsers(namespace string)

ClearNamespaceUsers clear users in namespace

func (*UserManager) GetNamespaceByUser

func (u *UserManager) GetNamespaceByUser(userName, password string) string

GetNamespaceByUser return namespace by user

func (*UserManager) RebuildNamespaceUsers

func (u *UserManager) RebuildNamespaceUsers(namespace *models.Namespace)

RebuildNamespaceUsers rebuild users in namespace

type UserProperty

type UserProperty struct {
	RWFlag        int
	RWSplit       int
	OtherProperty int
}

UserProperty means runtime user properties

Jump to

Keyboard shortcuts

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