Skip to content

Commit

Permalink
Improve error handling
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Lord <[email protected]>
  • Loading branch information
mattlord committed Jan 10, 2025
1 parent 91ded28 commit 10aa896
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
17 changes: 10 additions & 7 deletions go/vt/vttablet/tabletmanager/vdiff/table_differ.go
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ func (td *tableDiffer) updateTableProgress(dbClient binlogplayer.DBClient, dr *D
}
lastPKTxt, err := prototext.Marshal(lastPK)
if err != nil {
return err
return vterrors.Wrapf(err, "failed to marshal lastpk value %+v for table %s", lastPK, td.table.Name)
}
query, err = sqlparser.ParseAndBind(sqlUpdateTableProgress,
sqltypes.Int64BindVariable(dr.ProcessedRows),
Expand Down Expand Up @@ -907,20 +907,21 @@ func (td *tableDiffer) getSourcePKCols() error {
}
sourceShard, err := sourceTS.GetShard(ctx, td.wd.ct.sourceKeyspace, sourceShardName)
if err != nil {
return err
return vterrors.Wrapf(err, "failed to get source shard %s", sourceShardName)
}
if sourceShard.PrimaryAlias == nil {
return fmt.Errorf("source shard %s has no primary", sourceShardName)
return vterrors.Errorf(vtrpcpb.Code_FAILED_PRECONDITION, "source shard %s has no primary", sourceShardName)
}
sourceTablet, err := sourceTS.GetTablet(ctx, sourceShard.PrimaryAlias)
if err != nil {
return fmt.Errorf("failed to get source shard %s primary", sourceShardName)
return vterrors.Wrapf(err, "failed to get primary tablet in source shard %s", sourceShardName)
}
sourceSchema, err := td.wd.ct.tmc.GetSchema(ctx, sourceTablet.Tablet, &tabletmanagerdatapb.GetSchemaRequest{
Tables: []string{td.table.Name},
})
if err != nil {
return err
return vterrors.Wrapf(err, "failed to get the schema for table %s from source tablet %s",
td.table.Name, topoproto.TabletAliasString(sourceTablet.Tablet.Alias))
}
sourceTable := sourceSchema.TableDefinitions[0]
if len(sourceTable.PrimaryKeyColumns) == 0 {
Expand All @@ -931,13 +932,15 @@ func (td *tableDiffer) getSourcePKCols() error {
MaxRows: 1,
})
if err != nil {
return nil, err
return nil, vterrors.Wrapf(err, "failed to query the %s source tablet in order to get a primary key equivalent for the %s table",
topoproto.TabletAliasString(sourceTablet.Tablet.Alias), td.table.Name)
}
return sqltypes.Proto3ToResult(res), nil
}
pkeCols, _, err := mysqlctl.GetPrimaryKeyEquivalentColumns(ctx, executeFetch, sourceTablet.DbName(), td.table.Name)
if err != nil {
return err
return vterrors.Wrapf(err, "failed to get a primary key equivalent for the %s table from source tablet %s",
td.table.Name, topoproto.TabletAliasString(sourceTablet.Tablet.Alias))
}
if len(pkeCols) > 0 {
sourceTable.PrimaryKeyColumns = pkeCols
Expand Down
6 changes: 4 additions & 2 deletions go/vt/vttablet/tabletmanager/vdiff/workflow_differ.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,8 @@ func (wd *workflowDiffer) buildPlan(dbClient binlogplayer.DBClient, filter *binl
// We get the PK columns from the source schema as well as they can differ
// and they determine the proper position to use when saving our progress.
if err := td.getSourcePKCols(); err != nil {
return err
return vterrors.Wrapf(err, "could not get the primary key columns from the %s source keyspace",
wd.ct.sourceKeyspace)
}
}
if len(wd.tableDiffers) == 0 {
Expand Down Expand Up @@ -419,7 +420,8 @@ func (wd *workflowDiffer) getTableLastPK(dbClient binlogplayer.DBClient, tableNa
if len(lastpk) != 0 {
lastPK := &tabletmanagerdatapb.VDiffTableLastPK{}
if err := prototext.Unmarshal(lastpk, lastPK); err != nil {
return nil, vterrors.Wrapf(err, "failed to unmarshal lastpk for table %s", tableName)
return nil, vterrors.Wrapf(err, "failed to unmarshal lastpk value of %s for table %s",
string(lastpk), tableName)
}
return lastPK, nil
}
Expand Down

0 comments on commit 10aa896

Please sign in to comment.