Skip to content

Commit

Permalink
Merge #55109
Browse files Browse the repository at this point in the history
55109: sql: doctor check for dropped tables r=spaskob a=spaskob

If a table is dropped it should not have a namespace entry.

Release note: none.

Co-authored-by: Spas Bojanov <[email protected]>
  • Loading branch information
craig[bot] and Spas Bojanov committed Oct 2, 2020
2 parents 6fa7a09 + c0404a5 commit 411cb5b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/sql/doctor/doctor.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ func ExamineDescriptors(
}
continue
}

if desc.Dropped() {
fmt.Fprint(stdout, reportMsg(desc, "dropped but namespace entry(s) found: %v", names))
problemsFound = true
}

// We delete all pointed descriptors to leave what is missing in the
// descriptor table.
delete(nMap, row.ID)
Expand Down
23 changes: 23 additions & 0 deletions pkg/sql/doctor/doctor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/catalog/tabledesc"
"github.com/cockroachdb/cockroach/pkg/sql/doctor"
"github.com/cockroachdb/cockroach/pkg/sql/types"
"github.com/cockroachdb/cockroach/pkg/util/hlc"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/cockroach/pkg/util/protoutil"
Expand Down Expand Up @@ -69,6 +70,10 @@ func TestExamineDescriptors(t *testing.T) {
defer leaktest.AfterTest(t)()
defer log.Scope(t).Close(t)

droppedValidTableDesc := protoutil.Clone(validTableDesc).(*descpb.Descriptor)
descpb.TableFromDescriptor(droppedValidTableDesc, hlc.Timestamp{WallTime: 1}).
State = descpb.DescriptorState_DROP

tests := []struct {
descTable doctor.DescriptorTable
namespaceTable doctor.NamespaceTable
Expand Down Expand Up @@ -269,6 +274,24 @@ Row(s) [{ParentID:0 ParentSchemaID:0 Name:null}]: NULL value found
},
expected: `Examining 1 descriptors and 3 namespace entries...
Database 1: ParentID 0, ParentSchemaID 0, Name 'db': extra draining names found [{ParentID:0 ParentSchemaID:0 Name:db3}]
`,
},
{
descTable: doctor.DescriptorTable{
{ID: 1, DescBytes: toBytes(t, droppedValidTableDesc)},
{
ID: 2,
DescBytes: toBytes(t, &descpb.Descriptor{Union: &descpb.Descriptor_Database{
Database: &descpb.DatabaseDescriptor{Name: "db", ID: 2},
}}),
},
},
namespaceTable: doctor.NamespaceTable{
{NameInfo: descpb.NameInfo{ParentID: 2, ParentSchemaID: 29, Name: "t"}, ID: 1},
{NameInfo: descpb.NameInfo{Name: "db"}, ID: 2},
},
expected: `Examining 2 descriptors and 2 namespace entries...
Table 1: ParentID 2, ParentSchemaID 29, Name 't': dropped but namespace entry(s) found: [{2 29 t}]
`,
},
}
Expand Down

0 comments on commit 411cb5b

Please sign in to comment.