server

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2023 License: Apache-2.0 Imports: 44 Imported by: 0

Documentation

Index

Constants

View Source
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
)
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 (
	Offline = iota
	Online
	Unknown
)

Variables

View Source
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.

View Source
var HbaConfigFile = flag.String("hba", "./etc/hba.conf", "He3Proxy hba config file")

define hba configuration

View Source
var UnParseSQL = [6]string{"PREPARE", "ROLLBACK", "LISTEN", "NOTIFY", "UNLISTEN", "VACUUM"}

Functions

func BytesCombine

func BytesCombine(pBytes []byte, data []byte) []byte

func GetAuthenticationConfiguration

func GetAuthenticationConfiguration() *hba.Conf

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

func ParseAndNormalize(val string) (*hba.Conf, error)

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

func RegisterAuthMethod(
	method string, validConnTypes hba.ConnType,
)

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 BoolIndex

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

func (*BoolIndex) Get

func (b *BoolIndex) Get() (int32, int32, bool)

func (*BoolIndex) Set

func (b *BoolIndex) Set(index bool)

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) 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 ExecuteDB

type ExecuteDB struct {
	ExecNode *backend.Node
	IsSlave  bool
	// contains filtered or unexported fields
}

type IPInfo

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

func ParseIPInfo

func ParseIPInfo(v string) (IPInfo, error)

func (*IPInfo) Info

func (t *IPInfo) Info() string

func (*IPInfo) Match

func (t *IPInfo) Match(ip net.IP) bool

type ResultRow

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

type Schema

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

type Server

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

func NewServer

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

func (*Server) AddAllowIP

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

func (*Server) AddBlackSql

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

func (*Server) AddSlave

func (s *Server) AddSlave(node string, addr string) error

func (*Server) ChangeLogSql

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

func (*Server) ChangeProxy

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

func (*Server) ChangeSlowLogTime

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

func (*Server) Close

func (s *Server) Close()

func (*Server) DelAllowIP

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

func (*Server) DelBlackSql

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

func (*Server) DeleteSlave

func (s *Server) DeleteSlave(node string, addr string) error

func (*Server) DownMaster

func (s *Server) DownMaster(node, masterAddr string) error

func (*Server) DownSlave

func (s *Server) DownSlave(node, slaveAddr string) error

func (*Server) GetAllBlackSqls

func (s *Server) GetAllBlackSqls() []string

func (*Server) GetAllNodes

func (s *Server) GetAllNodes() map[string]*backend.Node

func (*Server) GetAllowIps

func (s *Server) GetAllowIps() []string

func (*Server) GetMonitorData

func (s *Server) GetMonitorData() map[string]map[string]string

func (*Server) GetNode

func (s *Server) GetNode(name string) *backend.Node

func (*Server) GetSchema

func (s *Server) GetSchema(user string) *Schema

func (*Server) GetSlowLogTime

func (s *Server) GetSlowLogTime() int

func (*Server) Run

func (s *Server) Run() error

func (*Server) SaveProxyConfig

func (s *Server) SaveProxyConfig() error

func (*Server) Status

func (s *Server) Status() string

func (*Server) UpMaster

func (s *Server) UpMaster(node string, addr string) error

func (*Server) UpSlave

func (s *Server) UpSlave(node string, addr string) error

func (*Server) UpdateConfig

func (s *Server) UpdateConfig(newCfg *config.Config)

type Stmt

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

func (*Stmt) ResetParams

func (s *Stmt) ResetParams()

Jump to

Keyboard shortcuts

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