Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Commit

Permalink
Post successful failover: immediate update of cluster_name
Browse files Browse the repository at this point in the history
  • Loading branch information
Shlomi Noach committed Jun 24, 2019
1 parent 19c0209 commit 9667e1d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
28 changes: 28 additions & 0 deletions go/inst/instance_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -1718,6 +1718,34 @@ func updateInstanceClusterName(instance *Instance) error {
return ExecDBWriteFunc(writeFunc)
}

// ReplaceClusterName replaces all occurances of oldClusterName with newClusterName
// It is called after a master failover
func ReplaceClusterName(oldClusterName string, newClusterName string) error {
if oldClusterName == "" {
return log.Errorf("replaceClusterName: skipping empty oldClusterName")
}
if newClusterName == "" {
return log.Errorf("replaceClusterName: skipping empty newClusterName")
}
writeFunc := func() error {
_, err := db.ExecOrchestrator(`
update
database_instance
set
cluster_name=?
where
and cluster_name=?
`, newClusterName, oldClusterName,
)
if err != nil {
return log.Errore(err)
}
AuditOperation("replace-cluster-name", nil, fmt.Sprintf("replaxced %s with %s", oldClusterName, newClusterName))
return nil
}
return ExecDBWriteFunc(writeFunc)
}

// ReviewUnseenInstances reviews instances that have not been seen (suposedly dead) and updates some of their data
func ReviewUnseenInstances() error {
instances, err := ReadUnseenInstances()
Expand Down
1 change: 1 addition & 0 deletions go/logic/topology_recovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,7 @@ func checkAndRecoverDeadMaster(analysisEntry inst.ReplicationAnalysis, candidate
func() error {
before := analysisEntry.AnalyzedInstanceKey.StringCode()
after := promotedReplica.Key.StringCode()
inst.ReplaceClusterName(before, after)
AuditTopologyRecovery(topologyRecovery, fmt.Sprintf("- RecoverDeadMaster: updating cluster_alias: %v -> %v", before, after))
if alias := analysisEntry.ClusterDetails.ClusterAlias; alias != "" {
inst.SetClusterAlias(promotedReplica.Key.StringCode(), alias)
Expand Down

0 comments on commit 9667e1d

Please sign in to comment.