Skip to content

Commit

Permalink
remove duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
tanjinx committed Jun 25, 2024
1 parent 3ac6b17 commit 4cd293b
Showing 1 changed file with 11 additions and 29 deletions.
40 changes: 11 additions & 29 deletions go/vt/vttablet/tabletmanager/rpc_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,17 @@ func (tm *TabletManager) Backup(ctx context.Context, logger logutil.Logger, req
if err := tm.changeTypeLocked(bgCtx, originalType, DBActionNone, SemiSyncActionNone); err != nil {
l.Errorf("Failed to change tablet type from %v to %v, error: %v", topodatapb.TabletType_BACKUP, originalType, err)
return
} else {
// Tell Orchestrator we're no longer stopped on purpose.
// Do this in the background, as it's best-effort.
go func() {
if tm.orc == nil {
return
}
if err := tm.orc.EndMaintenance(tm.Tablet()); err != nil {
logger.Warningf("Orchestrator EndMaintenance failed: %v", err)
}
}()
}

// Find the correct primary tablet and set the replication source,
Expand Down Expand Up @@ -174,35 +185,6 @@ func (tm *TabletManager) Backup(ctx context.Context, logger logutil.Logger, req

returnErr := mysqlctl.Backup(ctx, backupParams)

if engine.ShouldDrainForBackup() {
bgCtx := context.Background()
// Starting from here we won't be able to recover if we get stopped by a cancelled
// context. It is also possible that the context already timed out during the
// above call to Backup. Thus we use the background context to get through to the finish.

// Change our type back to the original value.
// Original type could be primary so pass in a real value for PrimaryTermStartTime
if err := tm.changeTypeLocked(bgCtx, originalType, DBActionNone, SemiSyncActionNone); err != nil {
// failure in changing the topology type is probably worse,
// so returning that (we logged the snapshot error anyway)
if returnErr != nil {
l.Errorf("mysql backup command returned error: %v", returnErr)
}
returnErr = err
} else {
// Tell Orchestrator we're no longer stopped on purpose.
// Do this in the background, as it's best-effort.
go func() {
if tm.orc == nil {
return
}
if err := tm.orc.EndMaintenance(tm.Tablet()); err != nil {
logger.Warningf("Orchestrator EndMaintenance failed: %v", err)
}
}()
}
}

return returnErr
}

Expand Down

0 comments on commit 4cd293b

Please sign in to comment.