Skip to content

Commit

Permalink
go/vt/vttablet: fix nilness issues (#14686)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdlayher authored Dec 6, 2023
1 parent 7312b05 commit f8a90ac
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 17 deletions.
14 changes: 7 additions & 7 deletions go/vt/vttablet/grpctabletconn/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (conn *gRPCQueryClient) StreamExecute(ctx context.Context, target *querypb.
fields = ser.Result.Fields
}
if err := callback(sqltypes.CustomProto3ToResult(fields, ser.Result)); err != nil {
if err == nil || err == io.EOF {
if err == io.EOF {
return nil
}
return err
Expand Down Expand Up @@ -537,7 +537,7 @@ func (conn *gRPCQueryClient) BeginStreamExecute(ctx context.Context, target *que
fields = ser.Result.Fields
}
if err := callback(sqltypes.CustomProto3ToResult(fields, ser.Result)); err != nil {
if err == nil || err == io.EOF {
if err == io.EOF {
return state, nil
}
return state, err
Expand Down Expand Up @@ -583,7 +583,7 @@ func (conn *gRPCQueryClient) MessageStream(ctx context.Context, target *querypb.
fields = msr.Result.Fields
}
if err := callback(sqltypes.CustomProto3ToResult(fields, msr.Result)); err != nil {
if err == nil || err == io.EOF {
if err == io.EOF {
return nil
}
return err
Expand Down Expand Up @@ -640,7 +640,7 @@ func (conn *gRPCQueryClient) StreamHealth(ctx context.Context, callback func(*qu
return tabletconn.ErrorFromGRPC(err)
}
if err := callback(shr); err != nil {
if err == nil || err == io.EOF {
if err == io.EOF {
return nil
}
return err
Expand Down Expand Up @@ -924,7 +924,7 @@ func (conn *gRPCQueryClient) ReserveBeginStreamExecute(ctx context.Context, targ
fields = ser.Result.Fields
}
if err := callback(sqltypes.CustomProto3ToResult(fields, ser.Result)); err != nil {
if err == nil || err == io.EOF {
if err == io.EOF {
return state, nil
}
return state, err
Expand Down Expand Up @@ -1029,7 +1029,7 @@ func (conn *gRPCQueryClient) ReserveStreamExecute(ctx context.Context, target *q
fields = ser.Result.Fields
}
if err := callback(sqltypes.CustomProto3ToResult(fields, ser.Result)); err != nil {
if err == nil || err == io.EOF {
if err == io.EOF {
return state, nil
}
return state, err
Expand Down Expand Up @@ -1092,7 +1092,7 @@ func (conn *gRPCQueryClient) GetSchema(ctx context.Context, target *querypb.Targ
return tabletconn.ErrorFromGRPC(err)
}
if err := callback(shr); err != nil {
if err == nil || err == io.EOF {
if err == io.EOF {
return nil
}
return err
Expand Down
4 changes: 2 additions & 2 deletions go/vt/vttablet/onlineddl/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ func (e *Executor) cutOverVReplMigration(ctx context.Context, s *VReplStream) er
defer tmClient.Close()

// sanity checks:
vreplTable, err := getVreplTable(ctx, s)
vreplTable, err := getVreplTable(s)
if err != nil {
return err
}
Expand Down Expand Up @@ -1422,7 +1422,7 @@ func (e *Executor) initVreplicationRevertMigration(ctx context.Context, onlineDD
return nil, err
}

vreplTableName, err := getVreplTable(ctx, revertStream)
vreplTableName, err := getVreplTable(revertStream)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions go/vt/vttablet/onlineddl/vrepl.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,16 +659,16 @@ func (v *VRepl) generateStartStatement(ctx context.Context) (string, error) {
)
}

func getVreplTable(ctx context.Context, s *VReplStream) (string, error) {
func getVreplTable(s *VReplStream) (string, error) {
// sanity checks:
if s == nil {
return "", vterrors.Errorf(vtrpcpb.Code_UNKNOWN, "No vreplication stream migration %s", s.workflow)
return "", vterrors.Errorf(vtrpcpb.Code_UNKNOWN, "No vreplication stream migration")
}
if s.bls.Filter == nil {
return "", vterrors.Errorf(vtrpcpb.Code_UNKNOWN, "No binlog source filter for migration %s", s.workflow)
}
if len(s.bls.Filter.Rules) != 1 {
return "", vterrors.Errorf(vtrpcpb.Code_UNKNOWN, "Cannot detect filter rules for migration/vreplication %+v", s.workflow)
return "", vterrors.Errorf(vtrpcpb.Code_UNKNOWN, "Cannot detect filter rules for migration/vreplication %s", s.workflow)
}
vreplTable := s.bls.Filter.Rules[0].Match
return vreplTable, nil
Expand Down
3 changes: 0 additions & 3 deletions go/vt/vttablet/tabletmanager/vdiff/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,6 @@ func (vde *Engine) handleCreateResumeAction(ctx context.Context, dbClient binlog
if qr.RowsAffected == 0 {
msg := fmt.Sprintf("no completed or stopped vdiff found for UUID %s on tablet %v",
req.VdiffUuid, vde.thisTablet.Alias)
if err != nil {
msg = fmt.Sprintf("%s (%v)", msg, err)
}
return fmt.Errorf(msg)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type sequencedExpectationSet map[SequencedExpectation]any

func (ses *sequencedExpectationSet) Add(expectation SequencedExpectation) {
if ses == nil {
*ses = make(sequencedExpectationSet)
ses = new(sequencedExpectationSet)
}
(*ses)[expectation] = true
}
Expand All @@ -27,7 +27,7 @@ func (ses *sequencedExpectationSet) Contains(expectation SequencedExpectation) b

func (ses *sequencedExpectationSet) Slice() []SequencedExpectation {
s := make([]SequencedExpectation, 0)
if len(*ses) == 0 {
if ses == nil || len(*ses) == 0 {
return s
}
for se := range *ses {
Expand Down

0 comments on commit f8a90ac

Please sign in to comment.