Skip to content

Commit

Permalink
tabledesc: validate that old FK representation is not used
Browse files Browse the repository at this point in the history
Previously, pre-19.2, we used to use a different foreign key
representation. We have since then migrated off of it. This commit adds
validation checks to verify that we are no longer using it.

This commit also makes superficial changes to the
catalog.TableDescriptor interface.

Fixes cockroachdb#66262

Release note: None
  • Loading branch information
Marius Posta committed Sep 23, 2021
1 parent 24b570f commit 87bbae7
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 549 deletions.
1 change: 0 additions & 1 deletion pkg/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ ALL_TESTS = [
"//pkg/spanconfig/spanconfigkvaccessor:spanconfigkvaccessor_test",
"//pkg/spanconfig/spanconfigmanager:spanconfigmanager_test",
"//pkg/sql/catalog/catalogkeys:catalogkeys_test",
"//pkg/sql/catalog/catalogkv:catalogkv_test",
"//pkg/sql/catalog/catformat:catformat_test",
"//pkg/sql/catalog/catprivilege:catprivilege_test",
"//pkg/sql/catalog/colinfo:colinfo_test",
Expand Down
23 changes: 1 addition & 22 deletions pkg/sql/catalog/catalogkv/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("//build:STRINGER.bzl", "stringer")

go_library(
Expand Down Expand Up @@ -33,27 +33,6 @@ go_library(
],
)

go_test(
name = "catalogkv_test",
size = "small",
srcs = ["unwrap_validation_test.go"],
data = glob(["testdata/**"]),
embed = [":catalogkv"],
deps = [
"//pkg/keys",
"//pkg/kv",
"//pkg/roachpb:with-mocks",
"//pkg/sql/catalog",
"//pkg/sql/catalog/descpb",
"//pkg/testutils",
"//pkg/util/encoding/csv",
"//pkg/util/hlc",
"//pkg/util/protoutil",
"@com_github_cockroachdb_errors//:errors",
"@com_github_stretchr_testify//require",
],
)

stringer(
name = "gen-descriptorkind-stringer",
src = "catalogkv.go",
Expand Down

This file was deleted.

This file was deleted.

136 changes: 0 additions & 136 deletions pkg/sql/catalog/catalogkv/unwrap_validation_test.go

This file was deleted.

2 changes: 0 additions & 2 deletions pkg/sql/catalog/descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,6 @@ type TableDescriptor interface {
ForeachInboundFK(f func(fk *descpb.ForeignKeyConstraint) error) error
GetConstraintInfo() (map[string]descpb.ConstraintDetail, error)
AllActiveAndInactiveForeignKeys() []*descpb.ForeignKeyConstraint
GetInboundFKs() []descpb.ForeignKeyConstraint
GetOutboundFKs() []descpb.ForeignKeyConstraint

GetLocalityConfig() *descpb.TableDescriptor_LocalityConfig
IsLocalityRegionalByRow() bool
Expand Down
13 changes: 13 additions & 0 deletions pkg/sql/catalog/tabledesc/structured.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/types"
"github.com/cockroachdb/cockroach/pkg/util/errorutil/unimplemented"
"github.com/cockroachdb/cockroach/pkg/util/hlc"
"github.com/cockroachdb/cockroach/pkg/util/iterutil"
"github.com/cockroachdb/cockroach/pkg/util/protoutil"
"github.com/cockroachdb/errors"
"github.com/lib/pq/oid"
Expand Down Expand Up @@ -314,6 +315,9 @@ func (desc *wrapper) ForeachDependedOnBy(
) error {
for i := range desc.DependedOnBy {
if err := f(&desc.DependedOnBy[i]); err != nil {
if iterutil.Done(err) {
return nil
}
return err
}
}
Expand All @@ -327,6 +331,9 @@ func (desc *wrapper) ForeachOutboundFK(
) error {
for i := range desc.OutboundFKs {
if err := f(&desc.OutboundFKs[i]); err != nil {
if iterutil.Done(err) {
return nil
}
return err
}
}
Expand All @@ -338,6 +345,9 @@ func (desc *wrapper) ForeachOutboundFK(
func (desc *wrapper) ForeachInboundFK(f func(fk *descpb.ForeignKeyConstraint) error) error {
for i := range desc.InboundFKs {
if err := f(&desc.InboundFKs[i]); err != nil {
if iterutil.Done(err) {
return nil
}
return err
}
}
Expand All @@ -354,6 +364,9 @@ func (desc *wrapper) NumFamilies() int {
func (desc *wrapper) ForeachFamily(f func(family *descpb.ColumnFamilyDescriptor) error) error {
for i := range desc.Families {
if err := f(&desc.Families[i]); err != nil {
if iterutil.Done(err) {
return nil
}
return err
}
}
Expand Down
Loading

0 comments on commit 87bbae7

Please sign in to comment.