Skip to content

Commit

Permalink
fix(bigtable): Resolve DeadlineExceeded conformance test failures (#9688
Browse files Browse the repository at this point in the history
)
  • Loading branch information
bhshkh committed Apr 16, 2024
1 parent cdebb60 commit 54d2990
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions bigtable/bigtable.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,22 @@ func init() {
}
}

// Convert error to grpc status error
func convertToGrpcStatusErr(err error) error {
if err != nil {
if errStatus, ok := status.FromError(err); ok {
return status.Error(errStatus.Code(), errStatus.Message())
}

ctxStatus := status.FromContextError(err)
if ctxStatus.Code() != codes.Unknown {
return status.Error(ctxStatus.Code(), ctxStatus.Message())
}
}

return err
}

func (c *Client) fullTableName(table string) string {
return fmt.Sprintf("projects/%s/instances/%s/tables/%s", c.project, c.instance, table)
}
Expand Down Expand Up @@ -286,19 +302,7 @@ func (t *Table) ReadRows(ctx context.Context, arg RowSet, f func(Row) bool, opts
return err
}, retryOptions...)

// Convert error to grpc status error
if err != nil {
if errStatus, ok := status.FromError(err); ok {
return status.Error(errStatus.Code(), errStatus.Message())
}

ctxStatus := status.FromContextError(err)
if ctxStatus.Code() != codes.Unknown {
return status.Error(ctxStatus.Code(), ctxStatus.Message())
}
}

return err
return convertToGrpcStatusErr(err)
}

// ReadRow is a convenience implementation of a single-row reader.
Expand Down Expand Up @@ -840,7 +844,7 @@ func (t *Table) Apply(ctx context.Context, row string, m *Mutation, opts ...Appl
if err == nil {
after(res)
}
return err
return convertToGrpcStatusErr(err)
}

req := &btpb.CheckAndMutateRowRequest{
Expand Down Expand Up @@ -873,7 +877,7 @@ func (t *Table) Apply(ctx context.Context, row string, m *Mutation, opts ...Appl
if err == nil {
after(cmRes)
}
return err
return convertToGrpcStatusErr(err)
}

// An ApplyOption is an optional argument to Apply.
Expand Down Expand Up @@ -1260,5 +1264,5 @@ func (t *Table) SampleRowKeys(ctx context.Context) ([]string, error) {
}
return nil
}, retryOptions...)
return sampledRowKeys, err
return sampledRowKeys, convertToGrpcStatusErr(err)
}

0 comments on commit 54d2990

Please sign in to comment.