Skip to content

Commit d83bc05

Browse files
authored
fix(bigtable): Allow nil condition in conditional mutation (#11457)
1 parent abb615e commit d83bc05

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

bigtable/bigtable.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,7 @@ func (t *Table) apply(ctx context.Context, mt *builtinMetricsTracer, row string,
10671067
}
10681068

10691069
var callOptions []gax.CallOption
1070-
if m.cond == nil {
1070+
if !m.isConditional {
10711071
req := &btpb.MutateRowRequest{
10721072
AppProfileId: t.c.appProfile,
10731073
RowKey: []byte(row),
@@ -1094,9 +1094,11 @@ func (t *Table) apply(ctx context.Context, mt *builtinMetricsTracer, row string,
10941094
}
10951095

10961096
req := &btpb.CheckAndMutateRowRequest{
1097-
AppProfileId: t.c.appProfile,
1098-
RowKey: []byte(row),
1099-
PredicateFilter: m.cond.proto(),
1097+
AppProfileId: t.c.appProfile,
1098+
RowKey: []byte(row),
1099+
}
1100+
if m.cond != nil {
1101+
req.PredicateFilter = m.cond.proto()
11001102
}
11011103
if t.authorizedView == "" {
11021104
req.TableName = t.c.fullTableName(t.table)
@@ -1148,10 +1150,10 @@ func GetCondMutationResult(matched *bool) ApplyOption {
11481150

11491151
// Mutation represents a set of changes for a single row of a table.
11501152
type Mutation struct {
1151-
ops []*btpb.Mutation
1152-
1153+
ops []*btpb.Mutation
1154+
cond Filter
11531155
// for conditional mutations
1154-
cond Filter
1156+
isConditional bool
11551157
mtrue, mfalse *Mutation
11561158
}
11571159

@@ -1169,7 +1171,7 @@ func NewMutation() *Mutation {
11691171
// The application of a ReadModifyWrite is atomic; concurrent ReadModifyWrites will
11701172
// be executed serially by the server.
11711173
func NewCondMutation(cond Filter, mtrue, mfalse *Mutation) *Mutation {
1172-
return &Mutation{cond: cond, mtrue: mtrue, mfalse: mfalse}
1174+
return &Mutation{cond: cond, mtrue: mtrue, mfalse: mfalse, isConditional: true}
11731175
}
11741176

11751177
// Set sets a value in a specified column, with the given timestamp.
@@ -1282,7 +1284,7 @@ func (t *Table) ApplyBulk(ctx context.Context, rowKeys []string, muts []*Mutatio
12821284
origEntries := make([]*entryErr, len(rowKeys))
12831285
for i, key := range rowKeys {
12841286
mut := muts[i]
1285-
if mut.cond != nil {
1287+
if mut.isConditional {
12861288
return nil, errors.New("conditional mutations cannot be applied in bulk")
12871289
}
12881290
origEntries[i] = &entryErr{Entry: &btpb.MutateRowsRequest_Entry{RowKey: []byte(key), Mutations: mut.ops}}

bigtable/internal/testproxy/proxy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ func (s *goTestProxyServer) CheckAndMutateRow(ctx context.Context, req *pb.Check
754754
falseMuts := mutationFromProto(rrq.FalseMutations)
755755

756756
rfPb := rrq.PredicateFilter
757-
f := bigtable.PassAllFilter()
757+
var f bigtable.Filter
758758

759759
if rfPb != nil {
760760
f = *filterFromProto(rfPb)

0 commit comments

Comments
 (0)