Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions go/vt/vttablet/tabletmanager/rpc_replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,17 @@ func (agent *ActionAgent) DemoteMaster(ctx context.Context) (string, error) {
}
defer agent.unlock()

// Tell Orchestrator we're stopped on purpose the demotion.
// This is a best effort task, so run it in a goroutine.
go func() {
if agent.orc == nil {
return
}
if err := agent.orc.BeginMaintenance(agent.Tablet(), "vttablet has been told to DemoteMaster"); err != nil {
log.Warningf("Orchestrator BeginMaintenance failed: %v", err)
}
}()

// Set the server read-only. Note all active connections are not
// affected.
if err := agent.MysqlDaemon.SetReadOnly(true); err != nil {
Expand Down Expand Up @@ -399,6 +410,21 @@ func (agent *ActionAgent) setMasterLocked(ctx context.Context, parentAlias *topo
return err
}

// If this tablet used to be a master, end orchestrator maintenance after we are connected to the new master.
// This is a best effort operation, so it should happen in a goroutine
if agent.Tablet().Type == topodatapb.TabletType_MASTER {
defer func() {
go func() {
if agent.orc == nil {
return
}
if err := agent.orc.EndMaintenance(agent.Tablet()); err != nil {
log.Warningf("Orchestrator EndMaintenance failed: %v", err)
}
}()
}()
}

// See if we were replicating at all, and should be replicating
wasReplicating := false
shouldbeReplicating := false
Expand Down