Skip to content

Commit a06904e

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

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

go/test/endtoend/preparestmt/stmt_methods_test.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/stretchr/testify/assert"
2929
"github.com/stretchr/testify/require"
3030

31+
"vitess.io/vitess/go/test/endtoend/cluster"
3132
"vitess.io/vitess/go/vt/vtgate/engine"
3233
)
3334

@@ -564,13 +565,25 @@ func validateJoinSpecializedPlan(t *testing.T, p map[string]any) {
564565

565566
func validateBaselineErrSpecializedPlan(t *testing.T, p map[string]any) {
566567
t.Helper()
568+
569+
vtgateVer, err := cluster.GetMajorVersion("vtgate")
570+
require.NoError(t, err)
571+
572+
// v24+ uses the following error message due to the work in:
573+
// https://github.com/vitessio/vitess/pull/18903
574+
expectedErr := "VT12001: unsupported: window functions are only supported for single-shard queries"
575+
if vtgateVer < 24 {
576+
// v23 and earlier uses the old error which reflected the limitation before that work.
577+
expectedErr = "VT12001: unsupported: OVER CLAUSE with sharded keyspace"
578+
}
579+
567580
plan, exist := p["Instructions"]
568581
require.True(t, exist, "plan Instructions not found")
569582

570583
pm, ok := plan.(map[string]any)
571584
require.True(t, ok, "plan is not of type map[string]any")
572585
require.EqualValues(t, "PlanSwitcher", pm["OperatorType"])
573-
require.EqualValues(t, "VT12001: unsupported: OVER CLAUSE with sharded keyspace", pm["BaselineErr"])
586+
require.EqualValues(t, expectedErr, pm["BaselineErr"])
574587

575588
pd, err := engine.PrimitiveDescriptionFromMap(plan.(map[string]any))
576589
require.NoError(t, err)

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)