Skip to content

Commit

Permalink
Cherry-pick e4dc872 with conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
vitess-bot[bot] authored and vitess-bot committed Dec 10, 2024
1 parent f0d9386 commit 1ba6f35
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions go/vt/vtctl/workflow/traffic_switcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -994,30 +994,55 @@ func (ts *trafficSwitcher) changeTableSourceWrites(ctx context.Context, access a
return ts.TopoServer().RebuildSrvVSchema(ctx, nil)
}

// cancelMigration attempts to revert all changes made during the migration so that we can get back to the
// state when traffic switching (or reversing) was initiated.
func (ts *trafficSwitcher) cancelMigration(ctx context.Context, sm *StreamMigrator) {
var err error
<<<<<<< HEAD

Check failure on line 1001 in go/vt/vtctl/workflow/traffic_switcher.go

View workflow job for this annotation

GitHub Actions / Code Coverage

syntax error: unexpected <<, expected }

Check failure on line 1001 in go/vt/vtctl/workflow/traffic_switcher.go

View workflow job for this annotation

GitHub Actions / Code Coverage

syntax error: unexpected <<, expected }
if ts.MigrationType() == binlogdatapb.MigrationType_TABLES {
err = ts.changeTableSourceWrites(ctx, allowWrites)
} else {
err = ts.changeShardsAccess(ctx, ts.SourceKeyspaceName(), ts.SourceShards(), allowWrites)
}
if err != nil {
ts.Logger().Errorf("Cancel migration failed: %v", err)
=======

if ctx.Err() != nil {
// Even though we create a new context later on we still record any context error:
// for forensics in case of failures.
ts.Logger().Infof("In Cancel migration: original context invalid: %s", ctx.Err())
>>>>>>> e4dc8729ec (SwitchTraffic: use separate context while canceling a migration (#17340))

Check failure on line 1015 in go/vt/vtctl/workflow/traffic_switcher.go

View workflow job for this annotation

GitHub Actions / Code Coverage

invalid character U+0023 '#'

Check failure on line 1015 in go/vt/vtctl/workflow/traffic_switcher.go

View workflow job for this annotation

GitHub Actions / Code Coverage

invalid character U+0023 '#'
}

sm.CancelStreamMigrations(ctx)
// We create a new context while canceling the migration, so that we are independent of the original
// context being cancelled prior to or during the cancel operation.
cmTimeout := 60 * time.Second
cmCtx, cmCancel := context.WithTimeout(context.Background(), cmTimeout)
defer cmCancel()

if ts.MigrationType() == binlogdatapb.MigrationType_TABLES {
err = ts.switchDeniedTables(cmCtx)
} else {
err = ts.changeShardsAccess(cmCtx, ts.SourceKeyspaceName(), ts.SourceShards(), allowWrites)
}
if err != nil {
ts.Logger().Errorf("Cancel migration failed: could not revert denied tables / shard access: %v", err)
}

sm.CancelStreamMigrations(cmCtx)

err = ts.ForAllTargets(func(target *MigrationTarget) error {

Check failure on line 1035 in go/vt/vtctl/workflow/traffic_switcher.go

View workflow job for this annotation

GitHub Actions / Code Coverage

syntax error: unexpected {, expected (

Check failure on line 1035 in go/vt/vtctl/workflow/traffic_switcher.go

View workflow job for this annotation

GitHub Actions / Code Coverage

syntax error: unexpected {, expected (
query := fmt.Sprintf("update _vt.vreplication set state='Running', message='' where db_name=%s and workflow=%s",

Check failure on line 1036 in go/vt/vtctl/workflow/traffic_switcher.go

View workflow job for this annotation

GitHub Actions / Code Coverage

syntax error: unexpected := in parameter list; possibly missing comma or )

Check failure on line 1036 in go/vt/vtctl/workflow/traffic_switcher.go

View workflow job for this annotation

GitHub Actions / Code Coverage

syntax error: unexpected := in parameter list; possibly missing comma or )
encodeString(target.GetPrimary().DbName()), encodeString(ts.WorkflowName()))

Check failure on line 1037 in go/vt/vtctl/workflow/traffic_switcher.go

View workflow job for this annotation

GitHub Actions / Code Coverage

syntax error: unexpected . after top level declaration

Check failure on line 1037 in go/vt/vtctl/workflow/traffic_switcher.go

View workflow job for this annotation

GitHub Actions / Code Coverage

syntax error: unexpected . after top level declaration
_, err := ts.TabletManagerClient().VReplicationExec(ctx, target.GetPrimary().Tablet, query)
_, err := ts.TabletManagerClient().VReplicationExec(cmCtx, target.GetPrimary().Tablet, query)
return err
})
if err != nil {
ts.Logger().Errorf("Cancel migration failed: could not restart vreplication: %v", err)
}

err = ts.deleteReverseVReplication(ctx)
err = ts.deleteReverseVReplication(cmCtx)
if err != nil {
ts.Logger().Errorf("Cancel migration failed: could not delete revers vreplication entries: %v", err)
}
Expand Down

0 comments on commit 1ba6f35

Please sign in to comment.