Skip to content

Commit

Permalink
feat: nil-check errors before printing them (vitessio#11156) (vitessi…
Browse files Browse the repository at this point in the history
…o#1026)

Signed-off-by: Manan Gupta <manan@planetscale.com>

Signed-off-by: Manan Gupta <manan@planetscale.com>

Signed-off-by: Manan Gupta <manan@planetscale.com>
  • Loading branch information
GuptaManan100 authored Sep 1, 2022
1 parent fb39c9c commit 37f18dd
Show file tree
Hide file tree
Showing 17 changed files with 170 additions and 57 deletions.
16 changes: 12 additions & 4 deletions go/vt/orchestrator/app/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ func Cli(command string, strict bool, instance string, destination string, owner
log.Fatal(err)
} else {
for _, e := range errs {
log.Error(e)
if e != nil {
log.Error(e)
}
}
for _, replica := range replicas {
fmt.Println(replica.Key.DisplayString())
Expand Down Expand Up @@ -250,7 +252,9 @@ func Cli(command string, strict bool, instance string, destination string, owner
log.Fatal(err)
} else {
for _, e := range errs {
log.Error(e)
if e != nil {
log.Error(e)
}
}
for _, replica := range movedReplicas {
fmt.Println(replica.Key.DisplayString())
Expand Down Expand Up @@ -287,7 +291,9 @@ func Cli(command string, strict bool, instance string, destination string, owner
log.Fatal(err)
} else {
for _, e := range errs {
log.Error(e)
if e != nil {
log.Error(e)
}
}
for _, replica := range repointedReplicas {
fmt.Printf("%s<%s\n", replica.Key.DisplayString(), instanceKey.DisplayString())
Expand Down Expand Up @@ -370,7 +376,9 @@ func Cli(command string, strict bool, instance string, destination string, owner
log.Fatal(err)
} else {
for _, e := range errs {
log.Error(e)
if e != nil {
log.Error(e)
}
}
for _, replica := range movedReplicas {
fmt.Println(replica.Key.DisplayString())
Expand Down
7 changes: 5 additions & 2 deletions go/vt/orchestrator/inst/analysis_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -773,8 +773,9 @@ func auditInstanceAnalysisInChangelog(instanceKey *InstanceKey, analysisCode Ana
)
if err == nil {
analysisChangeWriteCounter.Inc(1)
} else {
log.Error(err)
}
log.Error(err)
return err
}

Expand All @@ -788,7 +789,9 @@ func ExpireInstanceAnalysisChangelog() error {
`,
config.Config.UnseenInstanceForgetHours,
)
log.Error(err)
if err != nil {
log.Error(err)
}
return err
}

Expand Down
8 changes: 6 additions & 2 deletions go/vt/orchestrator/inst/candidate_database_instance_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ func RegisterCandidateInstance(candidate *CandidateDatabaseInstance) error {
`
writeFunc := func() error {
_, err := db.ExecOrchestrator(query, args...)
log.Error(err)
if err != nil {
log.Error(err)
}
return err
}
return ExecDBWriteFunc(writeFunc)
Expand All @@ -60,7 +62,9 @@ func ExpireCandidateInstances() error {
where last_suggested < NOW() - INTERVAL ? MINUTE
`, config.Config.CandidateInstanceExpireMinutes,
)
log.Error(err)
if err != nil {
log.Error(err)
}
return err
}
return ExecDBWriteFunc(writeFunc)
Expand Down
24 changes: 18 additions & 6 deletions go/vt/orchestrator/inst/cluster_alias_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ func writeClusterAlias(clusterName string, alias string) error {
(?, ?, now())
`,
clusterName, alias)
log.Error(err)
if err != nil {
log.Error(err)
}
return err
}
return ExecDBWriteFunc(writeFunc)
Expand All @@ -106,7 +108,9 @@ func writeClusterAliasManualOverride(clusterName string, alias string) error {
(?, ?)
`,
clusterName, alias)
log.Error(err)
if err != nil {
log.Error(err)
}
return err
}
return ExecDBWriteFunc(writeFunc)
Expand Down Expand Up @@ -139,7 +143,9 @@ func UpdateClusterAliases() error {
read_only desc,
num_replica_hosts asc
`, DowntimeLostInRecoveryMessage)
log.Error(err)
if err != nil {
log.Error(err)
}
return err
}
if err := ExecDBWriteFunc(writeFunc); err != nil {
Expand All @@ -159,7 +165,9 @@ func UpdateClusterAliases() error {
having
sum(suggested_cluster_alias = '') = count(*)
`)
log.Error(err)
if err != nil {
log.Error(err)
}
return err
}
if err := ExecDBWriteFunc(writeFunc); err != nil {
Expand All @@ -179,7 +187,9 @@ func ReplaceAliasClusterName(oldClusterName string, newClusterName string) (err
where cluster_name = ?
`,
newClusterName, oldClusterName)
log.Error(err)
if err != nil {
log.Error(err)
}
return err
}
err = ExecDBWriteFunc(writeFunc)
Expand All @@ -192,7 +202,9 @@ func ReplaceAliasClusterName(oldClusterName string, newClusterName string) (err
where cluster_name = ?
`,
newClusterName, oldClusterName)
log.Error(err)
if err != nil {
log.Error(err)
}
return err
}
if ferr := ExecDBWriteFunc(writeFunc); ferr != nil {
Expand Down
8 changes: 6 additions & 2 deletions go/vt/orchestrator/inst/cluster_domain_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ func WriteClusterDomainName(clusterName string, domainName string) error {
last_registered=values(last_registered)
`,
clusterName, domainName)
log.Error(err)
if err != nil {
log.Error(err)
}
return err
}
return ExecDBWriteFunc(writeFunc)
Expand All @@ -49,7 +51,9 @@ func ExpireClusterDomainName() error {
where last_registered < NOW() - INTERVAL ? MINUTE
`, config.Config.ExpiryHostnameResolvesMinutes,
)
log.Error(err)
if err != nil {
log.Error(err)
}
return err
}
return ExecDBWriteFunc(writeFunc)
Expand Down
24 changes: 18 additions & 6 deletions go/vt/orchestrator/inst/instance_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -1884,7 +1884,9 @@ func GetClusterName(instanceKey *InstanceKey) (clusterName string, err error) {
instanceKeyInformativeClusterName.Set(instanceKey.StringCode(), clusterName, cache.DefaultExpiration)
return nil
})
log.Error(err)
if err != nil {
log.Error(err)
}
return clusterName, err
}

Expand Down Expand Up @@ -2427,7 +2429,9 @@ func UpdateInstanceLastChecked(instanceKey *InstanceKey, partialSuccess bool) er
instanceKey.Hostname,
instanceKey.Port,
)
log.Error(err)
if err != nil {
log.Error(err)
}
return err
}
return ExecDBWriteFunc(writeFunc)
Expand All @@ -2454,7 +2458,9 @@ func UpdateInstanceLastAttemptedCheck(instanceKey *InstanceKey) error {
instanceKey.Hostname,
instanceKey.Port,
)
log.Error(err)
if err != nil {
log.Error(err)
}
return err
}
return ExecDBWriteFunc(writeFunc)
Expand Down Expand Up @@ -2635,7 +2641,9 @@ func RecordStaleInstanceBinlogCoordinates(instanceKey *InstanceKey, binlogCoordi
?, ?, ?, ?, NOW()
)`,
args...)
log.Error(err)
if err != nil {
log.Error(err)
}
return err
}

Expand All @@ -2650,7 +2658,9 @@ func ExpireStaleInstanceBinlogCoordinates() error {
where first_seen < NOW() - INTERVAL ? SECOND
`, expireSeconds,
)
log.Error(err)
if err != nil {
log.Error(err)
}
return err
}
return ExecDBWriteFunc(writeFunc)
Expand All @@ -2668,7 +2678,9 @@ func ResetInstanceRelaylogCoordinatesHistory(instanceKey *InstanceKey) error {
hostname=? and port=?
`, instanceKey.Hostname, instanceKey.Port,
)
log.Error(err)
if err != nil {
log.Error(err)
}
return err
}
return ExecDBWriteFunc(writeFunc)
Expand Down
4 changes: 3 additions & 1 deletion go/vt/orchestrator/inst/instance_topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -1831,7 +1831,9 @@ func RegroupReplicasGTID(

movedReplicas, unmovedReplicas, _, err = MoveReplicasViaGTID(replicasToMove, candidateReplica, postponedFunctionsContainer)
unmovedReplicas = append(unmovedReplicas, aheadReplicas...)
log.Error(err)
if err != nil {
log.Error(err)
}
return err
}
if postponedFunctionsContainer != nil && postponeAllMatchOperations != nil && postponeAllMatchOperations(candidateReplica, hasBestPromotionRule) {
Expand Down
4 changes: 3 additions & 1 deletion go/vt/orchestrator/inst/instance_topology_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,9 @@ func RestartReplication(instanceKey *InstanceKey) (instance *Instance, err error
return instance, err
}
instance, err = StartReplication(instanceKey)
log.Error(err)
if err != nil {
log.Error(err)
}
return instance, err
}

Expand Down
8 changes: 6 additions & 2 deletions go/vt/orchestrator/inst/maintenance_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ func InMaintenance(instanceKey *InstanceKey) (inMaintenance bool, err error) {
return nil
})

log.Error(err)
if err != nil {
log.Error(err)
}
return inMaintenance, err
}

Expand All @@ -189,7 +191,9 @@ func ReadMaintenanceInstanceKey(maintenanceToken int64) (*InstanceKey, error) {
return nil
})

log.Error(err)
if err != nil {
log.Error(err)
}
return res, err
}

Expand Down
4 changes: 3 additions & 1 deletion go/vt/orchestrator/inst/pool_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ func ExpirePoolInstances() error {
`,
config.Config.InstancePoolExpiryMinutes,
)
log.Error(err)
if err != nil {
log.Error(err)
}
return err
}
20 changes: 15 additions & 5 deletions go/vt/orchestrator/inst/resolve_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ func ReadAllHostnameUnresolves() ([]HostnameUnresolve, error) {
return nil
})

log.Error(err)
if err != nil {
log.Error(err)
}
return unres, err
}

Expand Down Expand Up @@ -213,7 +215,9 @@ func DeleteHostnameUnresolve(instanceKey *InstanceKey) error {
where hostname=?
`, instanceKey.Hostname,
)
log.Error(err)
if err != nil {
log.Error(err)
}
return err
}
return ExecDBWriteFunc(writeFunc)
Expand All @@ -227,7 +231,9 @@ func ExpireHostnameUnresolve() error {
where last_registered < NOW() - INTERVAL ? MINUTE
`, config.Config.ExpiryHostnameResolvesMinutes,
)
log.Error(err)
if err != nil {
log.Error(err)
}
return err
}
return ExecDBWriteFunc(writeFunc)
Expand Down Expand Up @@ -277,7 +283,9 @@ func DeleteInvalidHostnameResolves() error {
hostname = ?`,
invalidHostname,
)
log.Error(err)
if err != nil {
log.Error(err)
}
}
return err
}
Expand Down Expand Up @@ -308,7 +316,9 @@ func writeHostnameIPs(hostname string, ipv4String string, ipv6String string) err
ipv4String,
ipv6String,
)
log.Error(err)
if err != nil {
log.Error(err)
}
return err
}
return ExecDBWriteFunc(writeFunc)
Expand Down
12 changes: 9 additions & 3 deletions go/vt/orchestrator/inst/tag_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ func ReadInstanceTag(instanceKey *InstanceKey, tag *Tag) (tagExists bool, err er
return nil
})

log.Error(err)
if err != nil {
log.Error(err)
}
return tagExists, err
}

Expand All @@ -151,7 +153,9 @@ func ReadInstanceTags(instanceKey *InstanceKey) (tags [](*Tag), err error) {
return nil
})

log.Error(err)
if err != nil {
log.Error(err)
}
return tags, err
}

Expand Down Expand Up @@ -196,6 +200,8 @@ func GetInstanceKeysByTag(tag *Tag) (tagged *InstanceKeyMap, err error) {
tagged.AddKey(*key)
return nil
})
log.Error(err)
if err != nil {
log.Error(err)
}
return tagged, err
}
Loading

0 comments on commit 37f18dd

Please sign in to comment.