From c59fd853791eee228573bbb183669be8881ae3dd Mon Sep 17 00:00:00 2001 From: Eric Schmidt Date: Mon, 14 Nov 2022 12:46:31 -0800 Subject: [PATCH 1/3] chore(bigtable): More updates for table protection --- bigtable/bttest/inmem.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/bigtable/bttest/inmem.go b/bigtable/bttest/inmem.go index e2f202023cc1..331915cc77db 100644 --- a/bigtable/bttest/inmem.go +++ b/bigtable/bttest/inmem.go @@ -266,6 +266,16 @@ func (s *server) ModifyColumnFamilies(ctx context.Context, req *btapb.ModifyColu tbl.mu.Lock() defer tbl.mu.Unlock() + // Check table protection status + if tbl.isProtected { + for _, mod := range req.Modifications { + // Cannot delete columns from a protected table + if mod.GetDrop() { + return nil, status.Errorf(codes.FailedPrecondition, "table %q is protected from deletion", req.Name) + } + } + } + for _, mod := range req.Modifications { if create := mod.GetCreate(); create != nil { if _, ok := tbl.families[mod.Id]; ok { @@ -279,9 +289,6 @@ func (s *server) ModifyColumnFamilies(ctx context.Context, req *btapb.ModifyColu tbl.counter++ tbl.families[mod.Id] = newcf } else if mod.GetDrop() { - if tbl.isProtected { - return nil, status.Errorf(codes.FailedPrecondition, "table %q is protected from deletion", req.Name) - } if _, ok := tbl.families[mod.Id]; !ok { return nil, fmt.Errorf("can't delete unknown family %q", mod.Id) } From 91adcc46315cdfd178ac03fd7831c8b53540bbf0 Mon Sep 17 00:00:00 2001 From: Eric Schmidt Date: Mon, 14 Nov 2022 13:00:48 -0800 Subject: [PATCH 2/3] iter --- bigtable/bttest/inmem.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/bigtable/bttest/inmem.go b/bigtable/bttest/inmem.go index 331915cc77db..3d58459362bb 100644 --- a/bigtable/bttest/inmem.go +++ b/bigtable/bttest/inmem.go @@ -212,6 +212,17 @@ func (s *server) DeleteTable(ctx context.Context, req *btapb.DeleteTableRequest) func (s *server) UpdateTable(ctx context.Context, req *btapb.UpdateTableRequest) (*longrunning.Operation, error) { s.mu.Lock() defer s.mu.Unlock() + + updateMask := req.UpdateMask + if updateMask == nil { + return nil, status.Errorf(codes.InvalidArgument, "UpdateTableRequest.UpdateMask required for table update") + } + + var utr *btapb.UpdateTableRequest + if !updateMask.IsValid(utr) { + return nil, status.Errorf(codes.InvalidArgument, "incorrect path in UpdateMask") + } + tbl, ok := s.tables[req.GetTable().GetName()] if !ok { return nil, status.Errorf(codes.NotFound, "table %q not found", req.GetTable().GetName()) From 1c03c0499845bd770524068aa8eeab8d433a4d30 Mon Sep 17 00:00:00 2001 From: Eric Schmidt Date: Tue, 15 Nov 2022 13:59:22 -0800 Subject: [PATCH 3/3] fix test --- bigtable/bttest/inmem.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bigtable/bttest/inmem.go b/bigtable/bttest/inmem.go index 3d58459362bb..d00701192b16 100644 --- a/bigtable/bttest/inmem.go +++ b/bigtable/bttest/inmem.go @@ -218,15 +218,18 @@ func (s *server) UpdateTable(ctx context.Context, req *btapb.UpdateTableRequest) return nil, status.Errorf(codes.InvalidArgument, "UpdateTableRequest.UpdateMask required for table update") } - var utr *btapb.UpdateTableRequest + var utr *btapb.Table if !updateMask.IsValid(utr) { - return nil, status.Errorf(codes.InvalidArgument, "incorrect path in UpdateMask") + return nil, status.Errorf(codes.InvalidArgument, "incorrect path in UpdateMask; got: %v\n", updateMask) } tbl, ok := s.tables[req.GetTable().GetName()] if !ok { return nil, status.Errorf(codes.NotFound, "table %q not found", req.GetTable().GetName()) } + tbl.mu.Lock() + defer tbl.mu.Unlock() + tbl.isProtected = req.GetTable().GetDeletionProtection() res := &longrunning.Operation_Response{}