vitess.io/vitess@v0.16.2/go/vt/mysqlctl/mysql_daemon.go (about) 1 /* 2 Copyright 2019 The Vitess Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package mysqlctl 18 19 import ( 20 "context" 21 22 "vitess.io/vitess/go/mysql" 23 "vitess.io/vitess/go/sqltypes" 24 "vitess.io/vitess/go/vt/dbconnpool" 25 "vitess.io/vitess/go/vt/mysqlctl/tmutils" 26 27 querypb "vitess.io/vitess/go/vt/proto/query" 28 tabletmanagerdatapb "vitess.io/vitess/go/vt/proto/tabletmanagerdata" 29 ) 30 31 // MysqlDaemon is the interface we use for abstracting Mysqld. 32 type MysqlDaemon interface { 33 // methods related to mysql running or not 34 Start(ctx context.Context, cnf *Mycnf, mysqldArgs ...string) error 35 Shutdown(ctx context.Context, cnf *Mycnf, waitForMysqld bool) error 36 RunMysqlUpgrade() error 37 ReinitConfig(ctx context.Context, cnf *Mycnf) error 38 Wait(ctx context.Context, cnf *Mycnf) error 39 40 // GetMysqlPort returns the current port mysql is listening on. 41 GetMysqlPort() (int32, error) 42 43 // GetServerID returns the servers ID. 44 GetServerID(ctx context.Context) (uint32, error) 45 46 // GetServerUUID returns the servers UUID 47 GetServerUUID(ctx context.Context) (string, error) 48 49 // replication related methods 50 StartReplication(hookExtraEnv map[string]string) error 51 RestartReplication(hookExtraEnv map[string]string) error 52 StartReplicationUntilAfter(ctx context.Context, pos mysql.Position) error 53 StopReplication(hookExtraEnv map[string]string) error 54 StopIOThread(ctx context.Context) error 55 ReplicationStatus() (mysql.ReplicationStatus, error) 56 PrimaryStatus(ctx context.Context) (mysql.PrimaryStatus, error) 57 GetGTIDPurged(ctx context.Context) (mysql.Position, error) 58 SetSemiSyncEnabled(source, replica bool) error 59 SemiSyncEnabled() (source, replica bool) 60 SemiSyncStatus() (source, replica bool) 61 SemiSyncClients() (count uint32) 62 SemiSyncSettings() (timeout uint64, numReplicas uint32) 63 SemiSyncReplicationStatus() (bool, error) 64 ResetReplicationParameters(ctx context.Context) error 65 GetBinlogInformation(ctx context.Context) (binlogFormat string, logEnabled bool, logReplicaUpdate bool, binlogRowImage string, err error) 66 GetGTIDMode(ctx context.Context) (gtidMode string, err error) 67 FlushBinaryLogs(ctx context.Context) (err error) 68 GetBinaryLogs(ctx context.Context) (binaryLogs []string, err error) 69 GetPreviousGTIDs(ctx context.Context, binlog string) (previousGtids string, err error) 70 71 // reparenting related methods 72 ResetReplication(ctx context.Context) error 73 PrimaryPosition() (mysql.Position, error) 74 IsReadOnly() (bool, error) 75 SetReadOnly(on bool) error 76 SetSuperReadOnly(on bool) error 77 SetReplicationPosition(ctx context.Context, pos mysql.Position) error 78 SetReplicationSource(ctx context.Context, host string, port int, stopReplicationBefore bool, startReplicationAfter bool) error 79 WaitForReparentJournal(ctx context.Context, timeCreatedNS int64) error 80 81 WaitSourcePos(context.Context, mysql.Position) error 82 83 // Promote makes the current server the primary. It will not change 84 // the read_only state of the server. 85 Promote(map[string]string) (mysql.Position, error) 86 87 // Schema related methods 88 GetSchema(ctx context.Context, dbName string, request *tabletmanagerdatapb.GetSchemaRequest) (*tabletmanagerdatapb.SchemaDefinition, error) 89 GetColumns(ctx context.Context, dbName, table string) ([]*querypb.Field, []string, error) 90 GetPrimaryKeyColumns(ctx context.Context, dbName, table string) ([]string, error) 91 GetPrimaryKeyEquivalentColumns(ctx context.Context, dbName, table string) ([]string, error) 92 PreflightSchemaChange(ctx context.Context, dbName string, changes []string) ([]*tabletmanagerdatapb.SchemaChangeResult, error) 93 ApplySchemaChange(ctx context.Context, dbName string, change *tmutils.SchemaChange) (*tabletmanagerdatapb.SchemaChangeResult, error) 94 95 // GetAppConnection returns a app connection to be able to talk to the database. 96 GetAppConnection(ctx context.Context) (*dbconnpool.PooledDBConnection, error) 97 // GetDbaConnection returns a dba connection. 98 GetDbaConnection(ctx context.Context) (*dbconnpool.DBConnection, error) 99 // GetAllPrivsConnection returns an allprivs connection (for user with all privileges except SUPER). 100 GetAllPrivsConnection(ctx context.Context) (*dbconnpool.DBConnection, error) 101 102 // GetVersionString returns the database version as a string 103 GetVersionString() string 104 105 // GetVersionComment returns the version comment 106 GetVersionComment(ctx context.Context) string 107 108 // ExecuteSuperQueryList executes a list of queries, no result 109 ExecuteSuperQueryList(ctx context.Context, queryList []string) error 110 111 // FetchSuperQuery executes one query, returns the result 112 FetchSuperQuery(ctx context.Context, query string) (*sqltypes.Result, error) 113 114 // EnableBinlogPlayback enables playback of binlog events 115 EnableBinlogPlayback() error 116 117 // DisableBinlogPlayback disable playback of binlog events 118 DisableBinlogPlayback() error 119 120 // Close will close this instance of Mysqld. It will wait for all dba 121 // queries to be finished. 122 Close() 123 }