@@ -211,7 +211,7 @@ func (b *backupResumer) ResumeCompaction(
211211 // We interleave the computation of the compaction chain between the destination
212212 // resolution and writing of backup lock due to the need to verify that the
213213 // compaction chain is a valid chain.
214- prevManifests , localityInfo , encryption , allIters , err := getBackupChain (
214+ prevManifests , localityInfo , baseEncryptionOpts , allIters , err := getBackupChain (
215215 ctx , execCtx .ExecCfg (), execCtx .User (), initialDetails .Destination ,
216216 initialDetails .EncryptionOptions , initialDetails .EndTime , kmsEnv ,
217217 )
@@ -253,7 +253,7 @@ func (b *backupResumer) ResumeCompaction(
253253 return err
254254 }
255255 updatedDetails , err = updateCompactionBackupDetails (
256- ctx , compactChain , initialDetails , backupDest , encryption , kmsEnv ,
256+ ctx , compactChain , initialDetails , backupDest , baseEncryptionOpts , kmsEnv ,
257257 )
258258 if err != nil {
259259 return err
@@ -492,22 +492,12 @@ func updateCompactionBackupDetails(
492492 compactionChain compactionChain ,
493493 initialDetails jobspb.BackupDetails ,
494494 resolvedDest backupdest.ResolvedDestination ,
495- encryption * jobspb.BackupEncryptionOptions ,
495+ baseEncryptOpts * jobspb.BackupEncryptionOptions ,
496496 kmsEnv cloud.KMSEnv ,
497497) (jobspb.BackupDetails , error ) {
498498 if len (compactionChain .chainToCompact ) == 0 {
499499 return jobspb.BackupDetails {}, errors .New ("no backup manifests to compact" )
500500 }
501- var encryptionInfo * jobspb.EncryptionInfo
502- if encryption != nil {
503- var err error
504- _ , encryptionInfo , err = backupencryption .MakeNewEncryptionOptions (
505- ctx , encryption , kmsEnv ,
506- )
507- if err != nil {
508- return jobspb.BackupDetails {}, err
509- }
510- }
511501 lastBackup := compactionChain .lastBackup ()
512502 allDescs , _ , err := backupinfo .LoadSQLDescsFromBackupsAtTime (
513503 ctx ,
@@ -524,13 +514,16 @@ func updateCompactionBackupDetails(
524514 destination := initialDetails .Destination
525515 destination .Subdir = resolvedDest .ChosenSubdir
526516 compactedDetails := jobspb.BackupDetails {
527- Destination : destination ,
528- StartTime : compactionChain .start ,
529- EndTime : compactionChain .end ,
530- URI : resolvedDest .DefaultURI ,
531- URIsByLocalityKV : resolvedDest .URIsByLocalityKV ,
532- EncryptionOptions : encryption ,
533- EncryptionInfo : encryptionInfo ,
517+ Destination : destination ,
518+ StartTime : compactionChain .start ,
519+ EndTime : compactionChain .end ,
520+ URI : resolvedDest .DefaultURI ,
521+ URIsByLocalityKV : resolvedDest .URIsByLocalityKV ,
522+ // Because we cannot have nice things, we persist a semi hydrated version of
523+ // EncryptionOptions at planning, and then add the key at the beginning of
524+ // resume using the same data structure in details. NB: EncryptionInfo is
525+ // left blank and only added on the full backup (i think).
526+ EncryptionOptions : baseEncryptOpts ,
534527 CollectionURI : resolvedDest .CollectionURI ,
535528 ResolvedTargets : allDescsPb ,
536529 ResolvedCompleteDbs : lastBackup .CompleteDbs ,
@@ -692,28 +685,22 @@ func getBackupChain(
692685 log .Warningf (ctx , "failed to cleanup incremental backup stores: %+v" , err )
693686 }
694687 }()
695- // If encryption keys have not already been computed, then we will compute
696- // it using the base store.
697- // TODO (kev-cao): Once we resolve #143725, we can remove this check and
698- // expect `GetEncryptionFromBaseStore` to be idempotent.
699- var encryption * jobspb.BackupEncryptionOptions
700- if encryptionOpts != nil && encryptionOpts .Mode != jobspb .EncryptionMode_None &&
701- (encryptionOpts .Key != nil || encryptionOpts .KMSInfo != nil ) {
702- encryption = encryptionOpts
703- } else {
704- encryption , err = backupencryption .GetEncryptionFromBaseStore (
688+ baseEncryptionInfo := encryptionOpts
689+ if encryptionOpts != nil && ! encryptionOpts .HasKey () {
690+ baseEncryptionInfo , err = backupencryption .GetEncryptionFromBaseStore (
705691 ctx , baseStores [0 ], encryptionOpts , kmsEnv ,
706692 )
707693 if err != nil {
708694 return nil , nil , nil , nil , err
709695 }
710696 }
697+
711698 mem := execCfg .RootMemoryMonitor .MakeBoundAccount ()
712699 defer mem .Close (ctx )
713700
714701 _ , manifests , localityInfo , memReserved , err := backupdest .ResolveBackupManifests (
715702 ctx , & mem , baseStores , incStores , mkStore , resolvedBaseDirs ,
716- resolvedIncDirs , endTime , encryption , kmsEnv ,
703+ resolvedIncDirs , endTime , baseEncryptionInfo , kmsEnv ,
717704 user , false ,
718705 )
719706 if err != nil {
@@ -723,12 +710,12 @@ func getBackupChain(
723710 mem .Shrink (ctx , memReserved )
724711 }()
725712 allIters , err := backupinfo .GetBackupManifestIterFactories (
726- ctx , execCfg .DistSQLSrv .ExternalStorage , manifests , encryption , kmsEnv ,
713+ ctx , execCfg .DistSQLSrv .ExternalStorage , manifests , baseEncryptionInfo , kmsEnv ,
727714 )
728715 if err != nil {
729716 return nil , nil , nil , nil , err
730717 }
731- return manifests , localityInfo , encryption , allIters , nil
718+ return manifests , localityInfo , baseEncryptionInfo , allIters , nil
732719}
733720
734721// concludeBackupCompaction completes the backup compaction process after the backup has been
0 commit comments