Skip to content

Commit

Permalink
chore(bigtable): switch to google.golang.org/protobuf (#8626)
Browse files Browse the repository at this point in the history
Revival of #4317 without conflicts.
  • Loading branch information
codyoss authored Sep 29, 2023
1 parent 6933c5a commit 2b5a2b5
Show file tree
Hide file tree
Showing 15 changed files with 393 additions and 251 deletions.
47 changes: 20 additions & 27 deletions bigtable/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ import (
"cloud.google.com/go/internal/optional"
"cloud.google.com/go/longrunning"
lroauto "cloud.google.com/go/longrunning/autogen"
"github.com/golang/protobuf/ptypes"
durpb "github.com/golang/protobuf/ptypes/duration"
gax "github.com/googleapis/gax-go/v2"
"google.golang.org/api/cloudresourcemanager/v1"
"google.golang.org/api/iterator"
Expand All @@ -43,6 +41,7 @@ import (
"google.golang.org/grpc/metadata"
"google.golang.org/protobuf/types/known/durationpb"
field_mask "google.golang.org/protobuf/types/known/fieldmaskpb"
"google.golang.org/protobuf/types/known/timestamppb"
)

const adminAddr = "bigtableadmin.googleapis.com:443"
Expand Down Expand Up @@ -565,10 +564,10 @@ func (ac *AdminClient) SnapshotTable(ctx context.Context, table, cluster, snapsh
ctx = mergeOutgoingMetadata(ctx, ac.md)
prefix := ac.instancePrefix()

var ttlProto *durpb.Duration
var ttlProto *durationpb.Duration

if ttl > 0 {
ttlProto = ptypes.DurationProto(ttl)
ttlProto = durationpb.New(ttl)
}

req := &btapb.SnapshotTableRequest{
Expand Down Expand Up @@ -643,15 +642,15 @@ func newSnapshotInfo(snapshot *btapb.Snapshot) (*SnapshotInfo, error) {
tablePathParts := strings.Split(snapshot.SourceTable.Name, "/")
tableID := tablePathParts[len(tablePathParts)-1]

createTime, err := ptypes.Timestamp(snapshot.CreateTime)
if err != nil {
if err := snapshot.CreateTime.CheckValid(); err != nil {
return nil, fmt.Errorf("invalid createTime: %w", err)
}
createTime := snapshot.CreateTime.AsTime()

deleteTime, err := ptypes.Timestamp(snapshot.DeleteTime)
if err != nil {
return nil, fmt.Errorf("invalid deleteTime: %w", err)
if err := snapshot.DeleteTime.CheckValid(); err != nil {
return nil, fmt.Errorf("invalid deleteTime: %v", err)
}
deleteTime := snapshot.DeleteTime.AsTime()

return &SnapshotInfo{
Name: name,
Expand Down Expand Up @@ -1902,10 +1901,7 @@ func (ac *AdminClient) CreateBackup(ctx context.Context, table, cluster, backup
ctx = mergeOutgoingMetadata(ctx, ac.md)
prefix := ac.instancePrefix()

parsedExpireTime, err := ptypes.TimestampProto(expireTime)
if err != nil {
return err
}
parsedExpireTime := timestamppb.New(expireTime)

req := &btapb.CreateBackupRequest{
Parent: prefix + "/clusters/" + cluster,
Expand Down Expand Up @@ -1977,20 +1973,20 @@ func newBackupInfo(backup *btapb.Backup) (*BackupInfo, error) {
tablePathParts := strings.Split(backup.SourceTable, "/")
tableID := tablePathParts[len(tablePathParts)-1]

startTime, err := ptypes.Timestamp(backup.StartTime)
if err != nil {
return nil, fmt.Errorf("invalid startTime: %w", err)
if err := backup.StartTime.CheckValid(); err != nil {
return nil, fmt.Errorf("invalid startTime: %v", err)
}
startTime := backup.StartTime.AsTime()

endTime, err := ptypes.Timestamp(backup.EndTime)
if err != nil {
return nil, fmt.Errorf("invalid endTime: %w", err)
if err := backup.EndTime.CheckValid(); err != nil {
return nil, fmt.Errorf("invalid endTime: %v", err)
}
endTime := backup.EndTime.AsTime()

expireTime, err := ptypes.Timestamp(backup.ExpireTime)
if err != nil {
return nil, fmt.Errorf("invalid expireTime: %w", err)
if err := backup.ExpireTime.CheckValid(); err != nil {
return nil, fmt.Errorf("invalid expireTime: %v", err)
}
expireTime := backup.ExpireTime.AsTime()
encryptionInfo := newEncryptionInfo(backup.EncryptionInfo)
bi := BackupInfo{
Name: name,
Expand Down Expand Up @@ -2081,10 +2077,7 @@ func (ac *AdminClient) UpdateBackup(ctx context.Context, cluster, backup string,
ctx = mergeOutgoingMetadata(ctx, ac.md)
backupPath := ac.backupPath(cluster, ac.instance, backup)

expireTimestamp, err := ptypes.TimestampProto(expireTime)
if err != nil {
return err
}
expireTimestamp := timestamppb.New(expireTime)

updateMask := &field_mask.FieldMask{}
updateMask.Paths = append(updateMask.Paths, "expire_time")
Expand All @@ -2096,6 +2089,6 @@ func (ac *AdminClient) UpdateBackup(ctx context.Context, cluster, backup string,
},
UpdateMask: updateMask,
}
_, err = ac.tClient.UpdateBackup(ctx, req)
_, err := ac.tClient.UpdateBackup(ctx, req)
return err
}
2 changes: 1 addition & 1 deletion bigtable/bigtable.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (

btopt "cloud.google.com/go/bigtable/internal/option"
"cloud.google.com/go/internal/trace"
"github.com/golang/protobuf/proto"
gax "github.com/googleapis/gax-go/v2"
"google.golang.org/api/option"
"google.golang.org/api/option/internaloption"
Expand All @@ -37,6 +36,7 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"

// Install google-c2p resolver, which is required for direct path.
_ "google.golang.org/grpc/xds/googledirectpath"
Expand Down
8 changes: 4 additions & 4 deletions bigtable/bttest/inmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ import (
"google.golang.org/protobuf/proto"

longrunning "cloud.google.com/go/longrunning/autogen/longrunningpb"
emptypb "github.com/golang/protobuf/ptypes/empty"
"github.com/golang/protobuf/ptypes/wrappers"
"github.com/google/btree"
btapb "google.golang.org/genproto/googleapis/bigtable/admin/v2"
btpb "google.golang.org/genproto/googleapis/bigtable/v2"
Expand All @@ -61,7 +59,9 @@ import (
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/anypb"
"google.golang.org/protobuf/types/known/durationpb"
"google.golang.org/protobuf/types/known/emptypb"
"google.golang.org/protobuf/types/known/timestamppb"
"google.golang.org/protobuf/types/known/wrapperspb"
"rsc.io/binaryregexp"
)

Expand Down Expand Up @@ -619,8 +619,8 @@ func streamRow(stream btpb.Bigtable_ReadRowsServer, r *row, f *btpb.RowFilter, s
for _, cell := range cells {
rrr.Chunks = append(rrr.Chunks, &btpb.ReadRowsResponse_CellChunk{
RowKey: []byte(r.key),
FamilyName: &wrappers.StringValue{Value: fam.name},
Qualifier: &wrappers.BytesValue{Value: []byte(colName)},
FamilyName: &wrapperspb.StringValue{Value: fam.name},
Qualifier: &wrapperspb.BytesValue{Value: []byte(colName)},
TimestampMicros: cell.ts,
Value: cell.value,
Labels: cell.labels,
Expand Down
60 changes: 31 additions & 29 deletions bigtable/bttest/inmem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@ import (

"cloud.google.com/go/bigtable/internal/option"
"cloud.google.com/go/internal/testutil"
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes/wrappers"
"github.com/google/go-cmp/cmp"
btapb "google.golang.org/genproto/googleapis/bigtable/admin/v2"
btpb "google.golang.org/genproto/googleapis/bigtable/v2"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/encoding/prototext"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/testing/protocmp"
"google.golang.org/protobuf/types/known/wrapperspb"
)

func TestConcurrentMutationsReadModifyAndGC(t *testing.T) {
Expand Down Expand Up @@ -1177,8 +1179,8 @@ func TestReadRowsReversed(t *testing.T) {
wantChunks := []*btpb.ReadRowsResponse_CellChunk{
{
RowKey: []byte("row2"),
FamilyName: &wrappers.StringValue{Value: "cf"},
Qualifier: &wrappers.BytesValue{Value: []byte("cq")},
FamilyName: &wrapperspb.StringValue{Value: "cf"},
Qualifier: &wrapperspb.BytesValue{Value: []byte("cq")},
TimestampMicros: 1000,
Value: []byte("b"),
RowStatus: &btpb.ReadRowsResponse_CellChunk_CommitRow{
Expand All @@ -1187,16 +1189,16 @@ func TestReadRowsReversed(t *testing.T) {
},
{
RowKey: []byte("row1"),
FamilyName: &wrappers.StringValue{Value: "cf"},
Qualifier: &wrappers.BytesValue{Value: []byte("cq")},
FamilyName: &wrapperspb.StringValue{Value: "cf"},
Qualifier: &wrapperspb.BytesValue{Value: []byte("cq")},
TimestampMicros: 1000,
Value: []byte("a"),
RowStatus: &btpb.ReadRowsResponse_CellChunk_CommitRow{
CommitRow: true,
},
},
}
if diff := cmp.Diff(gotChunks, wantChunks, cmp.Comparer(proto.Equal)); diff != "" {
if diff := cmp.Diff(gotChunks, wantChunks, protocmp.Transform()); diff != "" {
t.Fatalf("Response chunks mismatch: got: + want -\n%s", diff)
}
}
Expand Down Expand Up @@ -1394,21 +1396,21 @@ func TestCheckAndMutateRowWithPredicate(t *testing.T) {
wantState: []*btpb.ReadRowsResponse_CellChunk{
{
RowKey: []byte("row1"),
FamilyName: &wrappers.StringValue{
FamilyName: &wrapperspb.StringValue{
Value: "cf",
},
Qualifier: &wrappers.BytesValue{
Qualifier: &wrapperspb.BytesValue{
Value: []byte("cq"),
},
TimestampMicros: 1000,
Value: []byte{0x11},
},
{
RowKey: []byte("row1"),
FamilyName: &wrappers.StringValue{
FamilyName: &wrapperspb.StringValue{
Value: "zf",
},
Qualifier: &wrappers.BytesValue{
Qualifier: &wrapperspb.BytesValue{
Value: []byte("et"),
},
TimestampMicros: 2000,
Expand All @@ -1419,10 +1421,10 @@ func TestCheckAndMutateRowWithPredicate(t *testing.T) {
},
{
RowKey: []byte("row2"),
FamilyName: &wrappers.StringValue{
FamilyName: &wrapperspb.StringValue{
Value: "df",
},
Qualifier: &wrappers.BytesValue{
Qualifier: &wrapperspb.BytesValue{
Value: []byte("dq"),
},
TimestampMicros: 1000,
Expand All @@ -1433,10 +1435,10 @@ func TestCheckAndMutateRowWithPredicate(t *testing.T) {
},
{
RowKey: []byte("row3"),
FamilyName: &wrappers.StringValue{
FamilyName: &wrapperspb.StringValue{
Value: "ef",
},
Qualifier: &wrappers.BytesValue{
Qualifier: &wrapperspb.BytesValue{
Value: []byte("eq"),
},
TimestampMicros: 1000,
Expand All @@ -1447,10 +1449,10 @@ func TestCheckAndMutateRowWithPredicate(t *testing.T) {
},
{
RowKey: []byte("row4"),
FamilyName: &wrappers.StringValue{
FamilyName: &wrapperspb.StringValue{
Value: "ff",
},
Qualifier: &wrappers.BytesValue{
Qualifier: &wrapperspb.BytesValue{
Value: []byte("fq"),
},
TimestampMicros: 1000,
Expand Down Expand Up @@ -1865,10 +1867,10 @@ func TestFilterRow(t *testing.T) {
} {
got, err := filterRow(test.filter, row.copy())
if err != nil {
t.Errorf("%s: got unexpected error: %v", proto.CompactTextString(test.filter), err)
t.Errorf("%s: got unexpected error: %v", prototext.Format(test.filter), err)
}
if got != test.want {
t.Errorf("%s: got %t, want %t", proto.CompactTextString(test.filter), got, test.want)
t.Errorf("%s: got %t, want %t", prototext.Format(test.filter), got, test.want)
}
}
}
Expand Down Expand Up @@ -1912,10 +1914,10 @@ func TestFilterRowWithErrors(t *testing.T) {
} {
got, err := filterRow(test.badRegex, row.copy())
if got != false {
t.Errorf("%s: got true, want false", proto.CompactTextString(test.badRegex))
t.Errorf("%s: got true, want false", prototext.Format(test.badRegex))
}
if err == nil {
t.Errorf("%s: got no error, want error", proto.CompactTextString(test.badRegex))
t.Errorf("%s: got no error, want error", prototext.Format(test.badRegex))
}
}
}
Expand Down Expand Up @@ -2111,8 +2113,8 @@ func TestFilterRowWithSingleColumnQualifier(t *testing.T) {
Chunks: []*btpb.ReadRowsResponse_CellChunk{
{
RowKey: []byte("row3"),
FamilyName: &wrappers.StringValue{Value: "cf"},
Qualifier: &wrappers.BytesValue{Value: []byte("cq")},
FamilyName: &wrapperspb.StringValue{Value: "cf"},
Qualifier: &wrapperspb.BytesValue{Value: []byte("cq")},
TimestampMicros: 1000,
Value: []byte("a"),
RowStatus: &btpb.ReadRowsResponse_CellChunk_CommitRow{
Expand Down Expand Up @@ -2199,8 +2201,8 @@ func TestValueFilterRowWithAlternationInRegex(t *testing.T) {
wantChunks := []*btpb.ReadRowsResponse_CellChunk{
{
RowKey: []byte("row1"),
FamilyName: &wrappers.StringValue{Value: "cf"},
Qualifier: &wrappers.BytesValue{Value: []byte("cq")},
FamilyName: &wrapperspb.StringValue{Value: "cf"},
Qualifier: &wrapperspb.BytesValue{Value: []byte("cq")},
TimestampMicros: 1000,
Value: []byte(""),
RowStatus: &btpb.ReadRowsResponse_CellChunk_CommitRow{
Expand All @@ -2209,8 +2211,8 @@ func TestValueFilterRowWithAlternationInRegex(t *testing.T) {
},
{
RowKey: []byte("row3"),
FamilyName: &wrappers.StringValue{Value: "cf"},
Qualifier: &wrappers.BytesValue{Value: []byte("cq")},
FamilyName: &wrapperspb.StringValue{Value: "cf"},
Qualifier: &wrapperspb.BytesValue{Value: []byte("cq")},
TimestampMicros: 1000,
Value: []byte("a"),
RowStatus: &btpb.ReadRowsResponse_CellChunk_CommitRow{
Expand Down Expand Up @@ -2296,10 +2298,10 @@ func TestFilterRowCellsPerRowLimitFilterTruthiness(t *testing.T) {
} {
got, err := filterRow(test.filter, row.copy())
if err != nil {
t.Errorf("%s: got unexpected error: %v", proto.CompactTextString(test.filter), err)
t.Errorf("%s: got unexpected error: %v", prototext.Format(test.filter), err)
}
if got != test.want {
t.Errorf("%s: got %t, want %t", proto.CompactTextString(test.filter), got, test.want)
t.Errorf("%s: got %t, want %t", prototext.Format(test.filter), got, test.want)
}
}
}
10 changes: 5 additions & 5 deletions bigtable/bttest/instance_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import (

"cloud.google.com/go/iam/apiv1/iampb"
longrunning "cloud.google.com/go/longrunning/autogen/longrunningpb"
"github.com/golang/protobuf/ptypes/empty"
btapb "google.golang.org/genproto/googleapis/bigtable/admin/v2"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/emptypb"
)

var _ btapb.BigtableInstanceAdminServer = (*server)(nil)
Expand Down Expand Up @@ -58,7 +58,7 @@ var (
regInstanceName = regexp.MustCompile(instanceNameRegRaw)
)

func (s *server) DeleteInstance(ctx context.Context, req *btapb.DeleteInstanceRequest) (*empty.Empty, error) {
func (s *server) DeleteInstance(ctx context.Context, req *btapb.DeleteInstanceRequest) (*emptypb.Empty, error) {
name := req.GetName()
if !regInstanceName.Match([]byte(name)) {
return nil, status.Errorf(codes.InvalidArgument,
Expand All @@ -77,7 +77,7 @@ func (s *server) DeleteInstance(ctx context.Context, req *btapb.DeleteInstanceRe
// Then finally remove the instance.
delete(s.instances, name)

return new(empty.Empty), nil
return new(emptypb.Empty), nil
}

func (s *server) CreateCluster(ctx context.Context, req *btapb.CreateClusterRequest) (*longrunning.Operation, error) {
Expand All @@ -96,7 +96,7 @@ func (s *server) UpdateCluster(ctx context.Context, req *btapb.Cluster) (*longru
return nil, errUnimplemented
}

func (s *server) DeleteCluster(ctx context.Context, req *btapb.DeleteClusterRequest) (*empty.Empty, error) {
func (s *server) DeleteCluster(ctx context.Context, req *btapb.DeleteClusterRequest) (*emptypb.Empty, error) {
return nil, errUnimplemented
}

Expand All @@ -116,7 +116,7 @@ func (s *server) UpdateAppProfile(ctx context.Context, req *btapb.UpdateAppProfi
return nil, errUnimplemented
}

func (s *server) DeleteAppProfile(ctx context.Context, req *btapb.DeleteAppProfileRequest) (*empty.Empty, error) {
func (s *server) DeleteAppProfile(ctx context.Context, req *btapb.DeleteAppProfileRequest) (*emptypb.Empty, error) {
return nil, errUnimplemented
}

Expand Down
Loading

0 comments on commit 2b5a2b5

Please # to comment.