Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bigtable): Allow nil condition in conditional mutation #11457

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions bigtable/bigtable.go
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ func (t *Table) apply(ctx context.Context, mt *builtinMetricsTracer, row string,
}

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

req := &btpb.CheckAndMutateRowRequest{
AppProfileId: t.c.appProfile,
RowKey: []byte(row),
PredicateFilter: m.cond.proto(),
AppProfileId: t.c.appProfile,
RowKey: []byte(row),
}
if m.cond != nil {
req.PredicateFilter = m.cond.proto()
}
if t.authorizedView == "" {
req.TableName = t.c.fullTableName(t.table)
Expand Down Expand Up @@ -1119,10 +1121,10 @@ func GetCondMutationResult(matched *bool) ApplyOption {

// Mutation represents a set of changes for a single row of a table.
type Mutation struct {
ops []*btpb.Mutation

ops []*btpb.Mutation
cond Filter
// for conditional mutations
cond Filter
isConditional bool
mtrue, mfalse *Mutation
}

Expand All @@ -1140,7 +1142,7 @@ func NewMutation() *Mutation {
// The application of a ReadModifyWrite is atomic; concurrent ReadModifyWrites will
// be executed serially by the server.
func NewCondMutation(cond Filter, mtrue, mfalse *Mutation) *Mutation {
return &Mutation{cond: cond, mtrue: mtrue, mfalse: mfalse}
return &Mutation{cond: cond, mtrue: mtrue, mfalse: mfalse, isConditional: true}
}

// Set sets a value in a specified column, with the given timestamp.
Expand Down Expand Up @@ -1248,7 +1250,7 @@ func (t *Table) ApplyBulk(ctx context.Context, rowKeys []string, muts []*Mutatio
origEntries := make([]*entryErr, len(rowKeys))
for i, key := range rowKeys {
mut := muts[i]
if mut.cond != nil {
if mut.isConditional {
return nil, errors.New("conditional mutations cannot be applied in bulk")
}
origEntries[i] = &entryErr{Entry: &btpb.MutateRowsRequest_Entry{RowKey: []byte(key), Mutations: mut.ops}}
Expand Down
2 changes: 1 addition & 1 deletion bigtable/internal/testproxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ func (s *goTestProxyServer) CheckAndMutateRow(ctx context.Context, req *pb.Check
falseMuts := mutationFromProto(rrq.FalseMutations)

rfPb := rrq.PredicateFilter
f := bigtable.PassAllFilter()
var f bigtable.Filter

if rfPb != nil {
f = *filterFromProto(rfPb)
Expand Down
Loading