binding

package
v0.6.0-beta.40 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2023 License: AGPL-3.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReadWrite AccessMode = "ReadWrite"
	Readonly  AccessMode = "Readonly"
	None      AccessMode = "None"

	// keys from response's metadata.
	RespOpKey           = "operation"
	RespStartTimeKey    = "start-time"
	RespRowsAffectedKey = "rows-affected"
	RespEndTimeKey      = "end-time"
	RespDurationKey     = "duration"
	StatusCode          = "status-code"
	// 451 Unavailable For Legal Reasons, used to indicate operation failed.
	OperationFailedHTTPCode = "451"
	// 404 Not Found, used to indicate operation not found.
	OperationNotFoundHTTPCode = "404"

	// CommandSQLKey keys from request's metadata.
	CommandSQLKey = "sql"
)
View Source
const (
	// types for probe
	CheckRunningType int = iota
	CheckStatusType
	CheckRoleChangedType
)
View Source
const (
	PRIMARY   = "primary"
	SECONDARY = "secondary"
	MASTER    = "master"
	SLAVE     = "slave"
	LEADER    = "Leader"
	FOLLOWER  = "Follower"
	LEARNER   = "Learner"
	CANDIDATE = "Candidate"
)

Variables

View Source
var (
	ErrNoSQL           = fmt.Errorf(errMsgNoSQL)
	ErrNoUserName      = fmt.Errorf(errMsgNoUserName)
	ErrNoPassword      = fmt.Errorf(errMsgNoPassword)
	ErrNoRoleName      = fmt.Errorf(errMsgNoRoleName)
	ErrInvalidRoleName = fmt.Errorf(errMsgInvalidRoleName)
	ErrNoSuchUser      = fmt.Errorf(errMsgNoSuchUser)
)

Functions

func DefaultUserInfoParser

func DefaultUserInfoParser(req *bindings.InvokeRequest, object *UserInfo) error

func ParseObjFromRequest

func ParseObjFromRequest[T customizedObjType](req *bindings.InvokeRequest, parse objectParser[T], validator objectValidator[T], object *T) error

func SentProbeEvent

func SentProbeEvent(ctx context.Context, opsResult OpsResult, log logger.Logger)

func SortRoleByWeight

func SortRoleByWeight(r1, r2 RoleType) bool

func String2RoleType

func String2RoleType(roleName string) RoleType

func UserNameAndPasswdValidator

func UserNameAndPasswdValidator(user UserInfo) error

func UserNameAndRoleValidator

func UserNameAndRoleValidator(user UserInfo) error

func UserNameValidator

func UserNameValidator(user UserInfo) error

Types

type AccessMode

type AccessMode string

AccessMode defines SVC access mode enums. +enum

type BaseInternalOps

type BaseInternalOps interface {
	InternalQuery(ctx context.Context, sql string) ([]byte, error)
	InternalExec(ctx context.Context, sql string) (int64, error)
	GetLogger() logger.Logger
	GetRunningPort() int
}

type BaseOperations

type BaseOperations struct {
	CheckRunningFailedCount    int
	CheckStatusFailedCount     int
	CheckRoleFailedCount       int
	RoleUnchangedCount         int
	FailedEventReportFrequency int
	// RoleDetectionThreshold is used to set the report duration of role event after role changed,
	// then event controller can always get rolechanged events to maintain pod label accurately
	// in cases of:
	// 1 rolechanged event lost;
	// 2 pod role label deleted or updated incorrectly.
	RoleDetectionThreshold int
	DBPort                 int
	DBAddress              string
	DBType                 string
	OriRole                string
	DBRoles                map[string]AccessMode
	Logger                 logger.Logger
	Metadata               bindings.Metadata
	InitIfNeed             func() bool
	GetRole                func(context.Context, *bindings.InvokeRequest, *bindings.InvokeResponse) (string, error)

	OperationsMap map[bindings.OperationKind]Operation
}

func (*BaseOperations) CheckRoleOps

func (*BaseOperations) CheckRunningOps

func (ops *BaseOperations) CheckRunningOps(ctx context.Context, req *bindings.InvokeRequest, resp *bindings.InvokeResponse) (OpsResult, error)

CheckRunningOps checks whether the binding service is in running status, If check fails continuously, report an event at FailedEventReportFrequency frequency

func (*BaseOperations) GetRoleOps

func (*BaseOperations) Init

func (ops *BaseOperations) Init(metadata bindings.Metadata)

func (*BaseOperations) Invoke

Invoke handles all invoke operations.

func (*BaseOperations) LockOps added in v0.6.0

func (*BaseOperations) Operations

func (ops *BaseOperations) Operations() []bindings.OperationKind

Operations returns list of operations supported by the binding.

func (*BaseOperations) RegisterOperation

func (ops *BaseOperations) RegisterOperation(opsKind bindings.OperationKind, operation Operation)

func (*BaseOperations) RegisterOperationOnDBReady added in v0.6.0

func (ops *BaseOperations) RegisterOperationOnDBReady(opsKind bindings.OperationKind, operation Operation, manager component.DBManager)

func (*BaseOperations) SwitchoverOps added in v0.6.0

func (ops *BaseOperations) SwitchoverOps(ctx context.Context, req *bindings.InvokeRequest, resp *bindings.InvokeResponse) (OpsResult, error)

func (*BaseOperations) UnlockOps added in v0.6.0

func (*BaseOperations) VolumeProtectionOps added in v0.6.0

func (ops *BaseOperations) VolumeProtectionOps(ctx context.Context, req *bindings.InvokeRequest, rsp *bindings.InvokeResponse) (OpsResult, error)

type Operation

type Operation func(ctx context.Context, request *bindings.InvokeRequest, response *bindings.InvokeResponse) (OpsResult, error)

func StartupCheckWraper added in v0.6.0

func StartupCheckWraper(manager component.DBManager, operation Operation) Operation

type OpsResult

type OpsResult map[string]interface{}

func ExecuteObject

func ExecuteObject[T customizedObjType](ctx context.Context, ops BaseInternalOps, req *bindings.InvokeRequest,
	opsKind bindings.OperationKind, sqlTplRend cmdRender[T], msgTplRend cmdRender[T], object T) (OpsResult, error)

func QueryObject

func QueryObject[T customizedObjType](ctx context.Context, ops BaseInternalOps, req *bindings.InvokeRequest,
	opsKind bindings.OperationKind, sqlTplRend cmdRender[T], dataProcessor resultRender[T], object T) (OpsResult, error)

type RedisEntry

type RedisEntry struct {
	Key  string `json:"key"`
	Data []byte `json:"data,omitempty"`
}

type SlaveStatus added in v0.6.0

type SlaveStatus struct {
	SecondsBehindMaster int64 `json:"Seconds_Behind_Master"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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