Documentation ¶
Index ¶
- Constants
- Variables
- func BytesCombine(pBytes []byte, data []byte) []byte
- func GetAuthenticationConfiguration() *hba.Conf
- func ParseAndNormalize(val string) (*hba.Conf, error)
- func RegisterAuthMethod(method string, validConnTypes hba.ConnType)
- type BlacklistSqls
- type BoolIndex
- type ClientConn
- func (c *ClientConn) AddDatabase(nodeName string, role string, addr string) error
- func (c *ClientConn) Close() error
- func (c *ClientConn) DeleteDatabase(nodeName string, role string, addr string) error
- func (cc *ClientConn) DoAuth(ctx context.Context, auth []byte) error
- func (c *ClientConn) DownDatabase(nodeName string, role string, addr string) error
- func (c *ClientConn) GetExecDB(tokens []string, sql string) (*ExecuteDB, error)
- func (c *ClientConn) GetTransExecDB(tokens []string, sql string) (*ExecuteDB, error)
- func (c *ClientConn) Handshake() error
- func (c *ClientConn) IsAllowConnect() bool
- func (cc *ClientConn) PgOpenSessionAndDoAuth(ctx context.Context) error
- func (cc *ClientConn) ReceiveStartupMessage() (pgproto3.FrontendMessage, error)
- func (c *ClientConn) Run()
- func (c *ClientConn) RunPg(ctx context.Context)
- func (c *ClientConn) UpDatabase(nodeName string, role string, addr string) error
- func (cc *ClientConn) WriteData(data []byte) error
- type Counter
- type ExecuteDB
- type IPInfo
- type ResultRow
- type Schema
- type Server
- func (s *Server) AddAllowIP(v string) error
- func (s *Server) AddBlackSql(v string) error
- func (s *Server) AddSlave(node string, addr string) error
- func (s *Server) ChangeLogSql(v string) error
- func (s *Server) ChangeProxy(v string) error
- func (s *Server) ChangeSlowLogTime(v string) error
- func (s *Server) Close()
- func (s *Server) DelAllowIP(v string) error
- func (s *Server) DelBlackSql(v string) error
- func (s *Server) DeleteSlave(node string, addr string) error
- func (s *Server) DownMaster(node, masterAddr string) error
- func (s *Server) DownSlave(node, slaveAddr string) error
- func (s *Server) GetAllBlackSqls() []string
- func (s *Server) GetAllNodes() map[string]*backend.Node
- func (s *Server) GetAllowIps() []string
- func (s *Server) GetMonitorData() map[string]map[string]string
- func (s *Server) GetNode(name string) *backend.Node
- func (s *Server) GetSchema(user string) *Schema
- func (s *Server) GetSlowLogTime() int
- func (s *Server) Run() error
- func (s *Server) SaveProxyConfig() error
- func (s *Server) Status() string
- func (s *Server) UpMaster(node string, addr string) error
- func (s *Server) UpSlave(node string, addr string) error
- func (s *Server) UpdateConfig(newCfg *config.Config)
- type Stmt
Constants ¶
const ( BEGIN_UNSTART = iota // Not exec 'begin' statement BEGIN_PRESTART // 'begin' already exec, but not exec insert/create/update/delete... statement. // 'begin' already exec, but not exec insert/create/update/delete... statement., and auto exec commit for backend connection. // cancel transaction state. BEGIN_PRESTART_COMMIT // after exec 'begin', and will exec insert/create/update/delete... statement. BEGIN_RELSTART // after exec 'begin' and insert/create/update/delete... statement. // Add 'begin' for first insert/create/update/delete... statement. BEGIN_RELSTART_BEGIN // after exec 'commit' for client BEGIN_COMMIT )
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" )
const ( MasterComment = "/*master*/" SumFunc = "sum" CountFunc = "count" MaxFunc = "max" MinFunc = "min" LastInsertIdFunc = "last_insert_id" FUNC_EXIST = 1 )
const ( Offline = iota Online Unknown )
Variables ¶
var DEFAULT_CAPABILITY = mysql.CLIENT_LONG_PASSWORD | mysql.CLIENT_LONG_FLAG | mysql.CLIENT_CONNECT_WITH_DB | mysql.CLIENT_PROTOCOL_41 | mysql.CLIENT_TRANSACTIONS | mysql.CLIENT_SECURE_CONNECTION
var DefaultHBAConfig = func() *hba.Conf { loadDefaultMethods() conf, err := ParseAndNormalize(` host all all all md5 # built-in CockroachDB default local all all md5 # built-in CockroachDB default `) if err != nil { panic(err) } return conf }()
DefaultHBAConfig is used when the stored HBA configuration string is empty or invalid.
var HbaConfigFile = flag.String("hba", "./etc/hba.conf", "He3Proxy hba config file")
define hba configuration
var UnParseSQL = [6]string{"PREPARE", "ROLLBACK", "LISTEN", "NOTIFY", "UNLISTEN", "VACUUM"}
Functions ¶
func BytesCombine ¶
func GetAuthenticationConfiguration ¶
GetAuthenticationConfiguration retrieves the current applicable authentication configuration.
This is guaranteed to return a valid configuration. Additionally, the various setters for the configuration also pass through ParseAndNormalize(), whereby an entry is always present at the start, to enable root to log in with a valid client cert.
The data returned by this method is also observable via the debug endpoint /debug/hba_conf.
func ParseAndNormalize ¶
ParseAndNormalize calls hba.ParseAndNormalize and also ensures the configuration starts with a rule that authenticates the root user with client certificates.
This prevents users from shooting themselves in the foot and making root not able to login, thus disallowing anyone from fixing the HBA configuration.
func RegisterAuthMethod ¶
RegisterAuthMethod registers an AuthMethod for pgwire authentication and for use in HBA configuration.
The minReqVersion is checked upon configuration to verify whether the current active cluster version is at least the version specified.
The validConnTypes is checked during rule matching when accepting connections: if the connection type is not accepted by the auth method, authentication is refused upfront. For example, the "cert" method requires SSL; if a rule specifies "host .... cert" and the client connects without SSL, the authentication is refused. (To express "cert on SSL, password on non-SSL", the HBA conf can list 'hostssl ... cert; hostnossl .... password' instead.)
The checkEntry method, if provided, is called upon configuration the cluster setting in the SQL client which attempts to change the configuration. It can block the configuration if e.g. the syntax is invalid.
Types ¶
type BlacklistSqls ¶
type BlacklistSqls struct {
// contains filtered or unexported fields
}
type ClientConn ¶
type ClientConn struct { sync.Mutex Parse sync.Map //parse name and parse info // 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) DoAuth ¶
func (cc *ClientConn) DoAuth(ctx context.Context, auth []byte) error
DoAuth PostgreSQL During authentication, the client will not actively send the authentication password. The server needs to send different types of password authentication requests before the client returns the corresponding authentication information.
func (*ClientConn) DownDatabase ¶
func (c *ClientConn) DownDatabase(nodeName string, role string, addr string) error
func (*ClientConn) GetExecDB ¶
func (c *ClientConn) GetExecDB(tokens []string, sql string) (*ExecuteDB, error)
if sql need shard return nil, else return the unshard db
func (*ClientConn) GetTransExecDB ¶
func (c *ClientConn) GetTransExecDB(tokens []string, sql string) (*ExecuteDB, error)
func (*ClientConn) Handshake ¶
func (c *ClientConn) Handshake() error
func (*ClientConn) IsAllowConnect ¶
func (c *ClientConn) IsAllowConnect() bool
func (*ClientConn) PgOpenSessionAndDoAuth ¶
func (cc *ClientConn) PgOpenSessionAndDoAuth(ctx context.Context) error
PgOpenSessionAndDoAuth Initialize session and perform user authentication There is a difference between PgSQL and mysql. The PgSQL client will send the password only after receiving the auth request from the server. At the beginning, if the MySQL client has a password, it will send the password directly to the server.
func (*ClientConn) ReceiveStartupMessage ¶
func (cc *ClientConn) ReceiveStartupMessage() (pgproto3.FrontendMessage, error)
ReceiveStartupMessage receives the initial connection message. This method is used of the normal Receive method because the initial connection message is "special" and does not include the message type as the first byte. This will return either a StartupMessage, SSLRequest, GSSEncRequest, or CancelRequest.
func (*ClientConn) Run ¶
func (c *ClientConn) Run()
func (*ClientConn) RunPg ¶
func (c *ClientConn) RunPg(ctx context.Context)
handle client request through goroutine
func (*ClientConn) UpDatabase ¶
func (c *ClientConn) UpDatabase(nodeName string, role string, addr string) error
func (*ClientConn) WriteData ¶
func (cc *ClientConn) WriteData(data []byte) error
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) 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 Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) AddAllowIP ¶
func (*Server) AddBlackSql ¶
func (*Server) ChangeLogSql ¶
func (*Server) ChangeProxy ¶
func (*Server) ChangeSlowLogTime ¶
func (*Server) DelAllowIP ¶
func (*Server) DelBlackSql ¶
func (*Server) DownMaster ¶
func (*Server) GetAllBlackSqls ¶
func (*Server) GetAllowIps ¶
func (*Server) GetSlowLogTime ¶
func (*Server) SaveProxyConfig ¶
func (*Server) UpdateConfig ¶
type Stmt ¶
type Stmt struct {
// contains filtered or unexported fields
}
func (*Stmt) ResetParams ¶
func (s *Stmt) ResetParams()