Skip to content

Commit 79ea2e6

Browse files
[release-22.0] VDiff: Handle the case where a workflow's table has been dropped on the source (#18985) (#18988)
Signed-off-by: Matt Lord <[email protected]> Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>
1 parent 4b4ff40 commit 79ea2e6

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

go/vt/vttablet/tabletmanager/vdiff/table_differ.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,13 @@ func (td *tableDiffer) getSourcePKCols() error {
944944
return vterrors.Wrapf(err, "failed to get the schema for table %s from source tablet %s",
945945
td.table.Name, topoproto.TabletAliasString(sourceTablet.Tablet.Alias))
946946
}
947+
if len(sourceSchema.TableDefinitions) == 0 {
948+
// The table no longer exists on the source. Any rows that exist on the target will be
949+
// reported as extra rows.
950+
log.Warningf("The %s table was not found on source tablet %s during VDiff for the %s workflow; any rows on the target will be reported as extra",
951+
td.table.Name, topoproto.TabletAliasString(sourceTablet.Tablet.Alias), td.wd.ct.workflow)
952+
return nil
953+
}
947954
sourceTable := sourceSchema.TableDefinitions[0]
948955
if len(sourceTable.PrimaryKeyColumns) == 0 {
949956
// We use the columns from a PKE if there is one.

go/vt/vttablet/tabletmanager/vdiff/table_differ_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,35 @@ func TestUpdateTableProgress(t *testing.T) {
129129
})
130130
}
131131
}
132+
133+
func TestGetSourcePKCols_TableDroppedOnSource(t *testing.T) {
134+
tvde := newTestVDiffEnv(t)
135+
defer tvde.close()
136+
137+
ct := tvde.createController(t, 1)
138+
139+
table := &tabletmanagerdatapb.TableDefinition{
140+
Name: "dropped_table",
141+
Columns: []string{"c1", "c2"},
142+
PrimaryKeyColumns: []string{"c1"},
143+
Fields: sqltypes.MakeTestFields("c1|c2", "int64|varchar"),
144+
}
145+
146+
tvde.tmc.schema = &tabletmanagerdatapb.SchemaDefinition{
147+
TableDefinitions: []*tabletmanagerdatapb.TableDefinition{},
148+
}
149+
150+
td := &tableDiffer{
151+
wd: &workflowDiffer{
152+
ct: ct,
153+
},
154+
table: table,
155+
tablePlan: &tablePlan{
156+
table: table,
157+
},
158+
}
159+
160+
err := td.getSourcePKCols()
161+
require.NoError(t, err)
162+
require.Nil(t, td.tablePlan.sourcePkCols)
163+
}

0 commit comments

Comments
 (0)