Skip to content

Commit

Permalink
Remove existing data check related code
Browse files Browse the repository at this point in the history
And defer that work to #16826

Signed-off-by: Matt Lord <[email protected]>
  • Loading branch information
mattlord committed Sep 25, 2024
1 parent 2b0d2f3 commit 345115e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 51 deletions.
15 changes: 4 additions & 11 deletions go/vt/vtctl/workflow/materializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import (
tabletmanagerdatapb "vitess.io/vitess/go/vt/proto/tabletmanagerdata"
vschemapb "vitess.io/vitess/go/vt/proto/vschema"
vtctldatapb "vitess.io/vitess/go/vt/proto/vtctldata"
vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc"
)

const (
Expand Down Expand Up @@ -284,15 +283,15 @@ func (mz *materializer) deploySchema() error {
return forAllShards(mz.targetShards, func(target *topo.ShardInfo) error {
allTables := []string{"/.*/"}

hasTargetTable := map[string]bool{}
req := &tabletmanagerdatapb.GetSchemaRequest{Tables: allTables}
targetSchema, err := schematools.GetSchema(mz.ctx, mz.ts, mz.tmc, target.PrimaryAlias, req)
if err != nil {
return err
}

hasTargetTable := make(map[string]*tabletmanagerdatapb.TableDefinition, len(targetSchema.TableDefinitions))
for _, td := range targetSchema.TableDefinitions {
hasTargetTable[td.Name] = td
hasTargetTable[td.Name] = true
}

targetTablet, err := mz.ts.GetTablet(mz.ctx, target.PrimaryAlias)
Expand All @@ -302,14 +301,8 @@ func (mz *materializer) deploySchema() error {

var applyDDLs []string
for _, ts := range mz.ms.TableSettings {
if td := hasTargetTable[ts.TargetTable]; td != nil {
// Table already exists. Let's be sure that it doesn't already have data.
// We exclude multi-tenant migrations from this check as the target tables
// are expected to frequently have data from previously migrated tenants.
if !mz.IsMultiTenantMigration() && td.RowCount > 0 {
return vterrors.Errorf(vtrpcpb.Code_FAILED_PRECONDITION,
"target table %s exists in the %s keyspace and is not empty", td.Name, target.Keyspace())
}
if hasTargetTable[ts.TargetTable] {
// Table already exists.
continue
}
if ts.CreateDdl == "" {
Expand Down
40 changes: 0 additions & 40 deletions go/vt/vtctl/workflow/materializer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2469,46 +2469,6 @@ func TestCreateLookupVindexFailures(t *testing.T) {
},
err: "we gots us an error",
},
{
description: "table exists and has data",
input: &vschemapb.Keyspace{
Vindexes: map[string]*vschemapb.Vindex{
"v2": {
Type: "consistent_lookup_unique",
Params: map[string]string{
"table": fmt.Sprintf("%s.t1_lkp", ms.TargetKeyspace),
"from": "c1",
"to": "keyspace_id",
},
},
},
Tables: map[string]*vschemapb.Table{
"t2": {
ColumnVindexes: []*vschemapb.ColumnVindex{{
Name: "v2",
Column: "c2",
}},
},
},
},
schemaAdditions: []*tabletmanagerdatapb.TableDefinition{{
Name: "t1_lkp",
Schema: "CREATE TABLE `t1_lkp` (\n`c1` INT,\n `keyspace_id` varbinary(128),\n PRIMARY KEY (`c1`)\n)",
Columns: []string{"c1", "keyspace_id"},
Fields: []*querypb.Field{
{
Name: "c1",
Type: sqltypes.Int32,
},
{
Name: "keyspace_id",
Type: sqltypes.VarBinary,
},
},
RowCount: 1,
}},
err: fmt.Sprintf("target table t1_lkp exists in the %s keyspace and is not empty", ms.TargetKeyspace),
},
}
for _, tcase := range testcases {
t.Run(tcase.description, func(t *testing.T) {
Expand Down

0 comments on commit 345115e

Please sign in to comment.