Documentation ¶
Index ¶
- Constants
- Variables
- func NewProxyInfo(cfg *models.Proxy, addr string) (*models.ProxyInfo, error)
- type AdminServer
- type ClientConn
- type HandshakeResponseInfo
- type Manager
- func (m *Manager) CheckPassword(user string, salt, auth []byte) (bool, string)
- func (m *Manager) CheckUser(user string) bool
- func (m *Manager) Close()
- func (m *Manager) ConfigFingerprint() string
- func (m *Manager) DeleteNamespace(name string) error
- func (m *Manager) GetNamespace(name string) *Namespace
- func (m *Manager) GetNamespaceByUser(userName, password string) string
- func (m *Manager) GetStatisticManager() *StatisticManager
- func (m *Manager) RecordBackendSQLMetrics(reqCtx *util.RequestContext, namespace string, sql, backendAddr string, ...)
- func (m *Manager) RecordSessionSQLMetrics(reqCtx *util.RequestContext, namespace string, sql string, startTime time.Time, ...)
- func (m *Manager) ReloadNamespaceCommit(name string) error
- func (m *Manager) ReloadNamespacePrepare(namespaceConfig *models.Namespace) error
- type Namespace
- func (n *Namespace) Close(delay bool)
- func (n *Namespace) DumpToJSON() []byte
- func (n *Namespace) GetAllowedDBs() []string
- func (n *Namespace) GetBackendErrorSQLFingerprint(md5 string) (string, bool)
- func (n *Namespace) GetBackendErrorSQLFingerprints() map[string]string
- func (n *Namespace) GetBackendSlowSQLFingerprint(md5 string) (string, bool)
- func (n *Namespace) GetBackendSlowSQLFingerprints() map[string]string
- func (n *Namespace) GetCachedPlan(db, sql string) (plan.Plan, bool)
- func (n *Namespace) GetDefaultCharset() string
- func (n *Namespace) GetDefaultCollationID() mysql.CollationID
- func (n *Namespace) GetDefaultPhyDB(dbname string) (string, error)
- func (n *Namespace) GetErrorSQLFingerprint(md5 string) (string, bool)
- func (n *Namespace) GetErrorSQLFingerprints() map[string]string
- func (n *Namespace) GetName() string
- func (n *Namespace) GetRouter() *router.Router
- func (n *Namespace) GetSequences() *sequence.SequenceManager
- func (n *Namespace) GetSlice(name string) *backend.Slice
- func (n *Namespace) GetSlowSQLFingerprint(md5 string) (string, bool)
- func (n *Namespace) GetSlowSQLFingerprints() map[string]string
- func (n *Namespace) GetUserProperty(user string) int
- func (n *Namespace) IsAllowWrite(user string) bool
- func (n *Namespace) IsAllowedDB(dbname string) bool
- func (n *Namespace) IsClientIPAllowed(clientIP net.IP) bool
- func (n *Namespace) IsRWSplit(user string) bool
- func (n *Namespace) IsSQLAllowed(reqCtx *util.RequestContext, sql string) bool
- func (n *Namespace) IsStatisticUser(user string) bool
- func (n *Namespace) SetBackendErrorSQLFingerprint(md5, fingerprint string)
- func (n *Namespace) SetBackendSlowSQLFingerprint(md5, fingerprint string)
- func (n *Namespace) SetCachedPlan(db, sql string, p plan.Plan)
- func (n *Namespace) SetErrorSQLFingerprint(md5, fingerprint string)
- func (n *Namespace) SetSlowSQLFingerprint(md5, fingerprint string)
- type NamespaceManager
- func (n *NamespaceManager) ConfigFingerprint() string
- func (n *NamespaceManager) DeleteNamespace(ns string)
- func (n *NamespaceManager) GetNamespace(namespace string) *Namespace
- func (n *NamespaceManager) GetNamespaces() map[string]*Namespace
- func (n *NamespaceManager) RebuildNamespace(config *models.Namespace) error
- type Response
- func CreateEOFResponse(status uint16) Response
- func CreateErrorResponse(status uint16, err error) Response
- func CreateFieldListResponse(status uint16, fl []*mysql.Field) Response
- func CreateNoopResponse() Response
- func CreateOKResponse(status uint16) Response
- func CreatePrepareResponse(status uint16, stmt *Stmt) Response
- func CreateResultResponse(status uint16, result *mysql.Result) Response
- type SQLFingerprint
- type Server
- type Session
- type SessionExecutor
- func (se *SessionExecutor) ExecuteCommand(cmd byte, data []byte) Response
- func (se *SessionExecutor) ExecuteSQL(reqCtx *util.RequestContext, slice, db, sql string) (*mysql.Result, error)
- func (se *SessionExecutor) ExecuteSQLs(reqCtx *util.RequestContext, sqls map[string]map[string][]string) ([]*mysql.Result, error)
- func (se *SessionExecutor) GetCharset() string
- func (se *SessionExecutor) GetCollationID() mysql.CollationID
- func (se *SessionExecutor) GetDatabase() string
- func (se *SessionExecutor) GetLastInsertID() uint64
- func (se *SessionExecutor) GetNamespace() *Namespace
- func (se *SessionExecutor) GetStatus() uint16
- func (se *SessionExecutor) GetVariables() *mysql.SessionVariables
- func (se *SessionExecutor) Parse(sql string) (ast.StmtNode, error)
- func (se *SessionExecutor) SetCharset(charset string)
- func (se *SessionExecutor) SetCollationID(id mysql.CollationID)
- func (se *SessionExecutor) SetDatabase(db string)
- func (se *SessionExecutor) SetLastInsertID(id uint64)
- func (se SessionExecutor) SetNamespaceDefaultCharset()
- func (se *SessionExecutor) SetNamespaceDefaultCollationID()
- func (se *SessionExecutor) SetStatus(status uint16)
- type StatisticManager
- func (s *StatisticManager) AddReadFlowCount(namespace string, byteCount int)
- func (s *StatisticManager) AddWriteFlowCount(namespace string, byteCount int)
- func (s *StatisticManager) Close()
- func (s *StatisticManager) DescSessionCount(namespace string)
- func (s *StatisticManager) GetHandlers() map[string]http.Handler
- func (s *StatisticManager) IncrSessionCount(namespace string)
- func (s *StatisticManager) Init(cfg *models.Proxy) error
- func (s *StatisticManager) RecordSQLForbidden(fingerprint, namespace string)
- type Stmt
- type UserManager
- func (u *UserManager) CheckPassword(user string, salt, auth []byte) (bool, string)
- func (u *UserManager) CheckUser(user string) bool
- func (u *UserManager) ClearNamespaceUsers(namespace string)
- func (u *UserManager) GetNamespaceByUser(userName, password string) string
- func (u *UserManager) RebuildNamespaceUsers(namespace *models.Namespace)
- type UserProperty
Constants ¶
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 ¶
var DefaultCapability = mysql.ClientLongPassword | mysql.ClientLongFlag | mysql.ClientConnectWithDB | mysql.ClientProtocol41 | mysql.ClientTransactions | mysql.ClientSecureConnection
DefaultCapability means default capability
Functions ¶
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
type ClientConn ¶
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 ¶
LoadAndCreateManager load namespace config, and create manager
func (*Manager) CheckPassword ¶
CheckPassword check if right password with specific user
func (*Manager) ConfigFingerprint ¶
ConfigFingerprint return config fingerprint
func (*Manager) DeleteNamespace ¶
DeleteNamespace delete namespace
func (*Manager) GetNamespace ¶
GetNamespace return specific namespace
func (*Manager) GetNamespaceByUser ¶
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 ¶
ReloadNamespaceCommit commit config
type Namespace ¶
type Namespace struct {
// contains filtered or unexported fields
}
Namespace is struct driected used by server
func NewNamespace ¶
NewNamespace init namespace
func (*Namespace) DumpToJSON ¶
DumpToJSON means easy encode json
func (*Namespace) GetAllowedDBs ¶
GetAllowedDBs return all allowed databases
func (*Namespace) GetBackendErrorSQLFingerprint ¶
GetBackendErrorSQLFingerprint return backedn error sql fingerprint
func (*Namespace) GetBackendErrorSQLFingerprints ¶
GetBackendErrorSQLFingerprints return all backend error sql fingerprints
func (*Namespace) GetBackendSlowSQLFingerprint ¶
GetBackendSlowSQLFingerprint return backend slow sql fingerprint
func (*Namespace) GetBackendSlowSQLFingerprints ¶
GetBackendSlowSQLFingerprints return all backend slow sql fingerprints
func (*Namespace) GetCachedPlan ¶
GetCachedPlan get plan in cache
func (*Namespace) GetDefaultCharset ¶
GetDefaultCharset return default charset
func (*Namespace) GetDefaultCollationID ¶
func (n *Namespace) GetDefaultCollationID() mysql.CollationID
GetDefaultCollationID return default collation id
func (*Namespace) GetDefaultPhyDB ¶
GetDefaultPhyDB return default real database
func (*Namespace) GetErrorSQLFingerprint ¶
GetErrorSQLFingerprint return error sql fingerprint
func (*Namespace) GetErrorSQLFingerprints ¶
GetErrorSQLFingerprints return all error sql fingerprints
func (*Namespace) GetSequences ¶
func (n *Namespace) GetSequences() *sequence.SequenceManager
func (*Namespace) GetSlowSQLFingerprint ¶
GetSlowSQLFingerprint return slow sql fingerprint
func (*Namespace) GetSlowSQLFingerprints ¶
GetSlowSQLFingerprints return slow sql fingerprints
func (*Namespace) GetUserProperty ¶
GetUserProperty return user information
func (*Namespace) IsAllowWrite ¶
IsAllowWrite check if user allow to write
func (*Namespace) IsAllowedDB ¶
IsAllowedDB if allowed database
func (*Namespace) IsClientIPAllowed ¶
IsClientIPAllowed check ip
func (*Namespace) IsSQLAllowed ¶
func (n *Namespace) IsSQLAllowed(reqCtx *util.RequestContext, sql string) bool
IsSQLAllowed check black sql
func (*Namespace) IsStatisticUser ¶
IsStatisticUser check if user is used to statistic
func (*Namespace) SetBackendErrorSQLFingerprint ¶
SetBackendErrorSQLFingerprint store backend error sql fingerprint
func (*Namespace) SetBackendSlowSQLFingerprint ¶
SetBackendSlowSQLFingerprint store backend slow sql fingerprint
func (*Namespace) SetCachedPlan ¶
SetCachedPlan set plan in cache
func (*Namespace) SetErrorSQLFingerprint ¶
SetErrorSQLFingerprint store error sql fingerprint
func (*Namespace) SetSlowSQLFingerprint ¶
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 ¶
Response response info
func CreateEOFResponse ¶
CreateEOFResponse create eof response
func CreateErrorResponse ¶
CreateErrorResponse create error response
func CreateFieldListResponse ¶
CreateFieldListResponse create field list response
func CreateNoopResponse ¶
func CreateNoopResponse() Response
CreateNoopResponse no op response, for ComStmtClose
func CreateOKResponse ¶
CreateOKResponse create ok response
func CreatePrepareResponse ¶
CreatePrepareResponse create prepare 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 {
// contains filtered or unexported fields
}
Server means proxy that serve client request
func (*Server) DeleteNamespace ¶
DeleteNamespace delete namespace in namespace manager
func (*Server) ReloadNamespaceCommit ¶
ReloadNamespaceCommit config change commit phase commit namespace does not need lock
func (*Server) ReloadNamespacePrepare ¶
ReloadNamespacePrepare config change prepare phase
type Session ¶
Session means session between client and proxy
func (*Session) Handshake ¶
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 ¶
IsAllowConnect check if allow to connect
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) 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) GetRewriteSQL ¶
GetRewriteSQL get rewrite sql
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 (*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 ¶
UserProperty means runtime user properties