From 10aa896bb3eb4c8c110f02ef88ebecd378ba03b0 Mon Sep 17 00:00:00 2001 From: Matt Lord Date: Fri, 10 Jan 2025 14:04:15 -0500 Subject: [PATCH] Improve error handling Signed-off-by: Matt Lord --- .../tabletmanager/vdiff/table_differ.go | 17 ++++++++++------- .../tabletmanager/vdiff/workflow_differ.go | 6 ++++-- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/go/vt/vttablet/tabletmanager/vdiff/table_differ.go b/go/vt/vttablet/tabletmanager/vdiff/table_differ.go index 486a6d63f14..06c03b236f7 100644 --- a/go/vt/vttablet/tabletmanager/vdiff/table_differ.go +++ b/go/vt/vttablet/tabletmanager/vdiff/table_differ.go @@ -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), @@ -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 { @@ -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 diff --git a/go/vt/vttablet/tabletmanager/vdiff/workflow_differ.go b/go/vt/vttablet/tabletmanager/vdiff/workflow_differ.go index 58670826ddb..0e53bbe4679 100644 --- a/go/vt/vttablet/tabletmanager/vdiff/workflow_differ.go +++ b/go/vt/vttablet/tabletmanager/vdiff/workflow_differ.go @@ -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 { @@ -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 }