Skip to content

Commit

Permalink
backupccl: check crdb_internal.invalid_objects during backup test cle…
Browse files Browse the repository at this point in the history
…anup

This patch adds a test helper function to easily check for invalid descriptors
during the cleanup of a test cluster created by any of the
backupRestoreTestSetup* helper funcs. This setup is used by many backup unit
tests (including all data driven tests), but a future PR should include this
clean up helper func in any backup unit test that doesn't include use
these helper funcs.

Informs cockroachdb#84757

Release note: none
  • Loading branch information
msbutler committed Jul 28, 2022
1 parent 8c7cfe8 commit 01d251c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
17 changes: 17 additions & 0 deletions pkg/ccl/backupccl/backuputils/testutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,20 @@ func VerifyBackupRestoreStatementResult(

return nil
}

// CheckForInvalidDescriptors returns an error if there exists any descriptors in
// the crdb_internal.invalid_objects virtual table.
func CheckForInvalidDescriptors(sqlDB *gosql.DB) error {
rows, err := sqlDB.Query(`SELECT id FROM crdb_internal.invalid_objects`)
if err != nil {
return err
}
invalidIDs, err := sqlutils.RowsToDataDrivenOutput(rows)
if err != nil {
return err
}
if invalidIDs != "" {
return errors.Newf("The following descriptor ids are invalid %v", invalidIDs)
}
return nil
}
6 changes: 3 additions & 3 deletions pkg/ccl/backupccl/datadriven_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func newDatadrivenTestState() datadrivenTestState {
}
}

func (d *datadrivenTestState) cleanup(ctx context.Context) {
func (d *datadrivenTestState) cleanup(ctx context.Context, t *testing.T) {
for _, db := range d.sqlDBs {
db.Close()
}
Expand Down Expand Up @@ -353,12 +353,12 @@ func TestDataDriven(t *testing.T) {
datadriven.Walk(t, testutils.TestDataPath(t, "backup-restore"), func(t *testing.T, path string) {
var lastCreatedServer string
ds := newDatadrivenTestState()
defer ds.cleanup(ctx)
defer ds.cleanup(ctx, t)
datadriven.RunTest(t, path, func(t *testing.T, d *datadriven.TestData) string {

switch d.Cmd {
case "reset":
ds.cleanup(ctx)
ds.cleanup(ctx, t)
ds = newDatadrivenTestState()
return ""

Expand Down
10 changes: 10 additions & 0 deletions pkg/ccl/backupccl/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"context"
gosql "database/sql"
"fmt"
"github.com/cockroachdb/cockroach/pkg/ccl/backupccl/backuputils"
"io"
"io/ioutil"
"math/rand"
Expand Down Expand Up @@ -113,6 +114,9 @@ func backupRestoreTestSetupWithParams(
}

cleanupFn := func() {
if err := backuputils.CheckForInvalidDescriptors(tc.Conns[0]); err != nil {
t.Fatal(err)
}
tc.Stopper().Stop(ctx) // cleans up in memory storage's auxiliary dirs
dirCleanupFn() // cleans up dir, which is the nodelocal:// storage
}
Expand Down Expand Up @@ -164,6 +168,9 @@ func backupRestoreTestSetupEmptyWithParams(
sqlDB = sqlutils.MakeSQLRunner(tc.Conns[0])

cleanupFn := func() {
if err := backuputils.CheckForInvalidDescriptors(tc.Conns[0]); err != nil {
t.Fatal(err)
}
tc.Stopper().Stop(ctx) // cleans up in memory storage's auxiliary dirs
}

Expand All @@ -186,6 +193,9 @@ func createEmptyCluster(
sqlDB = sqlutils.MakeSQLRunner(tc.Conns[0])

cleanupFn := func() {
if err := backuputils.CheckForInvalidDescriptors(tc.Conns[0]); err != nil {
t.Fatal(err)
}
tc.Stopper().Stop(ctx) // cleans up in memory storage's auxiliary dirs
dirCleanupFn() // cleans up dir, which is the nodelocal:// storage
}
Expand Down

0 comments on commit 01d251c

Please sign in to comment.