@@ -754,7 +754,7 @@ func (ts *trafficSwitcher) changeShardsAccess(ctx context.Context, keyspace stri
754
754
755
755
func (ts * trafficSwitcher ) allowTargetWrites (ctx context.Context ) error {
756
756
if ts .MigrationType () == binlogdatapb .MigrationType_TABLES {
757
- return ts .switchDeniedTables (ctx )
757
+ return ts .switchDeniedTables (ctx , false )
758
758
}
759
759
return ts .changeShardsAccess (ctx , ts .TargetKeyspaceName (), ts .TargetShards (), allowWrites )
760
760
}
@@ -1062,7 +1062,7 @@ func (ts *trafficSwitcher) waitForCatchup(ctx context.Context, filteredReplicati
1062
1062
func (ts * trafficSwitcher ) stopSourceWrites (ctx context.Context ) error {
1063
1063
var err error
1064
1064
if ts .MigrationType () == binlogdatapb .MigrationType_TABLES {
1065
- err = ts .switchDeniedTables (ctx )
1065
+ err = ts .switchDeniedTables (ctx , false )
1066
1066
} else {
1067
1067
err = ts .changeShardsAccess (ctx , ts .SourceKeyspaceName (), ts .SourceShards (), disallowWrites )
1068
1068
}
@@ -1075,16 +1075,25 @@ func (ts *trafficSwitcher) stopSourceWrites(ctx context.Context) error {
1075
1075
1076
1076
// switchDeniedTables switches the denied tables rules for the traffic switch.
1077
1077
// They are removed on the source side and added on the target side.
1078
- func (ts * trafficSwitcher ) switchDeniedTables (ctx context.Context ) error {
1078
+ // If backward is true, then we swap this logic, removing on the target side
1079
+ // and adding on the source side. You would want to do that e.g. when canceling
1080
+ // a failed (and currently partial) traffic switch as the source and target
1081
+ // have already been switched in the trafficSwitcher.
1082
+ func (ts * trafficSwitcher ) switchDeniedTables (ctx context.Context , backward bool ) error {
1079
1083
if ts .MigrationType () != binlogdatapb .MigrationType_TABLES {
1080
1084
return nil
1081
1085
}
1082
1086
1087
+ rmsource , rmtarget := false , true
1088
+ if backward {
1089
+ rmsource , rmtarget = true , false
1090
+ }
1091
+
1083
1092
egrp , ectx := errgroup .WithContext (ctx )
1084
1093
egrp .Go (func () error {
1085
1094
return ts .ForAllSources (func (source * MigrationSource ) error {
1086
1095
if _ , err := ts .TopoServer ().UpdateShardFields (ctx , ts .SourceKeyspaceName (), source .GetShard ().ShardName (), func (si * topo.ShardInfo ) error {
1087
- return si .UpdateDeniedTables (ectx , topodatapb .TabletType_PRIMARY , nil , false , ts .Tables ())
1096
+ return si .UpdateDeniedTables (ectx , topodatapb .TabletType_PRIMARY , nil , rmsource , ts .Tables ())
1088
1097
}); err != nil {
1089
1098
return err
1090
1099
}
@@ -1107,7 +1116,7 @@ func (ts *trafficSwitcher) switchDeniedTables(ctx context.Context) error {
1107
1116
egrp .Go (func () error {
1108
1117
return ts .ForAllTargets (func (target * MigrationTarget ) error {
1109
1118
if _ , err := ts .TopoServer ().UpdateShardFields (ectx , ts .TargetKeyspaceName (), target .GetShard ().ShardName (), func (si * topo.ShardInfo ) error {
1110
- return si .UpdateDeniedTables (ctx , topodatapb .TabletType_PRIMARY , nil , true , ts .Tables ())
1119
+ return si .UpdateDeniedTables (ctx , topodatapb .TabletType_PRIMARY , nil , rmtarget , ts .Tables ())
1111
1120
}); err != nil {
1112
1121
return err
1113
1122
}
@@ -1153,12 +1162,12 @@ func (ts *trafficSwitcher) cancelMigration(ctx context.Context, sm *StreamMigrat
1153
1162
// canceled by the parent context.
1154
1163
wcCtx := context .WithoutCancel (ctx )
1155
1164
// Now we create a child context from that which has a timeout.
1156
- cmTimeout := 60 * time .Second
1165
+ cmTimeout := 2 * time .Minute
1157
1166
cmCtx , cmCancel := context .WithTimeout (wcCtx , cmTimeout )
1158
1167
defer cmCancel ()
1159
1168
1160
1169
if ts .MigrationType () == binlogdatapb .MigrationType_TABLES {
1161
- err = ts .switchDeniedTables (cmCtx )
1170
+ err = ts .switchDeniedTables (cmCtx , true /* revert */ )
1162
1171
} else {
1163
1172
err = ts .changeShardsAccess (cmCtx , ts .SourceKeyspaceName (), ts .SourceShards (), allowWrites )
1164
1173
}
@@ -1167,7 +1176,10 @@ func (ts *trafficSwitcher) cancelMigration(ctx context.Context, sm *StreamMigrat
1167
1176
ts .Logger ().Errorf ("Cancel migration failed: could not revert denied tables / shard access: %v" , err )
1168
1177
}
1169
1178
1170
- sm .CancelStreamMigrations (cmCtx )
1179
+ if err := sm .CancelStreamMigrations (cmCtx ); err != nil {
1180
+ cancelErrs .RecordError (fmt .Errorf ("could not cancel stream migrations: %v" , err ))
1181
+ ts .Logger ().Errorf ("Cancel migration failed: could not cancel stream migrations: %v" , err )
1182
+ }
1171
1183
1172
1184
err = ts .ForAllTargets (func (target * MigrationTarget ) error {
1173
1185
query := fmt .Sprintf ("update _vt.vreplication set state='Running', message='' where db_name=%s and workflow=%s" ,
@@ -1180,8 +1192,7 @@ func (ts *trafficSwitcher) cancelMigration(ctx context.Context, sm *StreamMigrat
1180
1192
ts .Logger ().Errorf ("Cancel migration failed: could not restart vreplication: %v" , err )
1181
1193
}
1182
1194
1183
- err = ts .deleteReverseVReplication (cmCtx )
1184
- if err != nil {
1195
+ if err := ts .deleteReverseVReplication (cmCtx ); err != nil {
1185
1196
cancelErrs .RecordError (fmt .Errorf ("could not delete reverse vreplication streams: %v" , err ))
1186
1197
ts .Logger ().Errorf ("Cancel migration failed: could not delete reverse vreplication streams: %v" , err )
1187
1198
}
0 commit comments