8000 release-21.1: backup: put SSTs in own dir by dt · Pull Request #66161 · cockroachdb/cockroach · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

release-21.1: backup: put SSTs in own dir #66161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pkg/ccl/backupccl/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ go_library(
"//pkg/sql/roleoption",
"//pkg/sql/rowenc",
"//pkg/sql/rowexec",
"//pkg/sql/sem/builtins",
"//pkg/sql/sem/tree",
"//pkg/sql/sessiondata",
"//pkg/sql/sqlerrors",
Expand Down
4 changes: 1 addition & 3 deletions pkg/ccl/backupccl/backup_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ package backupccl
import (
"bytes"
"context"
"fmt"
"time"

"github.com/cockroachdb/cockroach/pkg/ccl/storageccl"
Expand All @@ -25,7 +24,6 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/execinfrapb"
"github.com/cockroachdb/cockroach/pkg/sql/rowenc"
"github.com/cockroachdb/cockroach/pkg/sql/rowexec"
"github.com/cockroachdb/cockroach/pkg/sql/sem/builtins"
"github.com/cockroachdb/cockroach/pkg/sql/types"
"github.com/cockroachdb/cockroach/pkg/storage/cloud"
"github.com/cockroachdb/cockroach/pkg/storage/cloudimpl"
Expand Down Expand Up @@ -346,7 +344,7 @@ func runBackupProcessor(
files := make([]BackupManifest_File, 0)
for _, file := range res.Files {
if writeSSTsInProcessor {
file.Path = fmt.Sprintf("%d.sst", builtins.GenerateUniqueInt(flowCtx.EvalCtx.NodeID.SQLInstanceID()))
file.Path = storageccl.GenerateUniqueSSTName(flowCtx.EvalCtx.NodeID.SQLInstanceID())
if err := writeFile(ctx, file, defaultStore, storeByLocalityKV); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/ccl/backupccl/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ func TestBackupRestorePartitioned(t *testing.T) {
// Verify that at least one SST exists in each backup destination.
sstMatcher := regexp.MustCompile(`\d+\.sst`)
for i := 1; i <= 3; i++ {
subDir := fmt.Sprintf("%s/foo/%d", dir, i)
subDir := fmt.Sprintf("%s/foo/%d/data", dir, i)
files, err := ioutil.ReadDir(subDir)
if err != nil {
t.Fatal(err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/ccl/backupccl/import_spans_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func makeBackupManifest(
// We only care about the files' span.
files := make([]BackupManifest_File, 0)
for i, span := range append(spans, introducedSpans...) {
files = append(files, BackupManifest_File{Span: span, Path: fmt.Sprintf("%d.sst", i)})
files = append(files, BackupManifest_File{Span: span, Path: fmt.Sprintf("data/%d.sst", i)})
}

return BackupManifest{
Expand Down
15 changes: 11 additions & 4 deletions pkg/ccl/storageccl/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,7 @@ func evalExport(
}

if exportStore != nil {
// TODO(dt): don't reach out into a SQL builtin here; this code lives in KV.
// Create a unique int differently.
nodeID := cArgs.EvalCtx.NodeID()
exported.Path = fmt.Sprintf("%d.sst", builtins.GenerateUniqueInt(base.SQLInstanceID(nodeID)))
exported.Path = GenerateUniqueSSTName(base.SQLInstanceID(cArgs.EvalCtx.NodeID()))
if err := retry.WithMaxAttempts(ctx, base.DefaultRetryOptions(), maxUploadRetries, func() error {
// We blindly retry any error here because we expect the caller to have
// verified the target is writable before sending ExportRequests for it.
Expand Down Expand Up @@ -303,3 +300,13 @@ func getMatchingStore(
}
return "", roachpb.ExternalStorage{}, false
}

// GenerateUniqueSSTName generates a name for a backup SST that will not collide
// with another name generated by this node or another node.
func GenerateUniqueSSTName(nodeID base.SQLInstanceID) string {
// The data/ prefix, including a /, is intended to group SSTs in most of the
// common file/bucket browse UIs.
// TODO(dt): don't reach out into a SQL builtin here; this code lives in KV.
// Create a unique int differently.
return fmt.Sprintf("data/%d.sst", builtins.GenerateUniqueInt(nodeID))
}
0