Skip to content

Commit

Permalink
fix(bigtable/bttest): Error when applying a mutation with an empty ro…
Browse files Browse the repository at this point in the history
…w key

Against a real version of Bigtable, an attempt to apply a mutation with
an empty row key leads to the following error being produced

```
unable to apply: rpc error: code = InvalidArgument desc = Row keys must be non-empty
```

bttest does not conform to this behaviour. This commit:

- adds error-handling when given a mutation with an empty row key, and
- adds a regression test.
  • Loading branch information
adamroyjones committed May 13, 2024
1 parent 54fab10 commit 7737223
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
7 changes: 7 additions & 0 deletions bigtable/bttest/inmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,13 @@ func (s *server) PingAndWarm(ctx context.Context, req *btpb.PingAndWarmRequest)
// fam should be a snapshot of the keys of tbl.families.
// It assumes r.mu is locked.
func applyMutations(tbl *table, r *row, muts []*btpb.Mutation, fs map[string]*columnFamily) error {
if len(r.key) == 0 {
return status.Errorf(
codes.InvalidArgument,
"Row keys must be non-empty",
)
}

for _, mut := range muts {
switch mut := mut.Mutation.(type) {
default:
Expand Down
42 changes: 42 additions & 0 deletions bigtable/bttest/inmem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2424,6 +2424,48 @@ func TestMutateRowsEmptyMutationErrors(t *testing.T) {
}
}

func TestMutateRowEmptyRowKeyErrors(t *testing.T) {
srv := &server{tables: make(map[string]*table)}
ctx := context.Background()

const tableID = "mytable"
tblReq := &btapb.CreateTableRequest{
Parent: "cluster",
TableId: tableID,
Table: &btapb.Table{
ColumnFamilies: map[string]*btapb.ColumnFamily{"cf": {}},
},
}
if _, err := srv.CreateTable(ctx, tblReq); err != nil {
t.Fatalf("Failed to create the table: %v", err)
}

const name = "cluster/tables/" + tableID
req := &btpb.MutateRowRequest{
TableName: name,
RowKey: []byte(""),
Mutations: []*btpb.Mutation{
{
Mutation: &btpb.Mutation_SetCell_{
SetCell: &btpb.Mutation_SetCell{
FamilyName: "cf",
ColumnQualifier: []byte("col"),
TimestampMicros: 1000,
Value: []byte("hello, world!"),
},
},
},
},
}

resp, err := srv.MutateRow(ctx, req)
if resp != nil || err == nil || err.Error() !=
"rpc error: code = InvalidArgument"+
" desc = Row keys must be non-empty" {
t.Fatalf("Failed to produce the expected error: %s", err)
}
}

func TestFilterRowCellsPerRowLimitFilterTruthiness(t *testing.T) {
row := &row{
key: "row",
Expand Down

0 comments on commit 7737223

Please sign in to comment.