diff --git a/go/vt/vttablet/tabletmanager/vdiff/action.go b/go/vt/vttablet/tabletmanager/vdiff/action.go index 2966f2be0b6..a66a2e0be99 100644 --- a/go/vt/vttablet/tabletmanager/vdiff/action.go +++ b/go/vt/vttablet/tabletmanager/vdiff/action.go @@ -22,6 +22,7 @@ import ( "fmt" "github.com/google/uuid" + "google.golang.org/protobuf/encoding/protojson" "vitess.io/vitess/go/vt/topo/topoproto" "vitess.io/vitess/go/vt/vterrors" @@ -49,6 +50,12 @@ const ( var ( Actions = []VDiffAction{CreateAction, ShowAction, StopAction, ResumeAction, DeleteAction} ActionArgs = []string{AllActionArg, LastActionArg} + + optionsZeroVal = &tabletmanagerdatapb.VDiffOptions{ + PickerOptions: &tabletmanagerdatapb.VDiffPickerOptions{}, + CoreOptions: &tabletmanagerdatapb.VDiffCoreOptions{}, + ReportOptions: &tabletmanagerdatapb.VDiffReportOptions{}, + } ) func (vde *Engine) PerformVDiffAction(ctx context.Context, req *tabletmanagerdatapb.VDiffRequest) (*tabletmanagerdatapb.VDiffResponse, error) { @@ -190,7 +197,7 @@ func (vde *Engine) handleCreateResumeAction(ctx context.Context, dbClient binlog } resp.Id = int64(qr.InsertID) } else { - query := fmt.Sprintf(sqlResumeVDiff, encodeString(string(optionsJSON)), encodeString(req.VdiffUuid)) + query := fmt.Sprintf(sqlResumeVDiff, encodeString(req.VdiffUuid)) if qr, err = dbClient.ExecuteFetch(query, 1); err != nil { return err } @@ -209,9 +216,24 @@ func (vde *Engine) handleCreateResumeAction(ctx context.Context, dbClient binlog if err != nil { return err } + + vdiffRecord := qr.Named().Row() + if vdiffRecord == nil { + return fmt.Errorf("unable to %s vdiff for UUID %s as it was not found on tablet %v (%w)", + action, req.VdiffUuid, vde.thisTablet.Alias, err) + } + if action == ResumeAction { + // Use the existing options from the vdiff record. + options = optionsZeroVal + err = protojson.Unmarshal(vdiffRecord.AsBytes("options", []byte("{}")), options) + if err != nil { + return err + } + } + vde.mu.Lock() defer vde.mu.Unlock() - if err := vde.addController(qr.Named().Row(), options); err != nil { + if err := vde.addController(vdiffRecord, options); err != nil { return err } diff --git a/go/vt/vttablet/tabletmanager/vdiff/schema.go b/go/vt/vttablet/tabletmanager/vdiff/schema.go index 17ad055f2a8..d32d7e19276 100644 --- a/go/vt/vttablet/tabletmanager/vdiff/schema.go +++ b/go/vt/vttablet/tabletmanager/vdiff/schema.go @@ -82,7 +82,7 @@ const ( primary key (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4` sqlNewVDiff = "insert into _vt.vdiff(keyspace, workflow, state, options, shard, db_name, vdiff_uuid) values(%s, %s, '%s', %s, '%s', '%s', '%s')" - sqlResumeVDiff = `update _vt.vdiff as vd, _vt.vdiff_table as vdt set vd.options = %s, vd.started_at = NULL, vd.completed_at = NULL, vd.state = 'pending', + sqlResumeVDiff = `update _vt.vdiff as vd, _vt.vdiff_table as vdt set vd.started_at = NULL, vd.completed_at = NULL, vd.state = 'pending', vdt.state = 'pending' where vd.vdiff_uuid = %s and vd.id = vdt.vdiff_id and vd.state in ('completed', 'stopped') and vdt.state in ('completed', 'stopped')` sqlRetryVDiff = `update _vt.vdiff as vd left join _vt.vdiff_table as vdt on (vd.id = vdt.vdiff_id) set vd.state = 'pending',