From 5356ef543680b14b547cf98fa9425ba760e75d4d Mon Sep 17 00:00:00 2001 From: Dirkjan Bussink Date: Fri, 30 Jun 2023 18:05:34 +0200 Subject: [PATCH] vtorc: Cleanup more unused code (#13354) --- go/vt/external/golib/sqlutils/sqlutils.go | 57 +--------------- go/vt/vtorc/collection/collection.go | 7 -- go/vt/vtorc/config/config.go | 4 -- go/vt/vtorc/db/db.go | 5 +- go/vt/vtorc/inst/analysis.go | 13 ---- go/vt/vtorc/inst/audit.go | 26 -------- go/vt/vtorc/inst/audit_dao.go | 45 ------------- go/vt/vtorc/inst/audit_dao_test.go | 58 ++++++++++++++-- go/vt/vtorc/inst/instance.go | 53 +-------------- go/vt/vtorc/inst/instance_binlog.go | 62 ------------------ go/vt/vtorc/inst/instance_dao.go | 8 +-- go/vt/vtorc/inst/instance_test.go | 38 ----------- go/vt/vtorc/inst/instance_utils.go | 36 ---------- go/vt/vtorc/inst/oracle_gtid_set.go | 13 ++-- go/vt/vtorc/inst/postponed_functions.go | 69 -------------------- go/vt/vtorc/inst/process.go | 32 --------- go/vt/vtorc/inst/replication_thread_state.go | 10 --- go/vt/vtorc/logic/topology_recovery.go | 20 ------ go/vt/vtorc/logic/topology_recovery_dao.go | 2 +- go/vt/vtorc/util/math.go | 58 ---------------- 20 files changed, 69 insertions(+), 547 deletions(-) delete mode 100644 go/vt/vtorc/inst/audit.go delete mode 100644 go/vt/vtorc/inst/instance_binlog.go delete mode 100644 go/vt/vtorc/inst/postponed_functions.go delete mode 100644 go/vt/vtorc/inst/process.go diff --git a/go/vt/external/golib/sqlutils/sqlutils.go b/go/vt/external/golib/sqlutils/sqlutils.go index 88ab443b56b..eb1cb8c8941 100644 --- a/go/vt/external/golib/sqlutils/sqlutils.go +++ b/go/vt/external/golib/sqlutils/sqlutils.go @@ -77,35 +77,10 @@ func (this *RowData) MarshalJSON() ([]byte, error) { return json.Marshal(cells) } -func (this *RowData) Args() []any { - result := make([]any, len(*this)) - for i := range *this { - result[i] = (*(*this)[i].NullString()) - } - return result -} - -// ResultData is an ordered row set of RowData -type ResultData []RowData -type NamedResultData struct { - Columns []string - Data ResultData -} - -var EmptyResultData = ResultData{} - func (this *RowMap) GetString(key string) string { return (*this)[key].String } -// GetStringD returns a string from the map, or a default value if the key does not exist -func (this *RowMap) GetStringD(key string, def string) string { - if cell, ok := (*this)[key]; ok { - return cell.String - } - return def -} - func (this *RowMap) GetInt64(key string) int64 { res, _ := strconv.ParseInt(this.GetString(key), 10, 64) return res @@ -130,40 +105,16 @@ func (this *RowMap) GetInt(key string) int { return res } -func (this *RowMap) GetIntD(key string, def int) int { - res, err := strconv.Atoi(this.GetString(key)) - if err != nil { - return def - } - return res -} - func (this *RowMap) GetUint(key string) uint { res, _ := strconv.ParseUint(this.GetString(key), 10, 0) return uint(res) } -func (this *RowMap) GetUintD(key string, def uint) uint { - res, err := strconv.ParseUint(this.GetString(key), 10, 0) - if err != nil { - return def - } - return uint(res) -} - func (this *RowMap) GetUint64(key string) uint64 { res, _ := strconv.ParseUint(this.GetString(key), 10, 64) return res } -func (this *RowMap) GetUint64D(key string, def uint64) uint64 { - res, err := strconv.ParseUint(this.GetString(key), 10, 64) - if err != nil { - return def - } - return res -} - func (this *RowMap) GetUint32(key string) uint32 { res, _ := strconv.ParseUint(this.GetString(key), 10, 32) return uint32(res) @@ -181,7 +132,7 @@ func (this *RowMap) GetTime(key string) time.Time { } // knownDBs is a DB cache by uri -var knownDBs map[string]*sql.DB = make(map[string]*sql.DB) +var knownDBs = make(map[string]*sql.DB) var knownDBsMutex = &sync.Mutex{} // GetGenericDB returns a DB instance based on uri. @@ -203,12 +154,6 @@ func GetGenericDB(driverName, dataSourceName string) (*sql.DB, bool, error) { return knownDBs[dataSourceName], exists, nil } -// GetDB returns a MySQL DB instance based on uri. -// bool result indicates whether the DB was returned from cache; err -func GetDB(mysql_uri string) (*sql.DB, bool, error) { - return GetGenericDB("mysql", mysql_uri) -} - // GetSQLiteDB returns a SQLite DB instance based on DB file name. // bool result indicates whether the DB was returned from cache; err func GetSQLiteDB(dbFile string) (*sql.DB, bool, error) { diff --git a/go/vt/vtorc/collection/collection.go b/go/vt/vtorc/collection/collection.go index cfc8116c9c5..0ef9a71b9a3 100644 --- a/go/vt/vtorc/collection/collection.go +++ b/go/vt/vtorc/collection/collection.go @@ -97,13 +97,6 @@ func init() { namedCollection = make(map[string](*Collection)) } -// StopMonitoring stops monitoring all the collections -func StopMonitoring() { - for _, q := range namedCollection { - q.StopAutoExpiration() - } -} - // CreateOrReturnCollection allows for creation of a new collection or // returning a pointer to an existing one given the name. This allows access // to the data structure from the api interface (http/api.go) and also when writing (inst). diff --git a/go/vt/vtorc/config/config.go b/go/vt/vtorc/config/config.go index 00d58f6dd89..6f4c20cdaf8 100644 --- a/go/vt/vtorc/config/config.go +++ b/go/vt/vtorc/config/config.go @@ -36,10 +36,7 @@ var configurationLoaded = make(chan bool) const ( HealthPollSeconds = 1 ActiveNodeExpireSeconds = 5 - MaintenanceOwner = "vtorc" AuditPageSize = 20 - MaintenancePurgeDays = 7 - MaintenanceExpireMinutes = 10 DebugMetricsIntervalSeconds = 10 StaleInstanceCoordinatesExpireSeconds = 60 DiscoveryMaxConcurrency = 300 // Number of goroutines doing hosts discovery @@ -47,7 +44,6 @@ const ( DiscoveryQueueMaxStatisticsSize = 120 DiscoveryCollectionRetentionSeconds = 120 UnseenInstanceForgetHours = 240 // Number of hours after which an unseen instance is forgotten - CandidateInstanceExpireMinutes = 60 // Minutes after which a suggestion to use an instance as a candidate replica (to be preferably promoted on primary failover) is expired. FailureDetectionPeriodBlockMinutes = 60 // The time for which an instance's failure discovery is kept "active", so as to avoid concurrent "discoveries" of the instance's failure; this preceeds any recovery process, if any. ) diff --git a/go/vt/vtorc/db/db.go b/go/vt/vtorc/db/db.go index aca3b248c26..d565c9bbdc4 100644 --- a/go/vt/vtorc/db/db.go +++ b/go/vt/vtorc/db/db.go @@ -153,14 +153,11 @@ func execInternal(db *sql.DB, query string, args ...any) (sql.Result, error) { // ExecVTOrc will execute given query on the vtorc backend database. func ExecVTOrc(query string, args ...any) (sql.Result, error) { - var err error - query = translateStatement(query) db, err := OpenVTOrc() if err != nil { return nil, err } - res, err := sqlutils.ExecNoPrepare(db, query, args...) - return res, err + return execInternal(db, query, args...) } // QueryVTOrcRowsMap diff --git a/go/vt/vtorc/inst/analysis.go b/go/vt/vtorc/inst/analysis.go index e586ac33fc8..e0f83f6a2f1 100644 --- a/go/vt/vtorc/inst/analysis.go +++ b/go/vt/vtorc/inst/analysis.go @@ -18,7 +18,6 @@ package inst import ( "encoding/json" - "strings" "time" topodatapb "vitess.io/vitess/go/vt/proto/topodata" @@ -156,18 +155,6 @@ func (replicationAnalysis *ReplicationAnalysis) MarshalJSON() ([]byte, error) { return json.Marshal(i) } -// AnalysisString returns a human friendly description of all analysis issues -func (replicationAnalysis *ReplicationAnalysis) AnalysisString() string { - result := []string{} - if replicationAnalysis.Analysis != NoProblem { - result = append(result, string(replicationAnalysis.Analysis)) - } - for _, structureAnalysis := range replicationAnalysis.StructureAnalysis { - result = append(result, string(structureAnalysis)) - } - return strings.Join(result, ", ") -} - // Get a string description of the analyzed instance type (primary? co-primary? intermediate-primary?) func (replicationAnalysis *ReplicationAnalysis) GetAnalysisInstanceType() AnalysisInstanceType { if replicationAnalysis.IsCoPrimary { diff --git a/go/vt/vtorc/inst/audit.go b/go/vt/vtorc/inst/audit.go deleted file mode 100644 index b094a293040..00000000000 --- a/go/vt/vtorc/inst/audit.go +++ /dev/null @@ -1,26 +0,0 @@ -/* - Copyright 2014 Outbrain Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package inst - -// Audit presents a single audit entry (namely in the database) -type Audit struct { - AuditID int64 - AuditTimestamp string - AuditType string - AuditTabletAlias string - Message string -} diff --git a/go/vt/vtorc/inst/audit_dao.go b/go/vt/vtorc/inst/audit_dao.go index 22bc9395964..b2eab9abc64 100644 --- a/go/vt/vtorc/inst/audit_dao.go +++ b/go/vt/vtorc/inst/audit_dao.go @@ -22,7 +22,6 @@ import ( "os" "time" - "vitess.io/vitess/go/vt/external/golib/sqlutils" "vitess.io/vitess/go/vt/log" "github.com/rcrowley/go-metrics" @@ -109,50 +108,6 @@ func AuditOperation(auditType string, tabletAlias string, message string) error return nil } -// ReadRecentAudit returns a list of audit entries order chronologically descending, using page number. -func ReadRecentAudit(tabletAlias string, page int) ([]Audit, error) { - res := []Audit{} - args := sqlutils.Args() - whereCondition := `` - if tabletAlias != "" { - whereCondition = `where alias=?` - args = append(args, tabletAlias) - } - query := fmt.Sprintf(` - select - audit_id, - audit_timestamp, - audit_type, - alias, - message - from - audit - %s - order by - audit_timestamp desc - limit ? - offset ? - `, whereCondition) - args = append(args, config.AuditPageSize, page*config.AuditPageSize) - err := db.QueryVTOrc(query, args, func(m sqlutils.RowMap) error { - audit := Audit{} - audit.AuditID = m.GetInt64("audit_id") - audit.AuditTimestamp = m.GetString("audit_timestamp") - audit.AuditType = m.GetString("audit_type") - audit.AuditTabletAlias = m.GetString("alias") - audit.Message = m.GetString("message") - - res = append(res, audit) - return nil - }) - - if err != nil { - log.Error(err) - } - return res, err - -} - // ExpireAudit removes old rows from the audit table func ExpireAudit() error { return ExpireTableData("audit", "audit_timestamp") diff --git a/go/vt/vtorc/inst/audit_dao_test.go b/go/vt/vtorc/inst/audit_dao_test.go index 2b3c3bfad64..1d50de4c146 100644 --- a/go/vt/vtorc/inst/audit_dao_test.go +++ b/go/vt/vtorc/inst/audit_dao_test.go @@ -17,12 +17,14 @@ limitations under the License. package inst import ( + "fmt" "os" "testing" "time" "github.com/stretchr/testify/require" + "vitess.io/vitess/go/vt/external/golib/sqlutils" topodatapb "vitess.io/vitess/go/vt/proto/topodata" "vitess.io/vitess/go/vt/topo/topoproto" "vitess.io/vitess/go/vt/vtorc/config" @@ -75,7 +77,7 @@ func TestAuditOperation(t *testing.T) { auditType := "test-audit-operation" message := "test-message" - t.Run("Audit to backend", func(t *testing.T) { + t.Run("audit to backend", func(t *testing.T) { config.Config.AuditLogFile = "" config.Config.AuditToSyslog = false config.Config.AuditToBackendDB = true @@ -85,7 +87,7 @@ func TestAuditOperation(t *testing.T) { require.NoError(t, err) // Check that we can read the recent audits - audits, err := ReadRecentAudit(tab100Alias, 0) + audits, err := readRecentAudit(tab100Alias, 0) require.NoError(t, err) require.Len(t, audits, 1) require.EqualValues(t, 1, audits[0].AuditID) @@ -94,7 +96,7 @@ func TestAuditOperation(t *testing.T) { require.EqualValues(t, tab100Alias, audits[0].AuditTabletAlias) // Check the same for no-filtering - audits, err = ReadRecentAudit("", 0) + audits, err = readRecentAudit("", 0) require.NoError(t, err) require.Len(t, audits, 1) require.EqualValues(t, 1, audits[0].AuditID) @@ -103,7 +105,7 @@ func TestAuditOperation(t *testing.T) { require.EqualValues(t, tab100Alias, audits[0].AuditTabletAlias) }) - t.Run("Audit to File", func(t *testing.T) { + t.Run("audit to File", func(t *testing.T) { config.Config.AuditToBackendDB = false config.Config.AuditToSyslog = false @@ -124,3 +126,51 @@ func TestAuditOperation(t *testing.T) { require.Contains(t, string(fileContent), "\ttest-audit-operation\tzone-1-0000000100\t[ks:0]\ttest-message") }) } + +// audit presents a single audit entry (namely in the database) +type audit struct { + AuditID int64 + AuditTimestamp string + AuditType string + AuditTabletAlias string + Message string +} + +// readRecentAudit returns a list of audit entries order chronologically descending, using page number. +func readRecentAudit(tabletAlias string, page int) ([]audit, error) { + res := []audit{} + var args []any + whereCondition := `` + if tabletAlias != "" { + whereCondition = `where alias=?` + args = append(args, tabletAlias) + } + query := fmt.Sprintf(` + select + audit_id, + audit_timestamp, + audit_type, + alias, + message + from + audit + %s + order by + audit_timestamp desc + limit ? + offset ? + `, whereCondition) + args = append(args, config.AuditPageSize, page*config.AuditPageSize) + err := db.QueryVTOrc(query, args, func(m sqlutils.RowMap) error { + a := audit{} + a.AuditID = m.GetInt64("audit_id") + a.AuditTimestamp = m.GetString("audit_timestamp") + a.AuditType = m.GetString("audit_type") + a.AuditTabletAlias = m.GetString("alias") + a.Message = m.GetString("message") + + res = append(res, a) + return nil + }) + return res, err +} diff --git a/go/vt/vtorc/inst/instance.go b/go/vt/vtorc/inst/instance.go index 39425f718ee..1216d4c24ae 100644 --- a/go/vt/vtorc/inst/instance.go +++ b/go/vt/vtorc/inst/instance.go @@ -97,8 +97,6 @@ type Instance struct { Problems []string LastDiscoveryLatency time.Duration - - seed bool // Means we force this instance to be written to backend, even if it's invalid, empty or forgotten } // NewInstance creates a new, empty instance @@ -129,48 +127,11 @@ func (instance *Instance) MajorVersion() []string { return MajorVersion(instance.Version) } -// MajorVersion returns this instance's major version number (e.g. for 5.5.36 it returns "5.5") +// MajorVersionString returns this instance's major version number (e.g. for 5.5.36 it returns "5.5") func (instance *Instance) MajorVersionString() string { return strings.Join(instance.MajorVersion(), ".") } -func (instance *Instance) IsMySQL51() bool { - return instance.MajorVersionString() == "5.1" -} - -func (instance *Instance) IsMySQL55() bool { - return instance.MajorVersionString() == "5.5" -} - -func (instance *Instance) IsMySQL56() bool { - return instance.MajorVersionString() == "5.6" -} - -func (instance *Instance) IsMySQL57() bool { - return instance.MajorVersionString() == "5.7" -} - -func (instance *Instance) IsMySQL80() bool { - return instance.MajorVersionString() == "8.0" -} - -// IsSmallerBinlogFormat returns true when this instance's binlgo format is -// "smaller" than the other's, i.e. binary logs cannot flow from the other instance to this one -func (instance *Instance) IsSmallerBinlogFormat(other *Instance) bool { - return IsSmallerBinlogFormat(instance.BinlogFormat, other.BinlogFormat) -} - -// IsSmallerMajorVersion tests this instance against another and returns true if this instance is of a smaller "major" varsion. -// e.g. 5.5.36 is NOT a smaller major version as comapred to 5.5.36, but IS as compared to 5.6.9 -func (instance *Instance) IsSmallerMajorVersion(other *Instance) bool { - return IsSmallerMajorVersion(instance.Version, other.Version) -} - -// IsSmallerMajorVersionByString checks if this instance has a smaller major version number than given one -func (instance *Instance) IsSmallerMajorVersionByString(otherVersion string) bool { - return IsSmallerMajorVersion(instance.Version, otherVersion) -} - // IsMariaDB checks whether this is any version of MariaDB func (instance *Instance) IsMariaDB() bool { return strings.Contains(instance.Version, "MariaDB") @@ -181,11 +142,6 @@ func (instance *Instance) IsPercona() bool { return strings.Contains(instance.VersionComment, "Percona") } -// isNDB check whether this is NDB Cluster (aka MySQL Cluster) -func (instance *Instance) IsNDB() bool { - return strings.Contains(instance.Version, "-ndb-") -} - // IsBinlogServer checks whether this is any type of a binlog server func (instance *Instance) IsBinlogServer() bool { return false @@ -205,13 +161,6 @@ func (instance *Instance) IsOracleMySQL() bool { return true } -func (instance *Instance) SetSeed() { - instance.seed = true -} -func (instance *Instance) IsSeed() bool { - return instance.seed -} - // applyFlavorName func (instance *Instance) applyFlavorName() { if instance == nil { diff --git a/go/vt/vtorc/inst/instance_binlog.go b/go/vt/vtorc/inst/instance_binlog.go deleted file mode 100644 index 629eb11a3e4..00000000000 --- a/go/vt/vtorc/inst/instance_binlog.go +++ /dev/null @@ -1,62 +0,0 @@ -/* - Copyright 2014 Outbrain Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package inst - -import ( - "regexp" -) - -// Event entries may contains table IDs (can be different for same tables on different servers) -// and also COMMIT transaction IDs (different values on different servers). -// So these need to be removed from the event entry if we're to compare and validate matching -// entries. -var eventInfoTransformations = map[*regexp.Regexp]string{ - regexp.MustCompile(`(.*) [/][*].*?[*][/](.*$)`): "$1 $2", // strip comments - regexp.MustCompile(`(COMMIT) .*$`): "$1", // commit number varies cross servers - regexp.MustCompile(`(table_id:) [0-9]+ (.*$)`): "$1 ### $2", // table ids change cross servers - regexp.MustCompile(`(table_id:) [0-9]+$`): "$1 ###", // table ids change cross servers - regexp.MustCompile(` X'([0-9a-fA-F]+)' COLLATE`): " 0x$1 COLLATE", // different ways to represent collate - regexp.MustCompile(`(BEGIN GTID [^ ]+) cid=.*`): "$1", // MariaDB GTID someimtes gets addition of "cid=...". Stripping -} - -type BinlogEvent struct { - Coordinates BinlogCoordinates - NextEventPos uint32 - EventType string - Info string -} - -func (binlogEvent *BinlogEvent) NextBinlogCoordinates() BinlogCoordinates { - return BinlogCoordinates{LogFile: binlogEvent.Coordinates.LogFile, LogPos: binlogEvent.NextEventPos, Type: binlogEvent.Coordinates.Type} -} - -func (binlogEvent *BinlogEvent) NormalizeInfo() { - for reg, replace := range eventInfoTransformations { - binlogEvent.Info = reg.ReplaceAllString(binlogEvent.Info, replace) - } -} - -func (binlogEvent *BinlogEvent) Equals(other *BinlogEvent) bool { - return binlogEvent.Coordinates.Equals(&other.Coordinates) && - binlogEvent.NextEventPos == other.NextEventPos && - binlogEvent.EventType == other.EventType && binlogEvent.Info == other.Info -} - -func (binlogEvent *BinlogEvent) EqualsIgnoreCoordinates(other *BinlogEvent) bool { - return binlogEvent.NextEventPos == other.NextEventPos && - binlogEvent.EventType == other.EventType && binlogEvent.Info == other.Info -} diff --git a/go/vt/vtorc/inst/instance_dao.go b/go/vt/vtorc/inst/instance_dao.go index 18ddc4bf3e4..b751018a9da 100644 --- a/go/vt/vtorc/inst/instance_dao.go +++ b/go/vt/vtorc/inst/instance_dao.go @@ -237,10 +237,10 @@ func ReadTopologyInstanceBufferable(tabletAlias string, latency *stopwatch.Named instance.SemiSyncPrimaryStatus = fullStatus.SemiSyncPrimaryStatus instance.SemiSyncReplicaStatus = fullStatus.SemiSyncReplicaStatus - if (instance.IsOracleMySQL() || instance.IsPercona()) && !instance.IsSmallerMajorVersionByString("5.6") { - // Stuff only supported on Oracle MySQL >= 5.6 + if instance.IsOracleMySQL() || instance.IsPercona() { + // Stuff only supported on Oracle / Percona MySQL // ... - // @@gtid_mode only available in Orcale MySQL >= 5.6 + // @@gtid_mode only available in Oracle / Percona MySQL >= 5.6 instance.GTIDMode = fullStatus.GtidMode instance.ServerUUID = fullStatus.ServerUuid if fullStatus.PrimaryStatus != nil { @@ -964,7 +964,7 @@ func mkInsertOdkuForInstances(instances []*Instance, instanceWasActuallyFound bo func writeManyInstances(instances []*Instance, instanceWasActuallyFound bool, updateLastSeen bool) error { writeInstances := [](*Instance){} for _, instance := range instances { - if InstanceIsForgotten(instance.InstanceAlias) && !instance.IsSeed() { + if InstanceIsForgotten(instance.InstanceAlias) { continue } writeInstances = append(writeInstances, instance) diff --git a/go/vt/vtorc/inst/instance_test.go b/go/vt/vtorc/inst/instance_test.go index 8dba101a8dc..9ca2f243999 100644 --- a/go/vt/vtorc/inst/instance_test.go +++ b/go/vt/vtorc/inst/instance_test.go @@ -30,44 +30,6 @@ func init() { var instance1 = Instance{InstanceAlias: "zone1-100"} -func TestIsSmallerMajorVersion(t *testing.T) { - i55 := Instance{Version: "5.5"} - i5517 := Instance{Version: "5.5.17"} - i56 := Instance{Version: "5.6"} - - require.False(t, i55.IsSmallerMajorVersion(&i5517)) - require.False(t, i56.IsSmallerMajorVersion(&i5517)) - require.True(t, i55.IsSmallerMajorVersion(&i56)) -} - -func TestIsVersion(t *testing.T) { - i51 := Instance{Version: "5.1.19"} - i55 := Instance{Version: "5.5.17-debug"} - i56 := Instance{Version: "5.6.20"} - i57 := Instance{Version: "5.7.8-log"} - - require.True(t, i51.IsMySQL51()) - require.True(t, i55.IsMySQL55()) - require.True(t, i56.IsMySQL56()) - require.False(t, i55.IsMySQL56()) - require.True(t, i57.IsMySQL57()) - require.False(t, i56.IsMySQL57()) -} - -func TestIsSmallerBinlogFormat(t *testing.T) { - iStatement := &Instance{BinlogFormat: "STATEMENT"} - iRow := &Instance{BinlogFormat: "ROW"} - iMixed := &Instance{BinlogFormat: "MIXED"} - require.True(t, iStatement.IsSmallerBinlogFormat(iRow)) - require.False(t, iStatement.IsSmallerBinlogFormat(iStatement)) - require.False(t, iRow.IsSmallerBinlogFormat(iStatement)) - - require.True(t, iStatement.IsSmallerBinlogFormat(iMixed)) - require.True(t, iMixed.IsSmallerBinlogFormat(iRow)) - require.False(t, iMixed.IsSmallerBinlogFormat(iStatement)) - require.False(t, iRow.IsSmallerBinlogFormat(iMixed)) -} - func TestReplicationThreads(t *testing.T) { { require.False(t, instance1.ReplicaRunning()) diff --git a/go/vt/vtorc/inst/instance_utils.go b/go/vt/vtorc/inst/instance_utils.go index b14a0794c31..f6bde729822 100644 --- a/go/vt/vtorc/inst/instance_utils.go +++ b/go/vt/vtorc/inst/instance_utils.go @@ -18,14 +18,9 @@ package inst import ( "regexp" - "strconv" "strings" ) -var ( - DowntimeLostInRecoveryMessage = "lost-in-recovery" -) - // MajorVersion returns a MySQL major version number (e.g. given "5.5.36" it returns "5.5") func MajorVersion(version string) []string { tokens := strings.Split(version, ".") @@ -35,37 +30,6 @@ func MajorVersion(version string) []string { return tokens[:2] } -// IsSmallerMajorVersion tests two versions against another and returns true if -// the former is a smaller "major" varsion than the latter. -// e.g. 5.5.36 is NOT a smaller major version as comapred to 5.5.40, but IS as compared to 5.6.9 -func IsSmallerMajorVersion(version string, otherVersion string) bool { - thisMajorVersion := MajorVersion(version) - otherMajorVersion := MajorVersion(otherVersion) - for i := 0; i < len(thisMajorVersion); i++ { - thisToken, _ := strconv.Atoi(thisMajorVersion[i]) - otherToken, _ := strconv.Atoi(otherMajorVersion[i]) - if thisToken < otherToken { - return true - } - if thisToken > otherToken { - return false - } - } - return false -} - -// IsSmallerBinlogFormat tests two binlog formats and sees if one is "smaller" than the other. -// "smaller" binlog format means you can replicate from the smaller to the larger. -func IsSmallerBinlogFormat(binlogFormat string, otherBinlogFormat string) bool { - if binlogFormat == "STATEMENT" { - return (otherBinlogFormat == "ROW" || otherBinlogFormat == "MIXED") - } - if binlogFormat == "MIXED" { - return otherBinlogFormat == "ROW" - } - return false -} - // RegexpMatchPatterns returns true if s matches any of the provided regexpPatterns func RegexpMatchPatterns(s string, regexpPatterns []string) bool { for _, filter := range regexpPatterns { diff --git a/go/vt/vtorc/inst/oracle_gtid_set.go b/go/vt/vtorc/inst/oracle_gtid_set.go index c4e88fccbd3..0ddab05ef55 100644 --- a/go/vt/vtorc/inst/oracle_gtid_set.go +++ b/go/vt/vtorc/inst/oracle_gtid_set.go @@ -22,9 +22,10 @@ import ( // OracleGtidSet represents a set of GTID ranges as depicted by Retrieved_Gtid_Set, Executed_Gtid_Set or @@gtid_purged. type OracleGtidSet struct { - GtidEntries [](*OracleGtidSetEntry) + GtidEntries []*OracleGtidSetEntry } +// NewOracleGtidSet creates a new GTID set. // Example input: `230ea8ea-81e3-11e4-972a-e25ec4bd140a:1-10539, // 316d193c-70e5-11e5-adb2-ecf4bb2262ff:1-8935:8984-6124596, // 321f5c0d-70e5-11e5-adb2-ecf4bb2262ff:1-56` @@ -54,7 +55,7 @@ func NewOracleGtidSet(gtidSet string) (res *OracleGtidSet, err error) { // By way of how this works there can only be one entry matching our UUID, but we generalize. // We keep order of entries. func (oracleGTIDSet *OracleGtidSet) RemoveUUID(uuid string) (removed bool) { - filteredEntries := [](*OracleGtidSetEntry){} + var filteredEntries []*OracleGtidSetEntry for _, entry := range oracleGTIDSet.GtidEntries { if entry.UUID == uuid { removed = true @@ -79,7 +80,7 @@ func (oracleGTIDSet *OracleGtidSet) RetainUUIDs(uuids []string) (anythingRemoved for _, uuid := range uuids { retainUUIDs[uuid] = true } - filteredEntries := [](*OracleGtidSetEntry){} + var filteredEntries []*OracleGtidSetEntry for _, entry := range oracleGTIDSet.GtidEntries { if retainUUIDs[entry.UUID] { filteredEntries = append(filteredEntries, entry) @@ -107,8 +108,8 @@ func (oracleGTIDSet *OracleGtidSet) SharedUUIDs(other *OracleGtidSet) (shared [] return shared } -// String returns a user-friendly string representation of this entry -func (oracleGTIDSet *OracleGtidSet) Explode() (result [](*OracleGtidSetEntry)) { +// Explode returns a user-friendly string representation of this entry +func (oracleGTIDSet *OracleGtidSet) Explode() (result []*OracleGtidSetEntry) { for _, entries := range oracleGTIDSet.GtidEntries { result = append(result, entries.Explode()...) } @@ -116,7 +117,7 @@ func (oracleGTIDSet *OracleGtidSet) Explode() (result [](*OracleGtidSetEntry)) { } func (oracleGTIDSet *OracleGtidSet) String() string { - tokens := []string{} + var tokens []string for _, entry := range oracleGTIDSet.GtidEntries { tokens = append(tokens, entry.String()) } diff --git a/go/vt/vtorc/inst/postponed_functions.go b/go/vt/vtorc/inst/postponed_functions.go deleted file mode 100644 index 1ce750964a5..00000000000 --- a/go/vt/vtorc/inst/postponed_functions.go +++ /dev/null @@ -1,69 +0,0 @@ -/* - Copyright 2015 Shlomi Noach, courtesy Booking.com - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package inst - -import ( - "sync" - - "vitess.io/vitess/go/vt/log" -) - -type PostponedFunctionsContainer struct { - waitGroup sync.WaitGroup - mutex sync.Mutex - descriptions []string -} - -func NewPostponedFunctionsContainer() *PostponedFunctionsContainer { - postponedFunctionsContainer := &PostponedFunctionsContainer{ - descriptions: []string{}, - } - return postponedFunctionsContainer -} - -func (postponedFuncsContainer *PostponedFunctionsContainer) AddPostponedFunction(postponedFunction func() error, description string) { - postponedFuncsContainer.mutex.Lock() - defer postponedFuncsContainer.mutex.Unlock() - - postponedFuncsContainer.descriptions = append(postponedFuncsContainer.descriptions, description) - - postponedFuncsContainer.waitGroup.Add(1) - go func() { - defer postponedFuncsContainer.waitGroup.Done() - _ = postponedFunction() - }() -} - -func (postponedFuncsContainer *PostponedFunctionsContainer) Wait() { - log.Infof("PostponedFunctionsContainer: waiting on %+v postponed functions", postponedFuncsContainer.Len()) - postponedFuncsContainer.waitGroup.Wait() - log.Infof("PostponedFunctionsContainer: done waiting") -} - -func (postponedFuncsContainer *PostponedFunctionsContainer) Len() int { - postponedFuncsContainer.mutex.Lock() - defer postponedFuncsContainer.mutex.Unlock() - - return len(postponedFuncsContainer.descriptions) -} - -func (postponedFuncsContainer *PostponedFunctionsContainer) Descriptions() []string { - postponedFuncsContainer.mutex.Lock() - defer postponedFuncsContainer.mutex.Unlock() - - return postponedFuncsContainer.descriptions -} diff --git a/go/vt/vtorc/inst/process.go b/go/vt/vtorc/inst/process.go deleted file mode 100644 index 99985045b56..00000000000 --- a/go/vt/vtorc/inst/process.go +++ /dev/null @@ -1,32 +0,0 @@ -/* - Copyright 2014 Outbrain Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package inst - -// Process presents a MySQL executing thread (as observed by PROCESSLIST) -type Process struct { - InstanceHostname string - InstancePort int - ID int64 - User string - Host string - Db string - Command string - Time int64 - State string - Info string - StartedAt string -} diff --git a/go/vt/vtorc/inst/replication_thread_state.go b/go/vt/vtorc/inst/replication_thread_state.go index e885625aa3f..85b968ac7bc 100644 --- a/go/vt/vtorc/inst/replication_thread_state.go +++ b/go/vt/vtorc/inst/replication_thread_state.go @@ -27,16 +27,6 @@ const ( ReplicationThreadStateOther ReplicationThreadState = 2 ) -func ReplicationThreadStateFromStatus(status string) ReplicationThreadState { - switch status { - case "No": - return ReplicationThreadStateStopped - case "Yes": - return ReplicationThreadStateRunning - } - return ReplicationThreadStateOther -} - // ReplicationThreadStateFromReplicationState gets the replication thread state from replication state // TODO: Merge these two into one func ReplicationThreadStateFromReplicationState(state mysql.ReplicationState) ReplicationThreadState { diff --git a/go/vt/vtorc/logic/topology_recovery.go b/go/vt/vtorc/logic/topology_recovery.go index 7be452ec336..929ee10c6ad 100644 --- a/go/vt/vtorc/logic/topology_recovery.go +++ b/go/vt/vtorc/logic/topology_recovery.go @@ -21,7 +21,6 @@ import ( "encoding/json" "fmt" "math/rand" - "strings" "time" "github.com/patrickmn/go-cache" @@ -89,8 +88,6 @@ const ( // TopologyRecovery represents an entry in the topology_recovery table type TopologyRecovery struct { - inst.PostponedFunctionsContainer - ID int64 UID string AnalysisEntry inst.ReplicationAnalysis @@ -111,7 +108,6 @@ type TopologyRecovery struct { LastDetectionID int64 RelatedRecoveryID int64 Type RecoveryType - RecoveryType PrimaryRecoveryType } func NewTopologyRecovery(replicationAnalysis inst.ReplicationAnalysis) *TopologyRecovery { @@ -119,7 +115,6 @@ func NewTopologyRecovery(replicationAnalysis inst.ReplicationAnalysis) *Topology topologyRecovery.UID = util.PrettyUniqueToken() topologyRecovery.AnalysisEntry = replicationAnalysis topologyRecovery.AllErrors = []string{} - topologyRecovery.RecoveryType = NotPrimaryRecovery return topologyRecovery } @@ -150,15 +145,6 @@ func NewTopologyRecoveryStep(uid string, message string) *TopologyRecoveryStep { } } -type PrimaryRecoveryType string - -const ( - NotPrimaryRecovery PrimaryRecoveryType = "NotPrimaryRecovery" - PrimaryRecoveryGTID PrimaryRecoveryType = "PrimaryRecoveryGTID" - PrimaryRecoveryBinlogServer PrimaryRecoveryType = "PrimaryRecoveryBinlogServer" - PrimaryRecoveryUnknown PrimaryRecoveryType = "PrimaryRecoveryUnknown" -) - var emergencyReadTopologyInstanceMap *cache.Cache var emergencyRestartReplicaTopologyInstanceMap *cache.Cache var emergencyOperationGracefulPeriodMap *cache.Cache @@ -692,12 +678,6 @@ func executeCheckAndRecoverFunction(analysisEntry *inst.ReplicationAnalysis) (er // that we just completed because we would be using stale data. DiscoverInstance(analysisEntry.AnalyzedInstanceAlias, true) } - _ = AuditTopologyRecovery(topologyRecovery, fmt.Sprintf("Waiting for %d postponed functions", topologyRecovery.PostponedFunctionsContainer.Len())) - topologyRecovery.Wait() - _ = AuditTopologyRecovery(topologyRecovery, fmt.Sprintf("Executed %d postponed functions", topologyRecovery.PostponedFunctionsContainer.Len())) - if topologyRecovery.PostponedFunctionsContainer.Len() > 0 { - _ = AuditTopologyRecovery(topologyRecovery, fmt.Sprintf("Executed postponed functions: %+v", strings.Join(topologyRecovery.PostponedFunctionsContainer.Descriptions(), ", "))) - } return err } diff --git a/go/vt/vtorc/logic/topology_recovery_dao.go b/go/vt/vtorc/logic/topology_recovery_dao.go index 20e23975499..c835b9ecfe4 100644 --- a/go/vt/vtorc/logic/topology_recovery_dao.go +++ b/go/vt/vtorc/logic/topology_recovery_dao.go @@ -514,7 +514,7 @@ func ReadInActivePeriodSuccessorInstanceRecovery(tabletAlias string) ([]*Topolog func ReadRecentRecoveries(unacknowledgedOnly bool, page int) ([]*TopologyRecovery, error) { whereConditions := []string{} whereClause := "" - args := sqlutils.Args() + var args []any if unacknowledgedOnly { whereConditions = append(whereConditions, `acknowledged=0`) } diff --git a/go/vt/vtorc/util/math.go b/go/vt/vtorc/util/math.go index 869b7ac354d..7f1e3057b07 100644 --- a/go/vt/vtorc/util/math.go +++ b/go/vt/vtorc/util/math.go @@ -16,64 +16,6 @@ package util -func MinInt(i1, i2 int) int { - if i1 < i2 { - return i1 - } - return i2 -} - -func MaxInt(i1, i2 int) int { - if i1 > i2 { - return i1 - } - return i2 -} - -func MinInt64(i1, i2 int64) int64 { - if i1 < i2 { - return i1 - } - return i2 -} - -func MaxInt64(i1, i2 int64) int64 { - if i1 > i2 { - return i1 - } - return i2 -} - -func MaxUInt64(i1, i2 uint64) uint64 { - if i1 > i2 { - return i1 - } - return i2 -} - -func MinString(i1, i2 string) string { - if i1 < i2 { - return i1 - } - return i2 -} - -// TernaryString acts like a "? :" C-style ternary operator for strings -func TernaryString(condition bool, resTrue string, resFalse string) string { - if condition { - return resTrue - } - return resFalse -} - -// TernaryInt acts like a "? :" C-style ternary operator for ints -func TernaryInt(condition bool, resTrue int, resFalse int) int { - if condition { - return resTrue - } - return resFalse -} - // AbsInt64 is an ABS function for int64 type func AbsInt64(i int64) int64 { if i >= 0 {