Skip to content

Commit

Permalink
Fix Mount+Migrate
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Lord <[email protected]>
  • Loading branch information
mattlord committed Jan 9, 2025
1 parent b97ad0e commit c9f57f7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
12 changes: 3 additions & 9 deletions go/vt/vttablet/tabletmanager/vdiff/table_differ.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,9 @@ func (td *tableDiffer) selectTablets(ctx context.Context) error {
sourceCells := strings.Split(td.wd.opts.PickerOptions.SourceCell, ",")
targetCells := strings.Split(td.wd.opts.PickerOptions.TargetCell, ",")

// For Mount+Migrate, the source tablets will be in a different
// Vitess cluster with its own TopoServer.
sourceTopoServer := td.wd.ct.ts
if td.wd.ct.externalCluster != "" {
extTS, err := td.wd.ct.ts.OpenExternalVitessClusterServer(ctx, td.wd.ct.externalCluster)
if err != nil {
return err
}
sourceTopoServer = extTS
sourceTopoServer, err := td.wd.getSourceTopoServer()
if err != nil {
return vterrors.Wrap(err, "failed to get source topo server")
}
tabletPickerOptions := discovery.TabletPickerOptions{}
wg.Add(1)
Expand Down
18 changes: 16 additions & 2 deletions go/vt/vttablet/tabletmanager/vdiff/workflow_differ.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"vitess.io/vitess/go/vt/log"
"vitess.io/vitess/go/vt/schema"
"vitess.io/vitess/go/vt/sqlparser"
"vitess.io/vitess/go/vt/topo"
"vitess.io/vitess/go/vt/vtctl/schematools"
"vitess.io/vitess/go/vt/vterrors"
"vitess.io/vitess/go/vt/vtgate/vindexes"
Expand Down Expand Up @@ -389,14 +390,18 @@ func (wd *workflowDiffer) buildPlan(dbClient binlogplayer.DBClient, filter *binl
// differ and determine the proper lastPK to use when saving progress.
// We use the first sourceShard as all of them should have the same schema.
sourceShardName := maps.Keys(wd.ct.sources)[0]
sourceShard, err := wd.ct.ts.GetShard(wd.ct.vde.ctx, wd.ct.sourceKeyspace, sourceShardName)
sourceTS, err := wd.getSourceTopoServer()
if err != nil {
return vterrors.Wrap(err, "failed to get source topo server")
}
sourceShard, err := sourceTS.GetShard(wd.ct.vde.ctx, wd.ct.sourceKeyspace, sourceShardName)
if err != nil {
return err
}
if sourceShard.PrimaryAlias == nil {
return fmt.Errorf("source shard %s has no primary", sourceShardName)
}
sourceTablet, err := wd.ct.ts.GetTablet(wd.ct.vde.ctx, sourceShard.PrimaryAlias)
sourceTablet, err := sourceTS.GetTablet(wd.ct.vde.ctx, sourceShard.PrimaryAlias)
if err != nil {
return fmt.Errorf("failed to get source shard %s primary", sourceShardName)
}
Expand Down Expand Up @@ -537,3 +542,12 @@ func (wd *workflowDiffer) initVDiffTables(dbClient binlogplayer.DBClient) error
}
return nil
}

// getSourceTopoServer returns the source topo server as for Mount+Migrate the
// source tablets will be in a different Vitess cluster with its own TopoServer.
func (wd *workflowDiffer) getSourceTopoServer() (*topo.Server, error) {
if wd.ct.externalCluster == "" {
return wd.ct.ts, nil
}
return wd.ct.ts.OpenExternalVitessClusterServer(wd.ct.vde.ctx, wd.ct.externalCluster)
}

0 comments on commit c9f57f7

Please sign in to comment.