Skip to content

Commit dbca69f

Browse files
craig[bot]kev-caoandy-kimballrickystewart
committed
144515: backup: update compaction to have its own manifest creation code r=msbutler a=kev-cao Previously, the compaction logic would rely on the `createBackupManifest` from the existing backup code, which caused some issues as outlined in #144512. This patch updates compaction logic to instead have its own manifest creation code that does not rely on existing cluster state. Fixes: #144512 Release note: None 145405: vecindex: add Level field to metadata KV key encoding r=drewkimball,michae2 a=andy-kimball Previously, the Metadata KV Key for a vector index partition had these fields: │Index Prefix│Prefix Columns│PartitionKey│Family ID 0│ This commit adds a Level field, which always has the value of zero: │Index Prefix│Prefix Columns│PartitionKey│Level 0│Family ID 0│ This is needed because the KV splits do not handle cases where one KV key is a prefix of other keys. It can cause an unsplittable range to form. By adding the Level field with value zero, we guarantee that the Metadata KV key always sorts before all Vector KV keys in the partition, and yet isn't a prefix of them. Epic: CRDB-42943 Release note: Vector indexes created in beta releases have an encoding issue that may result in failed inserts. These indexes should be dropped and re-created before being used with later releases. 145445: ci: bump timeout for lint r=celiala a=rickystewart ... from 30m to 60m. This timed out in #145433. Epic: none Release note: None Co-authored-by: Kevin Cao <[email protected]> Co-authored-by: Andrew Kimball <[email protected]> Co-authored-by: Ricky Stewart <[email protected]>
4 parents 50027f4 + 270619e + e22bb4d + bc99c2b commit dbca69f

File tree

7 files changed

+293
-101
lines changed

7 files changed

+293
-101
lines changed

build/github/lint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ bazel test \
2828
--sandbox_writable_path=$HOME \
2929
--test_env=GO_SDK=$(dirname $(dirname $(bazel run @go_sdk//:bin/go --run_under=realpath))) \
3030
--test_env=COCKROACH_WORKSPACE=$WORKSPACE \
31-
--test_timeout=1800 \
31+
--test_timeout=3600 \
3232
--build_event_binary_file=bes.bin \
3333
--jobs 50 \
3434
--remote_download_minimal $(./build/github/engflow-args.sh)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ require (
159159
github.com/elastic/gosigar v0.14.3
160160
github.com/emicklei/dot v0.15.0
161161
github.com/fatih/color v1.9.0
162+
github.com/fatih/structs v1.1.0
162163
github.com/felixge/fgprof v0.9.5
163164
github.com/fsnotify/fsnotify v1.5.1
164165
github.com/getsentry/sentry-go v0.27.0
@@ -326,7 +327,6 @@ require (
326327
github.com/eapache/go-resiliency v1.6.0 // indirect
327328
github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3 // indirect
328329
github.com/eapache/queue v1.1.0 // indirect
329-
github.com/fatih/structs v1.1.0 // indirect
330330
github.com/form3tech-oss/jwt-go v3.2.5+incompatible // indirect
331331
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
332332
github.com/ghodss/yaml v1.0.0 // indirect

pkg/backup/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ go_test(
224224
"//pkg/backup/backuputils",
225225
"//pkg/base",
226226
"//pkg/blobs",
227+
"//pkg/build",
227228
"//pkg/build/bazel",
228229
"//pkg/ccl/kvccl",
229230
"//pkg/ccl/multiregionccl",
@@ -345,6 +346,7 @@ go_test(
345346
"@com_github_cockroachdb_pebble//vfs",
346347
"@com_github_cockroachdb_redact//:redact",
347348
"@com_github_cockroachdb_version//:version",
349+
"@com_github_fatih_structs//:structs",
348350
"@com_github_gogo_protobuf//types",
349351
"@com_github_jackc_pgx_v5//:pgx",
350352
"@com_github_kr_pretty//:pretty",

pkg/backup/compaction_job.go

Lines changed: 50 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"github.com/cockroachdb/cockroach/pkg/jobs"
2323
"github.com/cockroachdb/cockroach/pkg/jobs/joberror"
2424
"github.com/cockroachdb/cockroach/pkg/jobs/jobspb"
25-
"github.com/cockroachdb/cockroach/pkg/multitenant/mtinfopb"
2625
"github.com/cockroachdb/cockroach/pkg/roachpb"
2726
"github.com/cockroachdb/cockroach/pkg/scheduledjobs"
2827
"github.com/cockroachdb/cockroach/pkg/security/username"
@@ -256,12 +255,12 @@ func (b *backupResumer) ResumeCompaction(
256255
return err
257256
}
258257
updatedDetails, err = updateCompactionBackupDetails(
259-
ctx, compactChain, initialDetails, backupDest, baseEncryptionOpts, kmsEnv,
258+
ctx, compactChain, initialDetails, backupDest, baseEncryptionOpts,
260259
)
261260
if err != nil {
262261
return err
263262
}
264-
backupManifest, err = createCompactionManifest(ctx, execCtx, updatedDetails, compactChain)
263+
backupManifest, err = compactChain.createCompactionManifest(ctx, updatedDetails)
265264
if err != nil {
266265
return err
267266
}
@@ -407,7 +406,9 @@ type compactionChain struct {
407406
// for a restore.
408407
backupChain []backuppb.BackupManifest
409408
chainToCompact []backuppb.BackupManifest
410-
// start refers to the start time of the first backup to be compacted.
409+
// start refers to the start time of the first backup to be compacted. This
410+
// will always be greater than 0 as a full backup is not a candidate for
411+
// compaction.
411412
// end refers to the end time of the last backup to be compacted.
412413
start, end hlc.Timestamp
413414
// Inclusive startIdx and exclusive endIdx of the sub-chain to compact.
@@ -485,7 +486,6 @@ func updateCompactionBackupDetails(
485486
initialDetails jobspb.BackupDetails,
486487
resolvedDest backupdest.ResolvedDestination,
487488
baseEncryptOpts *jobspb.BackupEncryptionOptions,
488-
kmsEnv cloud.KMSEnv,
489489
) (jobspb.BackupDetails, error) {
490490
if len(compactionChain.chainToCompact) == 0 {
491491
return jobspb.BackupDetails{}, errors.New("no backup manifests to compact")
@@ -525,19 +525,50 @@ func updateCompactionBackupDetails(
525525
return compactedDetails, nil
526526
}
527527

528-
// compactIntroducedSpans takes a compacted backup manifest and the full chain of backups it belongs
529-
// to and computes the introduced spans for the compacted backup.
530-
func compactIntroducedSpans(
531-
ctx context.Context, manifest backuppb.BackupManifest, chain compactionChain,
532-
) (roachpb.Spans, error) {
533-
if err := checkCoverage(ctx, manifest.Spans, chain.backupChain); err != nil {
534-
return roachpb.Spans{}, err
535-
}
536-
return filterSpans(
537-
manifest.Spans,
538-
chain.backupChain[chain.startIdx-1].Spans,
539-
),
540-
nil
528+
// createCompactionManifest creates a new manifest for a compaction job and its
529+
// compacted chain. The details should have its targets resolved.
530+
func (c compactionChain) createCompactionManifest(
531+
ctx context.Context, details jobspb.BackupDetails,
532+
) (*backuppb.BackupManifest, error) {
533+
// TODO (kev-cao): Will need to update the SSTSinkKeyWriter to support
534+
// range keys.
535+
lastBackup := c.lastBackup()
536+
if len(lastBackup.Tenants) != 0 {
537+
return nil, errors.New("backup compactions does not yet support range keys")
538+
}
539+
if err := checkCoverage(ctx, c.lastBackup().Spans, c.backupChain); err != nil {
540+
return nil, err
541+
}
542+
// In compaction, any span that is not included in the backup *preceding* the
543+
// compaction chain is considered introduced.
544+
introducedSpans := filterSpans(
545+
c.lastBackup().Spans,
546+
c.backupChain[c.startIdx-1].Spans,
547+
)
548+
cManifest := lastBackup
549+
cManifest.ID = uuid.MakeV4()
550+
cManifest.StartTime = c.start
551+
cManifest.Descriptors = details.ResolvedTargets
552+
cManifest.IntroducedSpans = introducedSpans
553+
cManifest.IsCompacted = true
554+
555+
cManifest.Dir = cloudpb.ExternalStorage{}
556+
// As this manifest will be used prior to the manifest actually being written
557+
// (and therefore its external files being created) we first set
558+
// HasExternalManifestSSTs to false and allow it to be set to true later when
559+
// it is written to storage.
560+
cManifest.HasExternalManifestSSTs = false
561+
// While we do not compaction on revision history backups, we still need to
562+
// nil out DescriptorChanges to avoid the placeholder descriptor from the
563+
// manifest of the last incremental.
564+
cManifest.DescriptorChanges = nil
565+
cManifest.Files = nil
566+
cManifest.EntryCounts = roachpb.RowCount{}
567+
568+
// The StatisticsFileNames is inherited from the stats of the latest
569+
// incremental we are compacting as the compacted manifest will have the same
570+
// targets as the last incremental.
571+
return &cManifest, nil
541572
}
542573

543574
// resolveBackupSubdir returns the resolved base full backup subdirectory from a
@@ -590,50 +621,8 @@ func resolveBackupDirs(
590621
return resolvedBaseDirs, resolvedIncDirs, resolvedSubdir, nil
591622
}
592623

593-
// createCompactionManifest creates a new manifest for a compaction job and its
594-
// compacted chain.
595-
func createCompactionManifest(
596-
ctx context.Context,
597-
execCtx sql.JobExecContext,
598-
details jobspb.BackupDetails,
599-
compactChain compactionChain,
600-
) (*backuppb.BackupManifest, error) {
601-
var tenantSpans []roachpb.Span
602-
var tenantInfos []mtinfopb.TenantInfoWithUsage
603-
if err := execCtx.ExecCfg().InternalDB.Txn(ctx, func(ctx context.Context, txn isql.Txn) error {
604-
var err error
605-
tenantSpans, tenantInfos, err = getTenantInfo(ctx, execCtx.ExecCfg().Codec, txn, details)
606-
return err
607-
}); err != nil {
608-
return nil, err
609-
}
610-
// TODO (kev-cao): Will need to update the SSTSinkKeyWriter to support
611-
// range keys.
612-
if len(tenantSpans) != 0 || len(tenantInfos) != 0 {
613-
return nil, errors.New("backup compactions does not yet support range keys")
614-
}
615-
m, err := createBackupManifest(
616-
ctx,
617-
execCtx.ExecCfg(),
618-
tenantSpans,
619-
tenantInfos,
620-
details,
621-
compactChain.backupChain,
622-
compactChain.allIters,
623-
)
624-
if err != nil {
625-
return nil, err
626-
}
627-
m.IsCompacted = true
628-
m.IntroducedSpans, err = compactIntroducedSpans(ctx, m, compactChain)
629-
if err != nil {
630-
return nil, err
631-
}
632-
return &m, nil
633-
}
634-
635624
// getBackupChain fetches the current shortest chain of backups (and its
636-
// associated info) required to restore the to the end time specified in the details.
625+
// associated info) required to restore to the end time specified in the details.
637626
func getBackupChain(
638627
ctx context.Context,
639628
execCfg *sql.ExecutorConfig,

0 commit comments

Comments
 (0)