From f0a04ec9264a961e5d9447f9fd7df6192019b516 Mon Sep 17 00:00:00 2001 From: Noble Mittal Date: Wed, 18 Dec 2024 23:26:41 +0530 Subject: [PATCH] Rename lookup to lookupVindex for better readability Signed-off-by: Noble Mittal --- .../workflow/{lookup.go => lookup_vindex.go} | 13 ++++---- go/vt/vtctl/workflow/materializer_test.go | 30 +++++++++---------- go/vt/vtctl/workflow/server.go | 4 +-- 3 files changed, 23 insertions(+), 24 deletions(-) rename go/vt/vtctl/workflow/{lookup.go => lookup_vindex.go} (96%) diff --git a/go/vt/vtctl/workflow/lookup.go b/go/vt/vtctl/workflow/lookup_vindex.go similarity index 96% rename from go/vt/vtctl/workflow/lookup.go rename to go/vt/vtctl/workflow/lookup_vindex.go index a0d5a701302..e86fa9531de 100644 --- a/go/vt/vtctl/workflow/lookup.go +++ b/go/vt/vtctl/workflow/lookup_vindex.go @@ -42,7 +42,7 @@ import ( ) // lookup is responsible for performing actions related to lookup vindexes. -type lookup struct { +type lookupVindex struct { ts *topo.Server tmc tmclient.TabletManagerClient @@ -50,9 +50,8 @@ type lookup struct { parser *sqlparser.Parser } -// prepareCreateLookup performs the preparatory steps for creating a -// Lookup Vindex. -func (l *lookup) prepareCreateLookup(ctx context.Context, workflow, keyspace string, specs *vschemapb.Keyspace, continueAfterCopyWithOwner bool) ( +// prepareCreate performs the preparatory steps for creating a Lookup Vindex. +func (l *lookupVindex) prepareCreate(ctx context.Context, workflow, keyspace string, specs *vschemapb.Keyspace, continueAfterCopyWithOwner bool) ( ms *vtctldatapb.MaterializeSettings, sourceVSchema, targetVSchema *vschemapb.Keyspace, cancelFunc func() error, err error) { var ( // sourceVSchemaTable is the table info present in the vschema. @@ -242,7 +241,7 @@ type vindexInfo struct { } // validateAndGetVindex validates and extracts vindex configuration -func (l *lookup) validateAndGetVindex(specs *vschemapb.Keyspace) (*vschemapb.Vindex, *vindexInfo, error) { +func (l *lookupVindex) validateAndGetVindex(specs *vschemapb.Keyspace) (*vschemapb.Vindex, *vindexInfo, error) { if specs == nil { return nil, nil, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "no vindex provided") } @@ -314,7 +313,7 @@ func (l *lookup) validateAndGetVindex(specs *vschemapb.Keyspace) (*vschemapb.Vin }, nil } -func (l *lookup) getTargetAndSourceVSchema(ctx context.Context, sourceKeyspace string, targetKeyspace string) (sourceVSchema *vschemapb.Keyspace, targetVSchema *vschemapb.Keyspace, err error) { +func (l *lookupVindex) getTargetAndSourceVSchema(ctx context.Context, sourceKeyspace string, targetKeyspace string) (sourceVSchema *vschemapb.Keyspace, targetVSchema *vschemapb.Keyspace, err error) { sourceVSchema, err = l.ts.GetVSchema(ctx, sourceKeyspace) if err != nil { return nil, nil, err @@ -375,7 +374,7 @@ func getSourceTable(specs *vschemapb.Keyspace, targetTableName string, fromCols return sourceTable, sourceTableName, nil } -func (l *lookup) generateCreateDDLStatement(tableSchema *tabletmanagerdatapb.SchemaDefinition, sourceVindexColumns []string, vInfo *vindexInfo, vindex *vschemapb.Vindex) (string, error) { +func (l *lookupVindex) generateCreateDDLStatement(tableSchema *tabletmanagerdatapb.SchemaDefinition, sourceVindexColumns []string, vInfo *vindexInfo, vindex *vschemapb.Vindex) (string, error) { lines := strings.Split(tableSchema.TableDefinitions[0].Schema, "\n") if len(lines) < 3 { // Should never happen. diff --git a/go/vt/vtctl/workflow/materializer_test.go b/go/vt/vtctl/workflow/materializer_test.go index 7c71d79bb7b..2b33bfc7afe 100644 --- a/go/vt/vtctl/workflow/materializer_test.go +++ b/go/vt/vtctl/workflow/materializer_test.go @@ -1515,13 +1515,13 @@ func TestCreateLookupVindexCreateDDL(t *testing.T) { setStartingVschema() }() } - l := &lookup{ + lv := &lookupVindex{ ts: env.ws.ts, tmc: env.ws.tmc, logger: env.ws.Logger(), parser: env.ws.SQLParser(), } - outms, _, _, cancelFunc, err := l.prepareCreateLookup(ctx, "workflow", ms.SourceKeyspace, tcase.specs, false) + outms, _, _, cancelFunc, err := lv.prepareCreate(ctx, "workflow", ms.SourceKeyspace, tcase.specs, false) if tcase.err != "" { require.Error(t, err) require.Contains(t, err.Error(), tcase.err, "prepareCreateLookup(%s) err: %v, does not contain %v", tcase.description, err, tcase.err) @@ -1769,13 +1769,13 @@ func TestCreateLookupVindexSourceVSchema(t *testing.T) { t.Fatal(err) } - l := &lookup{ + lv := &lookupVindex{ ts: env.ws.ts, tmc: env.ws.tmc, logger: env.ws.Logger(), parser: env.ws.SQLParser(), } - _, got, _, _, err := l.prepareCreateLookup(ctx, "workflow", ms.SourceKeyspace, specs, false) + _, got, _, _, err := lv.prepareCreate(ctx, "workflow", ms.SourceKeyspace, specs, false) require.NoError(t, err) if !proto.Equal(got, tcase.out) { t.Errorf("%s: got:\n%v, want\n%v", tcase.description, got, tcase.out) @@ -2011,13 +2011,13 @@ func TestCreateLookupVindexTargetVSchema(t *testing.T) { t.Fatal(err) } - l := &lookup{ + lv := &lookupVindex{ ts: env.ws.ts, tmc: env.ws.tmc, logger: env.ws.Logger(), parser: env.ws.SQLParser(), } - _, _, got, cancelFunc, err := l.prepareCreateLookup(ctx, "workflow", ms.SourceKeyspace, specs, false) + _, _, got, cancelFunc, err := lv.prepareCreate(ctx, "workflow", ms.SourceKeyspace, specs, false) if tcase.err != "" { if err == nil || !strings.Contains(err.Error(), tcase.err) { t.Errorf("prepareCreateLookup(%s) err: %v, must contain %v", tcase.description, err, tcase.err) @@ -2139,13 +2139,13 @@ func TestCreateLookupVindexSameKeyspace(t *testing.T) { t.Fatal(err) } - l := &lookup{ + lv := &lookupVindex{ ts: env.ws.ts, tmc: env.ws.tmc, logger: env.ws.Logger(), parser: env.ws.SQLParser(), } - _, got, _, _, err := l.prepareCreateLookup(ctx, "keyspace", ms.TargetKeyspace, specs, false) + _, got, _, _, err := lv.prepareCreate(ctx, "keyspace", ms.TargetKeyspace, specs, false) require.NoError(t, err) if !proto.Equal(got, want) { t.Errorf("same keyspace: got:\n%v, want\n%v", got, want) @@ -2271,13 +2271,13 @@ func TestCreateCustomizedVindex(t *testing.T) { t.Fatal(err) } - l := &lookup{ + lv := &lookupVindex{ ts: env.ws.ts, tmc: env.ws.tmc, logger: env.ws.Logger(), parser: env.ws.SQLParser(), } - _, got, _, _, err := l.prepareCreateLookup(ctx, "workflow", ms.TargetKeyspace, specs, false) + _, got, _, _, err := lv.prepareCreate(ctx, "workflow", ms.TargetKeyspace, specs, false) require.NoError(t, err) if !proto.Equal(got, want) { t.Errorf("customize create lookup error same: got:\n%v, want\n%v", got, want) @@ -2395,13 +2395,13 @@ func TestCreateLookupVindexIgnoreNulls(t *testing.T) { t.Fatal(err) } - l := &lookup{ + lv := &lookupVindex{ ts: env.ws.ts, tmc: env.ws.tmc, logger: env.ws.Logger(), parser: env.ws.SQLParser(), } - ms, ks, _, _, err := l.prepareCreateLookup(ctx, "workflow", ms.TargetKeyspace, specs, false) + ms, ks, _, _, err := lv.prepareCreate(ctx, "workflow", ms.TargetKeyspace, specs, false) require.NoError(t, err) if !proto.Equal(wantKs, ks) { t.Errorf("unexpected keyspace value: got:\n%v, want\n%v", ks, wantKs) @@ -2481,17 +2481,17 @@ func TestStopAfterCopyFlag(t *testing.T) { t.Fatal(err) } - l := &lookup{ + lv := &lookupVindex{ ts: env.ws.ts, tmc: env.ws.tmc, logger: env.ws.Logger(), parser: env.ws.SQLParser(), } - ms1, _, _, _, err := l.prepareCreateLookup(ctx, "workflow", ms.TargetKeyspace, specs, false) + ms1, _, _, _, err := lv.prepareCreate(ctx, "workflow", ms.TargetKeyspace, specs, false) require.NoError(t, err) require.Equal(t, ms1.StopAfterCopy, true) - ms2, _, _, _, err := l.prepareCreateLookup(ctx, "workflow", ms.TargetKeyspace, specs, true) + ms2, _, _, _, err := lv.prepareCreate(ctx, "workflow", ms.TargetKeyspace, specs, true) require.NoError(t, err) require.Equal(t, ms2.StopAfterCopy, false) } diff --git a/go/vt/vtctl/workflow/server.go b/go/vt/vtctl/workflow/server.go index afabea11b7b..badc4c5917e 100644 --- a/go/vt/vtctl/workflow/server.go +++ b/go/vt/vtctl/workflow/server.go @@ -567,13 +567,13 @@ func (s *Server) LookupVindexCreate(ctx context.Context, req *vtctldatapb.Lookup span.Annotate("cells", req.Cells) span.Annotate("tablet_types", req.TabletTypes) - l := &lookup{ + lv := &lookupVindex{ ts: s.ts, tmc: s.tmc, logger: s.Logger(), parser: s.SQLParser(), } - ms, sourceVSchema, targetVSchema, cancelFunc, err := l.prepareCreateLookup(ctx, req.Workflow, req.Keyspace, req.Vindex, req.ContinueAfterCopyWithOwner) + ms, sourceVSchema, targetVSchema, cancelFunc, err := lv.prepareCreate(ctx, req.Workflow, req.Keyspace, req.Vindex, req.ContinueAfterCopyWithOwner) if err != nil { return nil, err }