Use backupBase internally in base finder code (#4315)
First step to consolidating fields in backupBases. This adds the consolidated fields to the code for finding bases. --- #### Does this PR need a docs update or release note? - [ ] ✅ Yes, it's included - [ ] 🕐 Yes, but in a later PR - [x] ⛔ No #### Type of change - [ ] 🌻 Feature - [ ] 🐛 Bugfix - [ ] 🗺️ Documentation - [ ] 🤖 Supportability/Tests - [ ] 💻 CI/Deployment - [x] 🧹 Tech Debt/Cleanup #### Issue(s) * #3943 #### Test Plan - [ ] 💪 Manual - [x] ⚡ Unit test - [ ] 💚 E2E
This commit is contained in:
parent
0f256a97d5
commit
b33231e98d
@ -186,8 +186,16 @@ func (b *baseFinder) getBackupModel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
type backupBase struct {
|
type backupBase struct {
|
||||||
backup BackupEntry
|
Backup *backup.Backup
|
||||||
manifest ManifestEntry
|
ItemDataSnapshot *snapshot.Manifest
|
||||||
|
// Reasons contains the tenant, protected resource and service/categories that
|
||||||
|
// caused this snapshot to be selected as a base. It's possible some
|
||||||
|
// (tenant, protected resources) will have a subset of the categories as
|
||||||
|
// the reason for selecting a snapshot. For example:
|
||||||
|
// 1. backup user1 email,contacts -> B1
|
||||||
|
// 2. backup user1 contacts -> B2 (uses B1 as base)
|
||||||
|
// 3. backup user1 email,contacts,events (uses B1 for email, B2 for contacts)
|
||||||
|
Reasons []identity.Reasoner
|
||||||
}
|
}
|
||||||
|
|
||||||
// findBasesInSet goes through manifest metadata entries and sees if they're
|
// findBasesInSet goes through manifest metadata entries and sees if they're
|
||||||
@ -267,18 +275,10 @@ func (b *baseFinder) findBasesInSet(
|
|||||||
|
|
||||||
if b.isAssistBackupModel(ictx, bup) {
|
if b.isAssistBackupModel(ictx, bup) {
|
||||||
if assistBase == nil {
|
if assistBase == nil {
|
||||||
assistModel := BackupEntry{
|
|
||||||
Backup: bup,
|
|
||||||
Reasons: []identity.Reasoner{reason},
|
|
||||||
}
|
|
||||||
assistSnap := ManifestEntry{
|
|
||||||
Manifest: man,
|
|
||||||
Reasons: []identity.Reasoner{reason},
|
|
||||||
}
|
|
||||||
|
|
||||||
assistBase = &backupBase{
|
assistBase = &backupBase{
|
||||||
backup: assistModel,
|
Backup: bup,
|
||||||
manifest: assistSnap,
|
ItemDataSnapshot: man,
|
||||||
|
Reasons: []identity.Reasoner{reason},
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Ctx(ictx).Infow(
|
logger.Ctx(ictx).Infow(
|
||||||
@ -297,19 +297,10 @@ func (b *baseFinder) findBasesInSet(
|
|||||||
"search_snapshot_id", meta.ID,
|
"search_snapshot_id", meta.ID,
|
||||||
"ssid", ssid)
|
"ssid", ssid)
|
||||||
|
|
||||||
mergeSnap := ManifestEntry{
|
|
||||||
Manifest: man,
|
|
||||||
Reasons: []identity.Reasoner{reason},
|
|
||||||
}
|
|
||||||
|
|
||||||
mergeModel := BackupEntry{
|
|
||||||
Backup: bup,
|
|
||||||
Reasons: []identity.Reasoner{reason},
|
|
||||||
}
|
|
||||||
|
|
||||||
mergeBase = &backupBase{
|
mergeBase = &backupBase{
|
||||||
backup: mergeModel,
|
Backup: bup,
|
||||||
manifest: mergeSnap,
|
ItemDataSnapshot: man,
|
||||||
|
Reasons: []identity.Reasoner{reason},
|
||||||
}
|
}
|
||||||
|
|
||||||
break
|
break
|
||||||
@ -391,14 +382,11 @@ func (b *baseFinder) FindBases(
|
|||||||
tags map[string]string,
|
tags map[string]string,
|
||||||
) BackupBases {
|
) BackupBases {
|
||||||
var (
|
var (
|
||||||
// All maps go from ID -> entry. We need to track by ID so we can coalesce
|
// Backup models and item data snapshot manifests are 1:1 for bases so just
|
||||||
// the reason for selecting something. Kopia assisted snapshots also use
|
// track things by the backup ID. We need to track by ID so we can coalesce
|
||||||
// ManifestEntry so we have the reasons for selecting them to aid in
|
// the reason for selecting something.
|
||||||
// debugging.
|
mergeBases = map[model.StableID]backupBase{}
|
||||||
mergeBups = map[model.StableID]BackupEntry{}
|
assistBases = map[model.StableID]backupBase{}
|
||||||
assistBups = map[model.StableID]BackupEntry{}
|
|
||||||
mergeSnaps = map[manifest.ID]ManifestEntry{}
|
|
||||||
assistSnaps = map[manifest.ID]ManifestEntry{}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
for _, searchReason := range reasons {
|
for _, searchReason := range reasons {
|
||||||
@ -408,10 +396,7 @@ func (b *baseFinder) FindBases(
|
|||||||
"search_category", searchReason.Category().String())
|
"search_category", searchReason.Category().String())
|
||||||
logger.Ctx(ictx).Info("searching for previous manifests")
|
logger.Ctx(ictx).Info("searching for previous manifests")
|
||||||
|
|
||||||
mergeBase, assistBase, err := b.getBase(
|
mergeBase, assistBase, err := b.getBase(ictx, searchReason, tags)
|
||||||
ictx,
|
|
||||||
searchReason,
|
|
||||||
tags)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Ctx(ctx).Info(
|
logger.Ctx(ctx).Info(
|
||||||
"getting base, falling back to full backup for reason",
|
"getting base, falling back to full backup for reason",
|
||||||
@ -421,61 +406,67 @@ func (b *baseFinder) FindBases(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if mergeBase != nil {
|
if mergeBase != nil {
|
||||||
mergeSnap := mergeBase.manifest
|
mb, ok := mergeBases[mergeBase.Backup.ID]
|
||||||
mergeBackup := mergeBase.backup
|
|
||||||
|
|
||||||
ms, ok := mergeSnaps[mergeSnap.ID]
|
|
||||||
if ok {
|
if ok {
|
||||||
ms.Reasons = append(ms.Reasons, mergeSnap.Reasons...)
|
mb.Reasons = append(mb.Reasons, mergeBase.Reasons...)
|
||||||
} else {
|
} else {
|
||||||
ms = mergeSnap
|
mb = *mergeBase
|
||||||
}
|
}
|
||||||
|
|
||||||
mergeSnaps[mergeSnap.ID] = ms
|
mergeBases[mergeBase.Backup.ID] = mb
|
||||||
|
|
||||||
mb, ok := mergeBups[mergeBackup.ID]
|
|
||||||
if ok {
|
|
||||||
mb.Reasons = append(mb.Reasons, mergeSnap.Reasons...)
|
|
||||||
} else {
|
|
||||||
mb = mergeBackup
|
|
||||||
}
|
|
||||||
|
|
||||||
mergeBups[mergeBackup.ID] = mb
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if assistBase != nil {
|
if assistBase != nil {
|
||||||
assistSnap := assistBase.manifest
|
ab, ok := assistBases[assistBase.Backup.ID]
|
||||||
assistBackup := assistBase.backup
|
|
||||||
|
|
||||||
as, ok := assistSnaps[assistSnap.ID]
|
|
||||||
if ok {
|
if ok {
|
||||||
as.Reasons = append(as.Reasons, assistSnap.Reasons...)
|
ab.Reasons = append(ab.Reasons, assistBase.Reasons...)
|
||||||
} else {
|
} else {
|
||||||
as = assistSnap
|
ab = *assistBase
|
||||||
}
|
}
|
||||||
|
|
||||||
assistSnaps[assistSnap.ID] = as
|
assistBases[assistBase.Backup.ID] = ab
|
||||||
|
|
||||||
ab, ok := assistBups[assistBackup.ID]
|
|
||||||
if ok {
|
|
||||||
ab.Reasons = append(ab.Reasons, assistBackup.Reasons...)
|
|
||||||
} else {
|
|
||||||
ab = assistBackup
|
|
||||||
}
|
|
||||||
|
|
||||||
assistBups[assistBackup.ID] = ab
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(pandeyabs): Fix the terminology used in backupBases to go with
|
// Convert what we got to the format that backupBases takes right now.
|
||||||
// new definitions i.e. mergeSnaps instead of mergeBases, etc.
|
// TODO(ashmrtn): Remove when backupBases has consolidated fields.
|
||||||
res := &backupBases{
|
res := &backupBases{}
|
||||||
backups: maps.Values(mergeBups),
|
bups := make([]BackupEntry, 0, len(mergeBases))
|
||||||
assistBackups: maps.Values(assistBups),
|
snaps := make([]ManifestEntry, 0, len(mergeBases))
|
||||||
mergeBases: maps.Values(mergeSnaps),
|
|
||||||
assistBases: maps.Values(assistSnaps),
|
for _, base := range mergeBases {
|
||||||
|
bups = append(bups, BackupEntry{
|
||||||
|
Backup: base.Backup,
|
||||||
|
Reasons: base.Reasons,
|
||||||
|
})
|
||||||
|
|
||||||
|
snaps = append(snaps, ManifestEntry{
|
||||||
|
Manifest: base.ItemDataSnapshot,
|
||||||
|
Reasons: base.Reasons,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
res.backups = bups
|
||||||
|
res.mergeBases = snaps
|
||||||
|
|
||||||
|
bups = make([]BackupEntry, 0, len(assistBases))
|
||||||
|
snaps = make([]ManifestEntry, 0, len(assistBases))
|
||||||
|
|
||||||
|
for _, base := range assistBases {
|
||||||
|
bups = append(bups, BackupEntry{
|
||||||
|
Backup: base.Backup,
|
||||||
|
Reasons: base.Reasons,
|
||||||
|
})
|
||||||
|
|
||||||
|
snaps = append(snaps, ManifestEntry{
|
||||||
|
Manifest: base.ItemDataSnapshot,
|
||||||
|
Reasons: base.Reasons,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
res.assistBackups = bups
|
||||||
|
res.assistBases = snaps
|
||||||
|
|
||||||
res.fixupAndVerify(ctx)
|
res.fixupAndVerify(ctx)
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user