dbop

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrErrantTransactions = errors.New("detected errant transactions")
	ErrNoTopRunner        = errors.New("unable to determine the top runner")
	ErrTimeout            = errors.New("timeout")
)

Sentinel errors. To test these errors, use `errors.Is`.

View Source
var ErrNop = errors.New("nop")

ErrNop is a sentinel error for NopOperator

Functions

func ConfigureMySQLOnDocker added in v0.9.0

func ConfigureMySQLOnDocker(pwd *password.MySQLPassword, port int) error

func FindTopRunner added in v0.18.0

func FindTopRunner(ctx context.Context, o Operator, status []*MySQLInstanceStatus) (int, error)

FindTopRunner returns the index of the slice whose `GlobalVariables.ExecutedGtidSet` is most advanced. This may return ErrErrantTransactions for errant transactions or ErrNoTopRunner if there is no such instance.

func RunMySQLOnDocker added in v0.9.0

func RunMySQLOnDocker(name string, port, xport int) error

func SetLogger

func SetLogger(log logr.Logger)

SetLogger configures MySQL driver logging to use `log`.

Types

type AccessInfo

type AccessInfo struct {
	Host     string `db:"Host"`
	Port     int    `db:"Port"`
	User     string `db:"User"`
	Password string `db:"Password"`
}

type CloneStatus

type CloneStatus struct {
	State sql.NullString `db:"state"`
}

CloneStatus defines the observed clone status of a MySQL instance

type GlobalVariables

type GlobalVariables struct {
	UUID                  string `db:"@@server_uuid"`
	ExecutedGTID          string `db:"@@gtid_executed"`
	PurgedGTID            string `db:"@@gtid_purged"`
	ReadOnly              bool   `db:"@@read_only"`
	SuperReadOnly         bool   `db:"@@super_read_only"`
	WaitForSlaveCount     int    `db:"@@rpl_semi_sync_master_wait_for_slave_count"`
	SemiSyncMasterEnabled bool   `db:"@@rpl_semi_sync_master_enabled"`
	SemiSyncSlaveEnabled  bool   `db:"@@rpl_semi_sync_slave_enabled"`
}

GlobalVariables defines the observed global variable values of a MySQL instance

type MySQLInstanceStatus

type MySQLInstanceStatus struct {
	IsErrant        bool
	GlobalVariables GlobalVariables
	ReplicaHosts    []ReplicaHost
	ReplicaStatus   *ReplicaStatus // may not be available
	CloneStatus     *CloneStatus   // may not be available
}

MySQLInstanceStatus defines the observed state of a MySQL instance

type NopOperator added in v0.11.0

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

NopOperator is an implementation of Operator that always returns ErrNop.

func (NopOperator) Close added in v0.11.0

func (o NopOperator) Close() error

func (NopOperator) ConfigurePrimary added in v0.11.0

func (o NopOperator) ConfigurePrimary(ctx context.Context, waitForCount int) error

func (NopOperator) ConfigureReplica added in v0.11.0

func (o NopOperator) ConfigureReplica(ctx context.Context, source AccessInfo, semisync bool) error

func (NopOperator) GetStatus added in v0.11.0

func (NopOperator) IsSubsetGTID added in v0.11.0

func (o NopOperator) IsSubsetGTID(ctx context.Context, set1, set2 string) (bool, error)

func (NopOperator) KillConnections added in v0.11.0

func (o NopOperator) KillConnections(context.Context) error

func (NopOperator) Name added in v0.11.0

func (o NopOperator) Name() string

func (NopOperator) SetReadOnly added in v0.11.0

func (o NopOperator) SetReadOnly(context.Context, bool) error

func (NopOperator) StopReplicaIOThread added in v0.11.0

func (o NopOperator) StopReplicaIOThread(context.Context) error

func (NopOperator) SubtractGTID added in v0.15.0

func (o NopOperator) SubtractGTID(ctx context.Context, set1, set2 string) (string, error)

func (NopOperator) WaitForGTID added in v0.11.0

func (o NopOperator) WaitForGTID(ctx context.Context, gtidSet string, timeoutSeconds int) error

type Operator

type Operator interface {
	// Name is the name of the MySQL instance for which this operator works.
	Name() string

	// Close closes the underlying connections.
	Close() error

	// GetStatus reports the instance status.
	GetStatus(context.Context) (*MySQLInstanceStatus, error)

	// SubtractGTID returns GTID subset of set1 that are not in set2.
	SubtractGTID(ctx context.Context, set1, set2 string) (string, error)

	// IsSubsetGTID returns true if set1 is a subset of set2.
	IsSubsetGTID(ctx context.Context, set1, set2 string) (bool, error)

	// ConfigureReplica configures client-side replication.
	// If `symisync` is true, it enables client-side semi-synchronous replication.
	// In either case, it disables server-side semi-synchronous replication.
	ConfigureReplica(ctx context.Context, source AccessInfo, semisync bool) error

	// ConfigurePrimary configures server-side semi-synchronous replication.
	// For asynchronous replication, this method should not be called.
	ConfigurePrimary(ctx context.Context, waitForCount int) error

	// StopReplicaIOThread executes `STOP REPLICA IO_THREAD`.
	StopReplicaIOThread(context.Context) error

	// WaitForGTID waits for `mysqld` to execute all GTIDs in `gtidSet`.
	// If timeout happens, this return ErrTimeout.
	// If `timeoutSeconds` is zero, this will not timeout.
	WaitForGTID(ctx context.Context, gtidSet string, timeoutSeconds int) error

	// SetReadOnly makes the instance super_read_only if `true` is passed.
	// Otherwise, this stops the replication and makes the instance writable.
	SetReadOnly(context.Context, bool) error

	// KillConnections kills all connections except for ones from `localhost`
	// and ones for MOCO.
	KillConnections(context.Context) error
}

Operator represents a set of operations for a MySQL instance.

type OperatorFactory

type OperatorFactory interface {
	New(context.Context, *mocov1beta2.MySQLCluster, *password.MySQLPassword, int) (Operator, error)
	Cleanup()
}

OperatorFactory represents the factory for Operators.

func NewFactory

func NewFactory(r Resolver) OperatorFactory

NewFactory returns a new OperatorFactory that resolves instance IP address using `r`. If `r.Resolve` returns an error, the `New` method will return a NopOperator.

func NewTestFactory

func NewTestFactory() OperatorFactory

type Process added in v0.8.2

type Process struct {
	ID   uint64 `db:"ID"`
	User string `db:"USER"`
	Host string `db:"HOST"`
}

Process represents a process in `information_schema.PROCESSLIST` table.

type ReplicaHost

type ReplicaHost struct {
	ServerID    int32  `db:"Server_Id"`
	Host        string `db:"Host"`
	Port        int    `db:"Port"`
	SourceID    int32  `db:"Source_Id"`
	ReplicaUUID string `db:"Replica_UUID"`

	// the following fields don't appear normally
	User     string `db:"User"`
	Password string `db:"Password"`
}

ReplicaHost defines the columns from `SHOW REPLICAS`

type ReplicaStatus

type ReplicaStatus struct {
	LastIoErrno       int    `db:"Last_IO_Errno"`
	LastIoError       string `db:"Last_IO_Error"`
	LastSQLErrno      int    `db:"Last_SQL_Errno"`
	LastSQLError      string `db:"Last_SQL_Error"`
	SourceHost        string `db:"Source_Host"`
	RetrievedGtidSet  string `db:"Retrieved_Gtid_Set"`
	ExecutedGtidSet   string `db:"Executed_Gtid_Set"`
	ReplicaIORunning  string `db:"Replica_IO_Running"`
	ReplicaSQLRunning string `db:"Replica_SQL_Running"`

	// All of variables from here are NOT used in MOCO's reconcile
	ReplicaIOState            string        `db:"Replica_IO_State"`
	SourceUser                string        `db:"Source_User"`
	SourcePort                int           `db:"Source_Port"`
	ConnectRetry              int           `db:"Connect_Retry"`
	SourceLogFile             string        `db:"Source_Log_File"`
	ReadSourceLogPos          int           `db:"Read_Source_Log_Pos"`
	RelayLogFile              string        `db:"Relay_Log_File"`
	RelayLogPos               int           `db:"Relay_Log_Pos"`
	RelaySourceLogFile        string        `db:"Relay_Source_Log_File"`
	ReplicateDoDB             string        `db:"Replicate_Do_DB"`
	ReplicateIgnoreDB         string        `db:"Replicate_Ignore_DB"`
	ReplicateDoTable          string        `db:"Replicate_Do_Table"`
	ReplicateIgnoreTable      string        `db:"Replicate_Ignore_Table"`
	ReplicateWildDoTable      string        `db:"Replicate_Wild_Do_Table"`
	ReplicateWildIgnoreTable  string        `db:"Replicate_Wild_Ignore_Table"`
	LastErrno                 int           `db:"Last_Errno"`
	LastError                 string        `db:"Last_Error"`
	SkipCounter               int           `db:"Skip_Counter"`
	ExecSourceLogPos          int           `db:"Exec_Source_Log_Pos"`
	RelayLogSpace             int           `db:"Relay_Log_Space"`
	UntilCondition            string        `db:"Until_Condition"`
	UntilLogFile              string        `db:"Until_Log_File"`
	UntilLogPos               int           `db:"Until_Log_Pos"`
	SourceSSLAllowed          string        `db:"Source_SSL_Allowed"`
	SourceSSLCAFile           string        `db:"Source_SSL_CA_File"`
	SourceSSLCAPath           string        `db:"Source_SSL_CA_Path"`
	SourceSSLCert             string        `db:"Source_SSL_Cert"`
	SourceSSLCipher           string        `db:"Source_SSL_Cipher"`
	SourceSSLKey              string        `db:"Source_SSL_Key"`
	SecondsBehindSource       sql.NullInt64 `db:"Seconds_Behind_Source"`
	SourceSSLVerifyServerCert string        `db:"Source_SSL_Verify_Server_Cert"`
	ReplicateIgnoreServerIds  string        `db:"Replicate_Ignore_Server_Ids"`
	SourceServerID            int           `db:"Source_Server_Id"`
	SourceUUID                string        `db:"Source_UUID"`
	SourceInfoFile            string        `db:"Source_Info_File"`
	SQLDelay                  int           `db:"SQL_Delay"`
	SQLRemainingDelay         sql.NullInt64 `db:"SQL_Remaining_Delay"`
	ReplicaSQLRunningState    string        `db:"Replica_SQL_Running_State"`
	SourceRetryCount          int           `db:"Source_Retry_Count"`
	SourceBind                string        `db:"Source_Bind"`
	LastIOErrorTimestamp      string        `db:"Last_IO_Error_Timestamp"`
	LastSQLErrorTimestamp     string        `db:"Last_SQL_Error_Timestamp"`
	SourceSSLCrl              string        `db:"Source_SSL_Crl"`
	SourceSSLCrlpath          string        `db:"Source_SSL_Crlpath"`
	AutoPosition              string        `db:"Auto_Position"`
	ReplicateRewriteDB        string        `db:"Replicate_Rewrite_DB"`
	ChannelName               string        `db:"Channel_Name"`
	SourceTLSVersion          string        `db:"Source_TLS_Version"`
	Sourcepublickeypath       string        `db:"Source_public_key_path"`
	GetSourcepublickey        string        `db:"Get_Source_public_key"`
	NetworkNamespace          string        `db:"Network_Namespace"`
}

ReplicaStatus defines the observed state of a replica

func (*ReplicaStatus) IsRunning

func (rs *ReplicaStatus) IsRunning() bool

type Resolver

type Resolver interface {
	Resolve(context.Context, *mocov1beta2.MySQLCluster, int) (string, error)
}

Jump to

Keyboard shortcuts

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