From 345115e9597558dbd4e4079992a0e6e7e2a5214e Mon Sep 17 00:00:00 2001 From: Matt Lord Date: Wed, 25 Sep 2024 19:41:50 -0400 Subject: [PATCH] Remove existing data check related code And defer that work to https://github.com/vitessio/vitess/pull/16826 Signed-off-by: Matt Lord --- go/vt/vtctl/workflow/materializer.go | 15 +++------ go/vt/vtctl/workflow/materializer_test.go | 40 ----------------------- 2 files changed, 4 insertions(+), 51 deletions(-) diff --git a/go/vt/vtctl/workflow/materializer.go b/go/vt/vtctl/workflow/materializer.go index 4c51f9f74a2..9b8251257a8 100644 --- a/go/vt/vtctl/workflow/materializer.go +++ b/go/vt/vtctl/workflow/materializer.go @@ -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 ( @@ -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) @@ -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 == "" { diff --git a/go/vt/vtctl/workflow/materializer_test.go b/go/vt/vtctl/workflow/materializer_test.go index 30c8c24c987..8d3335041a3 100644 --- a/go/vt/vtctl/workflow/materializer_test.go +++ b/go/vt/vtctl/workflow/materializer_test.go @@ -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) {