Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
88338: cliccl: remove the debug backup commands r=dt a=stevendanna

These commands have been experimental and undocumented since their original development. Many of the commands provide the same functionality as "SHOW BACKUP".  The export command provides unique functionality, but it is hard to use correctly.

Further, leaving these in the code has forced us to maintain APIs in the backupccl code that we would have otherwised removed or refactored.

Release justification: Low risk removal of unsupported functionality.

Release note (cli change): The previously-experimental and undocumented `debug backup` has been removed.

Co-authored-by: Steven Danna <danna@cockroachlabs.com>
  • Loading branch information
craig[bot] and stevendanna committed Sep 26, 2022
2 parents 8107342 + 5974d17 commit 0961abd
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 1,976 deletions.
135 changes: 0 additions & 135 deletions pkg/ccl/backupccl/targets.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ package backupccl
import (
"context"
"fmt"
"reflect"
"sort"
"strings"

Expand All @@ -21,8 +20,6 @@ import (
"github.com/cockroachdb/cockroach/pkg/keys"
"github.com/cockroachdb/cockroach/pkg/kv"
"github.com/cockroachdb/cockroach/pkg/kv/kvclient"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/security/username"
"github.com/cockroachdb/cockroach/pkg/sql"
"github.com/cockroachdb/cockroach/pkg/sql/catalog"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb"
Expand All @@ -37,7 +34,6 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/cockroach/pkg/util/hlc"
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
"github.com/cockroachdb/cockroach/pkg/util/tracing"
"github.com/cockroachdb/errors"
)
Expand Down Expand Up @@ -423,137 +419,6 @@ func selectTargets(
// EntryFiles is a group of sst files of a backup table range
type EntryFiles []execinfrapb.RestoreFileSpec

// BackupTableEntry wraps information of a table retrieved
// from backup manifests.
// exported to cliccl for exporting data directly from backup sst.
type BackupTableEntry struct {
Desc catalog.TableDescriptor
Span roachpb.Span
Files []EntryFiles
LastSchemaChangeTime hlc.Timestamp
}

// MakeBackupTableEntry looks up the descriptor of fullyQualifiedTableName
// from backupManifests and returns a BackupTableEntry, which contains
// the table descriptor, the primary index span, and the sst files.
func MakeBackupTableEntry(
ctx context.Context,
fullyQualifiedTableName string,
backupManifests []backuppb.BackupManifest,
endTime hlc.Timestamp,
user username.SQLUsername,
backupCodec keys.SQLCodec,
) (BackupTableEntry, error) {
var descName []string
if descName = strings.Split(fullyQualifiedTableName, "."); len(descName) != 3 {
return BackupTableEntry{}, errors.Newf("table name should be specified in format databaseName.schemaName.tableName")
}

if !endTime.IsEmpty() {
ind := -1
for i, b := range backupManifests {
if b.StartTime.Less(endTime) && endTime.LessEq(b.EndTime) {
if endTime != b.EndTime && b.MVCCFilter != backuppb.MVCCFilter_All {
errorHints := "reading data for requested time requires that BACKUP was created with %q" +
" or should specify the time to be an exact backup time, nearest backup time is %s"
return BackupTableEntry{}, errors.WithHintf(
errors.Newf("unknown read time: %s", timeutil.Unix(0, endTime.WallTime).UTC()),
errorHints, backupOptRevisionHistory, timeutil.Unix(0, b.EndTime.WallTime).UTC(),
)
}
ind = i
break
}
}
if ind == -1 {
return BackupTableEntry{}, errors.Newf("supplied backups do not cover requested time %s", timeutil.Unix(0, endTime.WallTime).UTC())
}
backupManifests = backupManifests[:ind+1]
}

allDescs, _ := backupinfo.LoadSQLDescsFromBackupsAtTime(backupManifests, endTime)
resolver, err := backupresolver.NewDescriptorResolver(allDescs)
if err != nil {
return BackupTableEntry{}, errors.Wrapf(err, "creating a new resolver for all descriptors")
}

found, _, desc, err := resolver.LookupObject(ctx, tree.ObjectLookupFlags{}, descName[0], descName[1], descName[2])
if err != nil {
return BackupTableEntry{}, errors.Wrapf(err, "looking up table %s", fullyQualifiedTableName)
}
if !found {
return BackupTableEntry{}, errors.Newf("table %s not found", fullyQualifiedTableName)
}
tbMutable, ok := desc.(*tabledesc.Mutable)
if !ok {
return BackupTableEntry{}, errors.Newf("object %s not mutable", fullyQualifiedTableName)
}
tbDesc, err := catalog.AsTableDescriptor(tbMutable)
if err != nil {
return BackupTableEntry{}, errors.Wrapf(err, "fetching table %s descriptor", fullyQualifiedTableName)
}

tablePrimaryIndexSpan := tbDesc.PrimaryIndexSpan(backupCodec)

if err := checkCoverage(ctx, []roachpb.Span{tablePrimaryIndexSpan}, backupManifests); err != nil {
return BackupTableEntry{}, errors.Wrapf(err, "making spans for table %s", fullyQualifiedTableName)
}

introducedSpanFrontier, err := createIntroducedSpanFrontier(backupManifests, hlc.Timestamp{})
if err != nil {
return BackupTableEntry{}, err
}

entry := makeSimpleImportSpans(
[]roachpb.Span{tablePrimaryIndexSpan},
backupManifests,
nil, /*backupLocalityInfo*/
introducedSpanFrontier,
roachpb.Key{}, /*lowWaterMark*/
0, /* disable merging */
)
lastSchemaChangeTime := findLastSchemaChangeTime(backupManifests, tbDesc, endTime)

backupTableEntry := BackupTableEntry{
tbDesc,
tablePrimaryIndexSpan,
make([]EntryFiles, 0),
lastSchemaChangeTime,
}

for _, e := range entry {
backupTableEntry.Files = append(backupTableEntry.Files, e.Files)
}

return backupTableEntry, nil
}

func findLastSchemaChangeTime(
backupManifests []backuppb.BackupManifest, tbDesc catalog.TableDescriptor, endTime hlc.Timestamp,
) hlc.Timestamp {
lastSchemaChangeTime := endTime
for i := len(backupManifests) - 1; i >= 0; i-- {
manifest := backupManifests[i]
for j := len(manifest.DescriptorChanges) - 1; j >= 0; j-- {
rev := manifest.DescriptorChanges[j]

if endTime.LessEq(rev.Time) {
continue
}

if rev.ID == tbDesc.GetID() {
d := descbuilder.NewBuilder(rev.Desc).BuildExistingMutable()
revDesc, _ := catalog.AsTableDescriptor(d)
if !reflect.DeepEqual(revDesc.PublicColumns(), tbDesc.PublicColumns()) {
return lastSchemaChangeTime
}
lastSchemaChangeTime = rev.Time
}
}
}
return lastSchemaChangeTime
}

// checkMultiRegionCompatible checks if the given table is compatible to be
// restored into the given database according to its multi-region locality.
// It returns an error describing the incompatibility if not.
Expand Down
49 changes: 1 addition & 48 deletions pkg/ccl/cliccl/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,59 +6,27 @@ go_library(
srcs = [
"cliccl.go",
"debug.go",
"debug_backup.go",
"demo.go",
"start.go",
],
importpath = "github.com/cockroachdb/cockroach/pkg/ccl/cliccl",
visibility = ["//visibility:public"],
deps = [
"//pkg/base",
"//pkg/blobs",
"//pkg/ccl/backupccl",
"//pkg/ccl/backupccl/backupbase",
"//pkg/ccl/backupccl/backupdest",
"//pkg/ccl/backupccl/backupinfo",
"//pkg/ccl/backupccl/backuppb",
"//pkg/ccl/backupccl/backuputils",
"//pkg/ccl/baseccl",
"//pkg/ccl/cliccl/cliflagsccl",
"//pkg/ccl/storageccl",
"//pkg/ccl/storageccl/engineccl/enginepbccl",
"//pkg/ccl/utilccl",
"//pkg/ccl/workloadccl/cliccl",
"//pkg/cli",
"//pkg/cli/clierrorplus",
"//pkg/cli/cliflagcfg",
"//pkg/cli/cliflags",
"//pkg/cli/clisqlexec",
"//pkg/cli/democluster",
"//pkg/cloud",
"//pkg/cloud/nodelocal",
"//pkg/keys",
"//pkg/roachpb",
"//pkg/security/username",
"//pkg/server",
"//pkg/settings/cluster",
"//pkg/sql/catalog/colinfo",
"//pkg/sql/catalog/descpb",
"//pkg/sql/catalog/funcdesc",
"//pkg/sql/catalog/tabledesc",
"//pkg/sql/row",
"//pkg/sql/rowenc",
"//pkg/sql/sem/catconstants",
"//pkg/sql/sem/eval",
"//pkg/sql/sem/tree",
"//pkg/storage",
"//pkg/storage/enginepb",
"//pkg/util/hlc",
"//pkg/util/humanizeutil",
"//pkg/util/protoutil",
"//pkg/util/stop",
"//pkg/util/timeutil",
"//pkg/util/timeutil/pgdate",
"//pkg/util/uuid",
"@com_github_cockroachdb_apd_v3//:apd",
"@com_github_cockroachdb_errors//:errors",
"@com_github_cockroachdb_errors//oserror",
"@com_github_spf13_cobra//:cobra",
Expand All @@ -68,28 +36,13 @@ go_library(
go_test(
name = "cliccl_test",
size = "medium",
srcs = [
"debug_backup_test.go",
"main_test.go",
],
srcs = ["main_test.go"],
args = ["-test.timeout=295s"],
embed = [":cliccl"],
deps = [
"//pkg/base",
"//pkg/build",
"//pkg/ccl/backupccl/backupbase",
"//pkg/ccl/utilccl",
"//pkg/cli",
"//pkg/cli/clisqlexec",
"//pkg/server",
"//pkg/testutils",
"//pkg/testutils/serverutils",
"//pkg/testutils/sqlutils",
"//pkg/util/hlc",
"//pkg/util/leaktest",
"//pkg/util/log",
"//pkg/util/timeutil",
"@com_github_stretchr_testify//require",
],
)

Expand Down
Loading

0 comments on commit 0961abd

Please sign in to comment.