Wrap new base finder and wire it up (#3524)

Take the new base finder code, wrap it in
a thin wrapper and use it in place of the
previous way of finding base snapshots

This solution is not focused on efficiency
as it does result in looking up backup
models multiple times. It's more to get the
new way of finding bases out and then we
can go back and smooth things over when
we have the chance

---

#### Does this PR need a docs update or release note?

- [x]  Yes, it's included
- [ ] 🕐 Yes, but in a later PR
- [ ]  No

#### Type of change

- [x] 🌻 Feature
- [ ] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [ ] 🤖 Supportability/Tests
- [ ] 💻 CI/Deployment
- [ ] 🧹 Tech Debt/Cleanup

#### Issue(s)

* #3202

#### Test Plan

- [ ] 💪 Manual
- [x]  Unit test
- [x] 💚 E2E
This commit is contained in:
ashmrtn 2023-05-31 11:27:15 -07:00 committed by GitHub
parent 06b04c6eff
commit 7cb01b1e27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 141 additions and 128 deletions

View File

@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### Added
- Added ProtectedResourceName to the backup list json output. ProtectedResourceName holds either a UPN or a WebURL, depending on the resource type. - Added ProtectedResourceName to the backup list json output. ProtectedResourceName holds either a UPN or a WebURL, depending on the resource type.
- Rework base selection logic for incremental backups so it's more likely to find a valid base.
### Fixed ### Fixed
- Fix Exchange folder cache population error when parent folder isn't found. - Fix Exchange folder cache population error when parent folder isn't found.

View File

@ -15,10 +15,10 @@ import (
"github.com/alcionai/corso/src/pkg/logger" "github.com/alcionai/corso/src/pkg/logger"
) )
type BackupBases struct { type backupBases struct {
Backups []BackupEntry backups []BackupEntry
MergeBases []ManifestEntry mergeBases []ManifestEntry
AssistBases []ManifestEntry assistBases []ManifestEntry
} }
type BackupEntry struct { type BackupEntry struct {
@ -31,7 +31,7 @@ type baseFinder struct {
bg inject.GetBackuper bg inject.GetBackuper
} }
func NewBaseFinder( func newBaseFinder(
sm snapshotManager, sm snapshotManager,
bg inject.GetBackuper, bg inject.GetBackuper,
) (*baseFinder, error) { ) (*baseFinder, error) {
@ -183,11 +183,11 @@ func (b *baseFinder) getBase(
return b.findBasesInSet(ctx, reason, metas) return b.findBasesInSet(ctx, reason, metas)
} }
func (b *baseFinder) FindBases( func (b *baseFinder) findBases(
ctx context.Context, ctx context.Context,
reasons []Reason, reasons []Reason,
tags map[string]string, tags map[string]string,
) (BackupBases, error) { ) (backupBases, error) {
var ( var (
// All maps go from ID -> entry. We need to track by ID so we can coalesce // All maps go from ID -> entry. We need to track by ID so we can coalesce
// the reason for selecting something. Kopia assisted snapshots also use // the reason for selecting something. Kopia assisted snapshots also use
@ -251,9 +251,24 @@ func (b *baseFinder) FindBases(
} }
} }
return BackupBases{ return backupBases{
Backups: maps.Values(baseBups), backups: maps.Values(baseBups),
MergeBases: maps.Values(baseSnaps), mergeBases: maps.Values(baseSnaps),
AssistBases: maps.Values(kopiaAssistSnaps), assistBases: maps.Values(kopiaAssistSnaps),
}, nil }, nil
} }
func (b *baseFinder) FindBases(
ctx context.Context,
reasons []Reason,
tags map[string]string,
) ([]ManifestEntry, error) {
bb, err := b.findBases(ctx, reasons, tags)
if err != nil {
return nil, clues.Stack(err)
}
// assistBases contains all snapshots so we can return it while maintaining
// almost all compatibility.
return bb.assistBases, nil
}

View File

@ -342,10 +342,10 @@ func (suite *BaseFinderUnitSuite) TestNoResult_NoBackupsOrSnapshots() {
}, },
} }
bb, err := bf.FindBases(ctx, reasons, nil) bb, err := bf.findBases(ctx, reasons, nil)
assert.NoError(t, err, "getting bases: %v", clues.ToCore(err)) assert.NoError(t, err, "getting bases: %v", clues.ToCore(err))
assert.Empty(t, bb.MergeBases) assert.Empty(t, bb.mergeBases)
assert.Empty(t, bb.AssistBases) assert.Empty(t, bb.assistBases)
} }
func (suite *BaseFinderUnitSuite) TestNoResult_ErrorListingSnapshots() { func (suite *BaseFinderUnitSuite) TestNoResult_ErrorListingSnapshots() {
@ -366,10 +366,10 @@ func (suite *BaseFinderUnitSuite) TestNoResult_ErrorListingSnapshots() {
}, },
} }
bb, err := bf.FindBases(ctx, reasons, nil) bb, err := bf.findBases(ctx, reasons, nil)
assert.NoError(t, err, "getting bases: %v", clues.ToCore(err)) assert.NoError(t, err, "getting bases: %v", clues.ToCore(err))
assert.Empty(t, bb.MergeBases) assert.Empty(t, bb.mergeBases)
assert.Empty(t, bb.AssistBases) assert.Empty(t, bb.assistBases)
} }
func (suite *BaseFinderUnitSuite) TestGetBases() { func (suite *BaseFinderUnitSuite) TestGetBases() {
@ -825,7 +825,7 @@ func (suite *BaseFinderUnitSuite) TestGetBases() {
bg: &mockModelGetter{data: test.backupData}, bg: &mockModelGetter{data: test.backupData},
} }
bb, err := bf.FindBases( bb, err := bf.findBases(
ctx, ctx,
test.input, test.input,
nil) nil)
@ -833,17 +833,17 @@ func (suite *BaseFinderUnitSuite) TestGetBases() {
checkBackupEntriesMatch( checkBackupEntriesMatch(
t, t,
bb.Backups, bb.backups,
test.backupData, test.backupData,
test.expectedBaseReasons) test.expectedBaseReasons)
checkManifestEntriesMatch( checkManifestEntriesMatch(
t, t,
bb.MergeBases, bb.mergeBases,
test.manifestData, test.manifestData,
test.expectedBaseReasons) test.expectedBaseReasons)
checkManifestEntriesMatch( checkManifestEntriesMatch(
t, t,
bb.AssistBases, bb.assistBases,
test.manifestData, test.manifestData,
test.expectedAssistManifestReasons) test.expectedAssistManifestReasons)
}) })
@ -920,7 +920,7 @@ func (suite *BaseFinderUnitSuite) TestFetchPrevSnapshots_CustomTags() {
bg: &mockModelGetter{data: backupData}, bg: &mockModelGetter{data: backupData},
} }
bb, err := bf.FindBases( bb, err := bf.findBases(
ctx, ctx,
testAllUsersAllCats, testAllUsersAllCats,
test.tags) test.tags)
@ -928,7 +928,7 @@ func (suite *BaseFinderUnitSuite) TestFetchPrevSnapshots_CustomTags() {
checkManifestEntriesMatch( checkManifestEntriesMatch(
t, t,
bb.MergeBases, bb.mergeBases,
manifestData, manifestData,
test.expectedIdxs) test.expectedIdxs)
}) })

View File

@ -39,6 +39,6 @@ type (
ctx context.Context, ctx context.Context,
reasons []kopia.Reason, reasons []kopia.Reason,
tags map[string]string, tags map[string]string,
) (kopia.BackupBases, error) ) ([]kopia.ManifestEntry, error)
} }
) )

View File

@ -19,6 +19,7 @@ import (
"github.com/alcionai/corso/src/internal/data" "github.com/alcionai/corso/src/internal/data"
"github.com/alcionai/corso/src/internal/diagnostics" "github.com/alcionai/corso/src/internal/diagnostics"
"github.com/alcionai/corso/src/internal/observe" "github.com/alcionai/corso/src/internal/observe"
"github.com/alcionai/corso/src/internal/operations/inject"
"github.com/alcionai/corso/src/internal/stats" "github.com/alcionai/corso/src/internal/stats"
"github.com/alcionai/corso/src/pkg/backup/details" "github.com/alcionai/corso/src/pkg/backup/details"
"github.com/alcionai/corso/src/pkg/control/repository" "github.com/alcionai/corso/src/pkg/control/repository"
@ -616,6 +617,10 @@ func (w Wrapper) FetchPrevSnapshotManifests(
return fetchPrevSnapshotManifests(ctx, w.c, reasons, tags), nil return fetchPrevSnapshotManifests(ctx, w.c, reasons, tags), nil
} }
func (w Wrapper) NewBaseFinder(bg inject.GetBackuper) (*baseFinder, error) {
return newBaseFinder(w.c, bg)
}
func isErrEntryNotFound(err error) bool { func isErrEntryNotFound(err error) bool {
// Calling Child on a directory may return this. // Calling Child on a directory may return this.
if errors.Is(err, fs.ErrEntryNotFound) { if errors.Is(err, fs.ErrEntryNotFound) {

View File

@ -290,9 +290,24 @@ func (op *BackupOperation) do(
// should always be 1, since backups are 1:1 with resourceOwners. // should always be 1, since backups are 1:1 with resourceOwners.
opStats.resourceCount = 1 opStats.resourceCount = 1
kbf, err := op.kopia.NewBaseFinder(op.store)
if err != nil {
return nil, clues.Stack(err)
}
type baseFinder struct {
kinject.BaseFinder
kinject.RestoreProducer
}
bf := baseFinder{
BaseFinder: kbf,
RestoreProducer: op.kopia,
}
mans, mdColls, canUseMetaData, err := produceManifestsAndMetadata( mans, mdColls, canUseMetaData, err := produceManifestsAndMetadata(
ctx, ctx,
op.kopia, bf,
op.store, op.store,
reasons, fallbackReasons, reasons, fallbackReasons,
op.account.ID(), op.account.ID(),
@ -467,7 +482,7 @@ func consumeBackupCollections(
bc kinject.BackupConsumer, bc kinject.BackupConsumer,
tenantID string, tenantID string,
reasons []kopia.Reason, reasons []kopia.Reason,
mans []*kopia.ManifestEntry, mans []kopia.ManifestEntry,
cs []data.BackupCollection, cs []data.BackupCollection,
pmr prefixmatcher.StringSetReader, pmr prefixmatcher.StringSetReader,
backupID model.StableID, backupID model.StableID,
@ -652,7 +667,7 @@ func getNewPathRefs(
func lastCompleteBackups( func lastCompleteBackups(
ctx context.Context, ctx context.Context,
ms *store.Wrapper, ms *store.Wrapper,
mans []*kopia.ManifestEntry, mans []kopia.ManifestEntry,
) (map[string]*backup.Backup, int, error) { ) (map[string]*backup.Backup, int, error) {
var ( var (
oldestVersion = version.NoBackup oldestVersion = version.NoBackup
@ -703,7 +718,7 @@ func mergeDetails(
ctx context.Context, ctx context.Context,
ms *store.Wrapper, ms *store.Wrapper,
detailsStore streamstore.Streamer, detailsStore streamstore.Streamer,
mans []*kopia.ManifestEntry, mans []kopia.ManifestEntry,
dataFromBackup kopia.DetailsMergeInfoer, dataFromBackup kopia.DetailsMergeInfoer,
deets *details.Builder, deets *details.Builder,
writeStats *kopia.BackupStats, writeStats *kopia.BackupStats,

View File

@ -533,12 +533,12 @@ func (suite *BackupOpUnitSuite) TestBackupOperation_ConsumeBackupDataCollections
table := []struct { table := []struct {
name string name string
inputMan []*kopia.ManifestEntry inputMan []kopia.ManifestEntry
expected []kopia.IncrementalBase expected []kopia.IncrementalBase
}{ }{
{ {
name: "SingleManifestSingleReason", name: "SingleManifestSingleReason",
inputMan: []*kopia.ManifestEntry{ inputMan: []kopia.ManifestEntry{
{ {
Manifest: manifest1, Manifest: manifest1,
Reasons: []kopia.Reason{ Reasons: []kopia.Reason{
@ -557,7 +557,7 @@ func (suite *BackupOpUnitSuite) TestBackupOperation_ConsumeBackupDataCollections
}, },
{ {
name: "SingleManifestMultipleReasons", name: "SingleManifestMultipleReasons",
inputMan: []*kopia.ManifestEntry{ inputMan: []kopia.ManifestEntry{
{ {
Manifest: manifest1, Manifest: manifest1,
Reasons: []kopia.Reason{ Reasons: []kopia.Reason{
@ -578,7 +578,7 @@ func (suite *BackupOpUnitSuite) TestBackupOperation_ConsumeBackupDataCollections
}, },
{ {
name: "MultipleManifestsMultipleReasons", name: "MultipleManifestsMultipleReasons",
inputMan: []*kopia.ManifestEntry{ inputMan: []kopia.ManifestEntry{
{ {
Manifest: manifest1, Manifest: manifest1,
Reasons: []kopia.Reason{ Reasons: []kopia.Reason{
@ -731,7 +731,7 @@ func (suite *BackupOpUnitSuite) TestBackupOperation_MergeBackupDetails_AddsItems
name string name string
populatedModels map[model.StableID]backup.Backup populatedModels map[model.StableID]backup.Backup
populatedDetails map[string]*details.Details populatedDetails map[string]*details.Details
inputMans []*kopia.ManifestEntry inputMans []kopia.ManifestEntry
mdm *mockDetailsMergeInfoer mdm *mockDetailsMergeInfoer
errCheck assert.ErrorAssertionFunc errCheck assert.ErrorAssertionFunc
@ -758,7 +758,7 @@ func (suite *BackupOpUnitSuite) TestBackupOperation_MergeBackupDetails_AddsItems
return res return res
}(), }(),
inputMans: []*kopia.ManifestEntry{ inputMans: []kopia.ManifestEntry{
{ {
Manifest: makeManifest(suite.T(), "foo", ""), Manifest: makeManifest(suite.T(), "foo", ""),
Reasons: []kopia.Reason{ Reasons: []kopia.Reason{
@ -776,7 +776,7 @@ func (suite *BackupOpUnitSuite) TestBackupOperation_MergeBackupDetails_AddsItems
return res return res
}(), }(),
inputMans: []*kopia.ManifestEntry{ inputMans: []kopia.ManifestEntry{
{ {
Manifest: makeManifest(suite.T(), backup1.ID, ""), Manifest: makeManifest(suite.T(), backup1.ID, ""),
Reasons: []kopia.Reason{ Reasons: []kopia.Reason{
@ -803,7 +803,7 @@ func (suite *BackupOpUnitSuite) TestBackupOperation_MergeBackupDetails_AddsItems
return res return res
}(), }(),
inputMans: []*kopia.ManifestEntry{ inputMans: []kopia.ManifestEntry{
{ {
Manifest: makeManifest(suite.T(), backup1.ID, ""), Manifest: makeManifest(suite.T(), backup1.ID, ""),
Reasons: []kopia.Reason{ Reasons: []kopia.Reason{
@ -833,7 +833,7 @@ func (suite *BackupOpUnitSuite) TestBackupOperation_MergeBackupDetails_AddsItems
return res return res
}(), }(),
inputMans: []*kopia.ManifestEntry{ inputMans: []kopia.ManifestEntry{
{ {
Manifest: makeManifest(suite.T(), backup1.ID, ""), Manifest: makeManifest(suite.T(), backup1.ID, ""),
Reasons: []kopia.Reason{ Reasons: []kopia.Reason{
@ -869,7 +869,7 @@ func (suite *BackupOpUnitSuite) TestBackupOperation_MergeBackupDetails_AddsItems
return res return res
}(), }(),
inputMans: []*kopia.ManifestEntry{ inputMans: []kopia.ManifestEntry{
{ {
Manifest: makeManifest(suite.T(), backup1.ID, ""), Manifest: makeManifest(suite.T(), backup1.ID, ""),
Reasons: []kopia.Reason{ Reasons: []kopia.Reason{
@ -931,7 +931,7 @@ func (suite *BackupOpUnitSuite) TestBackupOperation_MergeBackupDetails_AddsItems
return res return res
}(), }(),
inputMans: []*kopia.ManifestEntry{ inputMans: []kopia.ManifestEntry{
{ {
Manifest: makeManifest(suite.T(), backup1.ID, ""), Manifest: makeManifest(suite.T(), backup1.ID, ""),
Reasons: []kopia.Reason{ Reasons: []kopia.Reason{
@ -961,7 +961,7 @@ func (suite *BackupOpUnitSuite) TestBackupOperation_MergeBackupDetails_AddsItems
return res return res
}(), }(),
inputMans: []*kopia.ManifestEntry{ inputMans: []kopia.ManifestEntry{
{ {
Manifest: makeManifest(suite.T(), backup1.ID, ""), Manifest: makeManifest(suite.T(), backup1.ID, ""),
Reasons: []kopia.Reason{ Reasons: []kopia.Reason{
@ -994,7 +994,7 @@ func (suite *BackupOpUnitSuite) TestBackupOperation_MergeBackupDetails_AddsItems
return res return res
}(), }(),
inputMans: []*kopia.ManifestEntry{ inputMans: []kopia.ManifestEntry{
{ {
Manifest: makeManifest(suite.T(), backup1.ID, ""), Manifest: makeManifest(suite.T(), backup1.ID, ""),
Reasons: []kopia.Reason{ Reasons: []kopia.Reason{
@ -1027,7 +1027,7 @@ func (suite *BackupOpUnitSuite) TestBackupOperation_MergeBackupDetails_AddsItems
return res return res
}(), }(),
inputMans: []*kopia.ManifestEntry{ inputMans: []kopia.ManifestEntry{
{ {
Manifest: makeManifest(suite.T(), backup1.ID, ""), Manifest: makeManifest(suite.T(), backup1.ID, ""),
Reasons: []kopia.Reason{ Reasons: []kopia.Reason{
@ -1061,7 +1061,7 @@ func (suite *BackupOpUnitSuite) TestBackupOperation_MergeBackupDetails_AddsItems
return res return res
}(), }(),
inputMans: []*kopia.ManifestEntry{ inputMans: []kopia.ManifestEntry{
{ {
Manifest: makeManifest(suite.T(), backup1.ID, ""), Manifest: makeManifest(suite.T(), backup1.ID, ""),
Reasons: []kopia.Reason{ Reasons: []kopia.Reason{
@ -1095,7 +1095,7 @@ func (suite *BackupOpUnitSuite) TestBackupOperation_MergeBackupDetails_AddsItems
return res return res
}(), }(),
inputMans: []*kopia.ManifestEntry{ inputMans: []kopia.ManifestEntry{
{ {
Manifest: makeManifest(suite.T(), backup1.ID, ""), Manifest: makeManifest(suite.T(), backup1.ID, ""),
Reasons: []kopia.Reason{ Reasons: []kopia.Reason{
@ -1146,7 +1146,7 @@ func (suite *BackupOpUnitSuite) TestBackupOperation_MergeBackupDetails_AddsItems
return res return res
}(), }(),
inputMans: []*kopia.ManifestEntry{ inputMans: []kopia.ManifestEntry{
{ {
Manifest: makeManifest(suite.T(), backup1.ID, ""), Manifest: makeManifest(suite.T(), backup1.ID, ""),
Reasons: []kopia.Reason{ Reasons: []kopia.Reason{
@ -1258,7 +1258,7 @@ func (suite *BackupOpUnitSuite) TestBackupOperation_MergeBackupDetails_AddsFolde
Category: itemPath1.Category(), Category: itemPath1.Category(),
} }
inputMans = []*kopia.ManifestEntry{ inputMans = []kopia.ManifestEntry{
{ {
Manifest: makeManifest(t, backup1.ID, ""), Manifest: makeManifest(t, backup1.ID, ""),
Reasons: []kopia.Reason{ Reasons: []kopia.Reason{

View File

@ -19,16 +19,8 @@ import (
"github.com/alcionai/corso/src/pkg/path" "github.com/alcionai/corso/src/pkg/path"
) )
type manifestFetcher interface {
FetchPrevSnapshotManifests(
ctx context.Context,
reasons []kopia.Reason,
tags map[string]string,
) ([]*kopia.ManifestEntry, error)
}
type manifestRestorer interface { type manifestRestorer interface {
manifestFetcher inject.BaseFinder
inject.RestoreProducer inject.RestoreProducer
} }
@ -47,14 +39,14 @@ func produceManifestsAndMetadata(
reasons, fallbackReasons []kopia.Reason, reasons, fallbackReasons []kopia.Reason,
tenantID string, tenantID string,
getMetadata bool, getMetadata bool,
) ([]*kopia.ManifestEntry, []data.RestoreCollection, bool, error) { ) ([]kopia.ManifestEntry, []data.RestoreCollection, bool, error) {
var ( var (
tags = map[string]string{kopia.TagBackupCategory: ""} tags = map[string]string{kopia.TagBackupCategory: ""}
metadataFiles = graph.AllMetadataFileNames() metadataFiles = graph.AllMetadataFileNames()
collections []data.RestoreCollection collections []data.RestoreCollection
) )
ms, err := mr.FetchPrevSnapshotManifests(ctx, reasons, tags) ms, err := mr.FindBases(ctx, reasons, tags)
if err != nil { if err != nil {
return nil, nil, false, clues.Wrap(err, "looking up prior snapshots") return nil, nil, false, clues.Wrap(err, "looking up prior snapshots")
} }
@ -70,7 +62,7 @@ func produceManifestsAndMetadata(
return ms, nil, false, nil return ms, nil, false, nil
} }
fbms, err := mr.FetchPrevSnapshotManifests(ctx, fallbackReasons, tags) fbms, err := mr.FindBases(ctx, fallbackReasons, tags)
if err != nil { if err != nil {
return nil, nil, false, clues.Wrap(err, "looking up prior snapshots under alternate id") return nil, nil, false, clues.Wrap(err, "looking up prior snapshots under alternate id")
} }
@ -177,9 +169,9 @@ func produceManifestsAndMetadata(
// 3. If mans has no entry for a reason, look for both complete and incomplete fallbacks. // 3. If mans has no entry for a reason, look for both complete and incomplete fallbacks.
func unionManifests( func unionManifests(
reasons []kopia.Reason, reasons []kopia.Reason,
mans []*kopia.ManifestEntry, mans []kopia.ManifestEntry,
fallback []*kopia.ManifestEntry, fallback []kopia.ManifestEntry,
) []*kopia.ManifestEntry { ) []kopia.ManifestEntry {
if len(fallback) == 0 { if len(fallback) == 0 {
return mans return mans
} }
@ -203,7 +195,9 @@ func unionManifests(
} }
// track the manifests that were collected with the current lookup // track the manifests that were collected with the current lookup
for _, m := range mans { for i := range mans {
m := &mans[i]
for _, r := range m.Reasons { for _, r := range m.Reasons {
k := r.Service.String() + r.Category.String() k := r.Service.String() + r.Category.String()
t := tups[k] t := tups[k]
@ -219,7 +213,8 @@ func unionManifests(
} }
// backfill from the fallback where necessary // backfill from the fallback where necessary
for _, m := range fallback { for i := range fallback {
m := &fallback[i]
useReasons := []kopia.Reason{} useReasons := []kopia.Reason{}
for _, r := range m.Reasons { for _, r := range m.Reasons {
@ -250,15 +245,15 @@ func unionManifests(
} }
// collect the results into a single slice of manifests // collect the results into a single slice of manifests
ms := map[string]*kopia.ManifestEntry{} ms := map[string]kopia.ManifestEntry{}
for _, m := range tups { for _, m := range tups {
if m.complete != nil { if m.complete != nil {
ms[string(m.complete.ID)] = m.complete ms[string(m.complete.ID)] = *m.complete
} }
if m.incomplete != nil { if m.incomplete != nil {
ms[string(m.incomplete.ID)] = m.incomplete ms[string(m.incomplete.ID)] = *m.incomplete
} }
} }
@ -269,7 +264,7 @@ func unionManifests(
// of manifests, that each manifest's Reason (owner, service, category) is only // of manifests, that each manifest's Reason (owner, service, category) is only
// included once. If a reason is duplicated by any two manifests, an error is // included once. If a reason is duplicated by any two manifests, an error is
// returned. // returned.
func verifyDistinctBases(ctx context.Context, mans []*kopia.ManifestEntry) error { func verifyDistinctBases(ctx context.Context, mans []kopia.ManifestEntry) error {
reasons := map[string]manifest.ID{} reasons := map[string]manifest.ID{}
for _, man := range mans { for _, man := range mans {
@ -303,7 +298,7 @@ func verifyDistinctBases(ctx context.Context, mans []*kopia.ManifestEntry) error
func collectMetadata( func collectMetadata(
ctx context.Context, ctx context.Context,
r inject.RestoreProducer, r inject.RestoreProducer,
man *kopia.ManifestEntry, man kopia.ManifestEntry,
fileNames []string, fileNames []string,
tenantID string, tenantID string,
errs *fault.Bus, errs *fault.Bus,

View File

@ -27,16 +27,16 @@ import (
type mockManifestRestorer struct { type mockManifestRestorer struct {
mockRestoreProducer mockRestoreProducer
mans []*kopia.ManifestEntry mans []kopia.ManifestEntry
mrErr error // err varname already claimed by mockRestoreProducer mrErr error // err varname already claimed by mockRestoreProducer
} }
func (mmr mockManifestRestorer) FetchPrevSnapshotManifests( func (mmr mockManifestRestorer) FindBases(
ctx context.Context, ctx context.Context,
reasons []kopia.Reason, reasons []kopia.Reason,
tags map[string]string, tags map[string]string,
) ([]*kopia.ManifestEntry, error) { ) ([]kopia.ManifestEntry, error) {
mans := map[string]*kopia.ManifestEntry{} mans := map[string]kopia.ManifestEntry{}
for _, r := range reasons { for _, r := range reasons {
for _, m := range mmr.mans { for _, m := range mmr.mans {
@ -49,10 +49,6 @@ func (mmr mockManifestRestorer) FetchPrevSnapshotManifests(
} }
} }
if len(mans) == 0 && len(reasons) == 0 {
return mmr.mans, mmr.mrErr
}
return maps.Values(mans), mmr.mrErr return maps.Values(mans), mmr.mrErr
} }
@ -247,7 +243,7 @@ func (suite *OperationsManifestsUnitSuite) TestCollectMetadata() {
mr := mockRestoreProducer{err: test.expectErr} mr := mockRestoreProducer{err: test.expectErr}
mr.buildRestoreFunc(t, test.manID, paths) mr.buildRestoreFunc(t, test.manID, paths)
man := &kopia.ManifestEntry{ man := kopia.ManifestEntry{
Manifest: &snapshot.Manifest{ID: manifest.ID(test.manID)}, Manifest: &snapshot.Manifest{ID: manifest.ID(test.manID)},
Reasons: test.reasons, Reasons: test.reasons,
} }
@ -263,12 +259,12 @@ func (suite *OperationsManifestsUnitSuite) TestVerifyDistinctBases() {
table := []struct { table := []struct {
name string name string
mans []*kopia.ManifestEntry mans []kopia.ManifestEntry
expect assert.ErrorAssertionFunc expect assert.ErrorAssertionFunc
}{ }{
{ {
name: "one manifest, one reason", name: "one manifest, one reason",
mans: []*kopia.ManifestEntry{ mans: []kopia.ManifestEntry{
{ {
Manifest: &snapshot.Manifest{}, Manifest: &snapshot.Manifest{},
Reasons: []kopia.Reason{ Reasons: []kopia.Reason{
@ -284,7 +280,7 @@ func (suite *OperationsManifestsUnitSuite) TestVerifyDistinctBases() {
}, },
{ {
name: "one incomplete manifest", name: "one incomplete manifest",
mans: []*kopia.ManifestEntry{ mans: []kopia.ManifestEntry{
{ {
Manifest: &snapshot.Manifest{IncompleteReason: "ir"}, Manifest: &snapshot.Manifest{IncompleteReason: "ir"},
}, },
@ -293,7 +289,7 @@ func (suite *OperationsManifestsUnitSuite) TestVerifyDistinctBases() {
}, },
{ {
name: "one manifest, multiple reasons", name: "one manifest, multiple reasons",
mans: []*kopia.ManifestEntry{ mans: []kopia.ManifestEntry{
{ {
Manifest: &snapshot.Manifest{}, Manifest: &snapshot.Manifest{},
Reasons: []kopia.Reason{ Reasons: []kopia.Reason{
@ -314,7 +310,7 @@ func (suite *OperationsManifestsUnitSuite) TestVerifyDistinctBases() {
}, },
{ {
name: "one manifest, duplicate reasons", name: "one manifest, duplicate reasons",
mans: []*kopia.ManifestEntry{ mans: []kopia.ManifestEntry{
{ {
Manifest: &snapshot.Manifest{}, Manifest: &snapshot.Manifest{},
Reasons: []kopia.Reason{ Reasons: []kopia.Reason{
@ -335,7 +331,7 @@ func (suite *OperationsManifestsUnitSuite) TestVerifyDistinctBases() {
}, },
{ {
name: "two manifests, non-overlapping reasons", name: "two manifests, non-overlapping reasons",
mans: []*kopia.ManifestEntry{ mans: []kopia.ManifestEntry{
{ {
Manifest: &snapshot.Manifest{}, Manifest: &snapshot.Manifest{},
Reasons: []kopia.Reason{ Reasons: []kopia.Reason{
@ -361,7 +357,7 @@ func (suite *OperationsManifestsUnitSuite) TestVerifyDistinctBases() {
}, },
{ {
name: "two manifests, overlapping reasons", name: "two manifests, overlapping reasons",
mans: []*kopia.ManifestEntry{ mans: []kopia.ManifestEntry{
{ {
Manifest: &snapshot.Manifest{}, Manifest: &snapshot.Manifest{},
Reasons: []kopia.Reason{ Reasons: []kopia.Reason{
@ -387,7 +383,7 @@ func (suite *OperationsManifestsUnitSuite) TestVerifyDistinctBases() {
}, },
{ {
name: "two manifests, overlapping reasons, one snapshot incomplete", name: "two manifests, overlapping reasons, one snapshot incomplete",
mans: []*kopia.ManifestEntry{ mans: []kopia.ManifestEntry{
{ {
Manifest: &snapshot.Manifest{}, Manifest: &snapshot.Manifest{},
Reasons: []kopia.Reason{ Reasons: []kopia.Reason{
@ -430,13 +426,13 @@ func (suite *OperationsManifestsUnitSuite) TestProduceManifestsAndMetadata() {
did = "detailsid" did = "detailsid"
) )
makeMan := func(pct path.CategoryType, id, incmpl, bid string) *kopia.ManifestEntry { makeMan := func(pct path.CategoryType, id, incmpl, bid string) kopia.ManifestEntry {
tags := map[string]string{} tags := map[string]string{}
if len(bid) > 0 { if len(bid) > 0 {
tags = map[string]string{"tag:" + kopia.TagBackupID: bid} tags = map[string]string{"tag:" + kopia.TagBackupID: bid}
} }
return &kopia.ManifestEntry{ return kopia.ManifestEntry{
Manifest: &snapshot.Manifest{ Manifest: &snapshot.Manifest{
ID: manifest.ID(id), ID: manifest.ID(id),
IncompleteReason: incmpl, IncompleteReason: incmpl,
@ -456,7 +452,6 @@ func (suite *OperationsManifestsUnitSuite) TestProduceManifestsAndMetadata() {
name string name string
mr mockManifestRestorer mr mockManifestRestorer
gb mockGetBackuper gb mockGetBackuper
reasons []kopia.Reason
getMeta bool getMeta bool
assertErr assert.ErrorAssertionFunc assertErr assert.ErrorAssertionFunc
assertB assert.BoolAssertionFunc assertB assert.BoolAssertionFunc
@ -467,10 +462,9 @@ func (suite *OperationsManifestsUnitSuite) TestProduceManifestsAndMetadata() {
name: "don't get metadata, no mans", name: "don't get metadata, no mans",
mr: mockManifestRestorer{ mr: mockManifestRestorer{
mockRestoreProducer: mockRestoreProducer{}, mockRestoreProducer: mockRestoreProducer{},
mans: []*kopia.ManifestEntry{}, mans: []kopia.ManifestEntry{},
}, },
gb: mockGetBackuper{detailsID: did}, gb: mockGetBackuper{detailsID: did},
reasons: []kopia.Reason{},
getMeta: false, getMeta: false,
assertErr: assert.NoError, assertErr: assert.NoError,
assertB: assert.False, assertB: assert.False,
@ -480,10 +474,9 @@ func (suite *OperationsManifestsUnitSuite) TestProduceManifestsAndMetadata() {
name: "don't get metadata", name: "don't get metadata",
mr: mockManifestRestorer{ mr: mockManifestRestorer{
mockRestoreProducer: mockRestoreProducer{}, mockRestoreProducer: mockRestoreProducer{},
mans: []*kopia.ManifestEntry{makeMan(path.EmailCategory, "id1", "", "")}, mans: []kopia.ManifestEntry{makeMan(path.EmailCategory, "id1", "", "")},
}, },
gb: mockGetBackuper{detailsID: did}, gb: mockGetBackuper{detailsID: did},
reasons: []kopia.Reason{},
getMeta: false, getMeta: false,
assertErr: assert.NoError, assertErr: assert.NoError,
assertB: assert.False, assertB: assert.False,
@ -493,10 +486,9 @@ func (suite *OperationsManifestsUnitSuite) TestProduceManifestsAndMetadata() {
name: "don't get metadata, incomplete manifest", name: "don't get metadata, incomplete manifest",
mr: mockManifestRestorer{ mr: mockManifestRestorer{
mockRestoreProducer: mockRestoreProducer{}, mockRestoreProducer: mockRestoreProducer{},
mans: []*kopia.ManifestEntry{makeMan(path.EmailCategory, "id1", "ir", "")}, mans: []kopia.ManifestEntry{makeMan(path.EmailCategory, "id1", "ir", "")},
}, },
gb: mockGetBackuper{detailsID: did}, gb: mockGetBackuper{detailsID: did},
reasons: []kopia.Reason{},
getMeta: false, getMeta: false,
assertErr: assert.NoError, assertErr: assert.NoError,
assertB: assert.False, assertB: assert.False,
@ -509,7 +501,6 @@ func (suite *OperationsManifestsUnitSuite) TestProduceManifestsAndMetadata() {
mrErr: assert.AnError, mrErr: assert.AnError,
}, },
gb: mockGetBackuper{detailsID: did}, gb: mockGetBackuper{detailsID: did},
reasons: []kopia.Reason{},
getMeta: true, getMeta: true,
assertErr: assert.Error, assertErr: assert.Error,
assertB: assert.False, assertB: assert.False,
@ -519,13 +510,12 @@ func (suite *OperationsManifestsUnitSuite) TestProduceManifestsAndMetadata() {
name: "verify distinct bases fails", name: "verify distinct bases fails",
mr: mockManifestRestorer{ mr: mockManifestRestorer{
mockRestoreProducer: mockRestoreProducer{}, mockRestoreProducer: mockRestoreProducer{},
mans: []*kopia.ManifestEntry{ mans: []kopia.ManifestEntry{
makeMan(path.EmailCategory, "id1", "", ""), makeMan(path.EmailCategory, "id1", "", ""),
makeMan(path.EmailCategory, "id2", "", ""), makeMan(path.EmailCategory, "id2", "", ""),
}, },
}, },
gb: mockGetBackuper{detailsID: did}, gb: mockGetBackuper{detailsID: did},
reasons: []kopia.Reason{},
getMeta: true, getMeta: true,
assertErr: assert.NoError, // No error, even though verify failed. assertErr: assert.NoError, // No error, even though verify failed.
assertB: assert.False, assertB: assert.False,
@ -535,10 +525,9 @@ func (suite *OperationsManifestsUnitSuite) TestProduceManifestsAndMetadata() {
name: "no manifests", name: "no manifests",
mr: mockManifestRestorer{ mr: mockManifestRestorer{
mockRestoreProducer: mockRestoreProducer{}, mockRestoreProducer: mockRestoreProducer{},
mans: []*kopia.ManifestEntry{}, mans: []kopia.ManifestEntry{},
}, },
gb: mockGetBackuper{detailsID: did}, gb: mockGetBackuper{detailsID: did},
reasons: []kopia.Reason{},
getMeta: true, getMeta: true,
assertErr: assert.NoError, assertErr: assert.NoError,
assertB: assert.True, assertB: assert.True,
@ -548,13 +537,12 @@ func (suite *OperationsManifestsUnitSuite) TestProduceManifestsAndMetadata() {
name: "only incomplete manifests", name: "only incomplete manifests",
mr: mockManifestRestorer{ mr: mockManifestRestorer{
mockRestoreProducer: mockRestoreProducer{}, mockRestoreProducer: mockRestoreProducer{},
mans: []*kopia.ManifestEntry{ mans: []kopia.ManifestEntry{
makeMan(path.EmailCategory, "id1", "ir", ""), makeMan(path.EmailCategory, "id1", "ir", ""),
makeMan(path.ContactsCategory, "id2", "ir", ""), makeMan(path.ContactsCategory, "id2", "ir", ""),
}, },
}, },
gb: mockGetBackuper{detailsID: did}, gb: mockGetBackuper{detailsID: did},
reasons: []kopia.Reason{},
getMeta: true, getMeta: true,
assertErr: assert.NoError, assertErr: assert.NoError,
assertB: assert.True, assertB: assert.True,
@ -568,10 +556,9 @@ func (suite *OperationsManifestsUnitSuite) TestProduceManifestsAndMetadata() {
"id": {data.NotFoundRestoreCollection{Collection: mockColl{id: "id_coll"}}}, "id": {data.NotFoundRestoreCollection{Collection: mockColl{id: "id_coll"}}},
}, },
}, },
mans: []*kopia.ManifestEntry{makeMan(path.EmailCategory, "id", "", "")}, mans: []kopia.ManifestEntry{makeMan(path.EmailCategory, "id", "", "")},
}, },
gb: mockGetBackuper{detailsID: did}, gb: mockGetBackuper{detailsID: did},
reasons: []kopia.Reason{},
getMeta: true, getMeta: true,
assertErr: assert.Error, assertErr: assert.Error,
assertB: assert.False, assertB: assert.False,
@ -581,10 +568,9 @@ func (suite *OperationsManifestsUnitSuite) TestProduceManifestsAndMetadata() {
name: "backup missing details id", name: "backup missing details id",
mr: mockManifestRestorer{ mr: mockManifestRestorer{
mockRestoreProducer: mockRestoreProducer{}, mockRestoreProducer: mockRestoreProducer{},
mans: []*kopia.ManifestEntry{makeMan(path.EmailCategory, "id1", "", "bid")}, mans: []kopia.ManifestEntry{makeMan(path.EmailCategory, "id1", "", "bid")},
}, },
gb: mockGetBackuper{}, gb: mockGetBackuper{},
reasons: []kopia.Reason{},
getMeta: true, getMeta: true,
assertErr: assert.NoError, assertErr: assert.NoError,
assertB: assert.False, assertB: assert.False,
@ -598,13 +584,12 @@ func (suite *OperationsManifestsUnitSuite) TestProduceManifestsAndMetadata() {
"incmpl_id": {data.NotFoundRestoreCollection{Collection: mockColl{id: "incmpl_id_coll"}}}, "incmpl_id": {data.NotFoundRestoreCollection{Collection: mockColl{id: "incmpl_id_coll"}}},
}, },
}, },
mans: []*kopia.ManifestEntry{ mans: []kopia.ManifestEntry{
makeMan(path.EmailCategory, "id", "", "bid"), makeMan(path.EmailCategory, "id", "", "bid"),
makeMan(path.EmailCategory, "incmpl_id", "ir", ""), makeMan(path.EmailCategory, "incmpl_id", "ir", ""),
}, },
}, },
gb: mockGetBackuper{detailsID: did}, gb: mockGetBackuper{detailsID: did},
reasons: []kopia.Reason{},
getMeta: true, getMeta: true,
assertErr: assert.NoError, assertErr: assert.NoError,
assertB: assert.True, assertB: assert.True,
@ -618,10 +603,9 @@ func (suite *OperationsManifestsUnitSuite) TestProduceManifestsAndMetadata() {
"id": {data.NotFoundRestoreCollection{Collection: mockColl{id: "id_coll"}}}, "id": {data.NotFoundRestoreCollection{Collection: mockColl{id: "id_coll"}}},
}, },
}, },
mans: []*kopia.ManifestEntry{makeMan(path.EmailCategory, "id", "", "bid")}, mans: []kopia.ManifestEntry{makeMan(path.EmailCategory, "id", "", "bid")},
}, },
gb: mockGetBackuper{detailsID: did}, gb: mockGetBackuper{detailsID: did},
reasons: []kopia.Reason{},
getMeta: true, getMeta: true,
assertErr: assert.NoError, assertErr: assert.NoError,
assertB: assert.True, assertB: assert.True,
@ -636,13 +620,12 @@ func (suite *OperationsManifestsUnitSuite) TestProduceManifestsAndMetadata() {
"contact": {data.NotFoundRestoreCollection{Collection: mockColl{id: "contact_coll"}}}, "contact": {data.NotFoundRestoreCollection{Collection: mockColl{id: "contact_coll"}}},
}, },
}, },
mans: []*kopia.ManifestEntry{ mans: []kopia.ManifestEntry{
makeMan(path.EmailCategory, "mail", "", "bid"), makeMan(path.EmailCategory, "mail", "", "bid"),
makeMan(path.ContactsCategory, "contact", "", "bid"), makeMan(path.ContactsCategory, "contact", "", "bid"),
}, },
}, },
gb: mockGetBackuper{detailsID: did}, gb: mockGetBackuper{detailsID: did},
reasons: []kopia.Reason{},
getMeta: true, getMeta: true,
assertErr: assert.NoError, assertErr: assert.NoError,
assertB: assert.True, assertB: assert.True,
@ -655,10 +638,9 @@ func (suite *OperationsManifestsUnitSuite) TestProduceManifestsAndMetadata() {
name: "error collecting metadata", name: "error collecting metadata",
mr: mockManifestRestorer{ mr: mockManifestRestorer{
mockRestoreProducer: mockRestoreProducer{err: assert.AnError}, mockRestoreProducer: mockRestoreProducer{err: assert.AnError},
mans: []*kopia.ManifestEntry{makeMan(path.EmailCategory, "id1", "", "bid")}, mans: []kopia.ManifestEntry{makeMan(path.EmailCategory, "id1", "", "bid")},
}, },
gb: mockGetBackuper{detailsID: did}, gb: mockGetBackuper{detailsID: did},
reasons: []kopia.Reason{},
getMeta: true, getMeta: true,
assertErr: assert.Error, assertErr: assert.Error,
assertB: assert.False, assertB: assert.False,
@ -677,7 +659,7 @@ func (suite *OperationsManifestsUnitSuite) TestProduceManifestsAndMetadata() {
ctx, ctx,
&test.mr, &test.mr,
&test.gb, &test.gb,
test.reasons, nil, []kopia.Reason{{ResourceOwner: ro}}, nil,
tid, tid,
test.getMeta) test.getMeta)
test.assertErr(t, err, clues.ToCore(err)) test.assertErr(t, err, clues.ToCore(err))
@ -739,8 +721,8 @@ func (suite *OperationsManifestsUnitSuite) TestProduceManifestsAndMetadata_fallb
fbIncomplete = "fb_incmpl" fbIncomplete = "fb_incmpl"
) )
makeMan := func(id, incmpl string, reasons []kopia.Reason) *kopia.ManifestEntry { makeMan := func(id, incmpl string, reasons []kopia.Reason) kopia.ManifestEntry {
return &kopia.ManifestEntry{ return kopia.ManifestEntry{
Manifest: &snapshot.Manifest{ Manifest: &snapshot.Manifest{
ID: manifest.ID(id), ID: manifest.ID(id),
IncompleteReason: incmpl, IncompleteReason: incmpl,
@ -1005,7 +987,7 @@ func (suite *OperationsManifestsUnitSuite) TestProduceManifestsAndMetadata_fallb
}) })
} }
mans := []*kopia.ManifestEntry{} mans := []kopia.ManifestEntry{}
for _, m := range test.man { for _, m := range test.man {
incomplete := "" incomplete := ""
@ -1027,7 +1009,7 @@ func (suite *OperationsManifestsUnitSuite) TestProduceManifestsAndMetadata_fallb
mr := mockManifestRestorer{mans: mans} mr := mockManifestRestorer{mans: mans}
mans, _, b, err := produceManifestsAndMetadata( gotMans, _, b, err := produceManifestsAndMetadata(
ctx, ctx,
&mr, &mr,
nil, nil,
@ -1040,7 +1022,7 @@ func (suite *OperationsManifestsUnitSuite) TestProduceManifestsAndMetadata_fallb
manIDs := []string{} manIDs := []string{}
for _, m := range mans { for _, m := range gotMans {
manIDs = append(manIDs, string(m.ID)) manIDs = append(manIDs, string(m.ID))
reasons := test.expectReasons[string(m.ID)] reasons := test.expectReasons[string(m.ID)]
@ -1075,12 +1057,12 @@ func (suite *BackupManifestUnitSuite) TestBackupOperation_VerifyDistinctBases()
table := []struct { table := []struct {
name string name string
input []*kopia.ManifestEntry input []kopia.ManifestEntry
errCheck assert.ErrorAssertionFunc errCheck assert.ErrorAssertionFunc
}{ }{
{ {
name: "SingleManifestMultipleReasons", name: "SingleManifestMultipleReasons",
input: []*kopia.ManifestEntry{ input: []kopia.ManifestEntry{
{ {
Manifest: &snapshot.Manifest{ Manifest: &snapshot.Manifest{
ID: "id1", ID: "id1",
@ -1103,7 +1085,7 @@ func (suite *BackupManifestUnitSuite) TestBackupOperation_VerifyDistinctBases()
}, },
{ {
name: "MultipleManifestsDistinctReason", name: "MultipleManifestsDistinctReason",
input: []*kopia.ManifestEntry{ input: []kopia.ManifestEntry{
{ {
Manifest: &snapshot.Manifest{ Manifest: &snapshot.Manifest{
ID: "id1", ID: "id1",
@ -1133,7 +1115,7 @@ func (suite *BackupManifestUnitSuite) TestBackupOperation_VerifyDistinctBases()
}, },
{ {
name: "MultipleManifestsSameReason", name: "MultipleManifestsSameReason",
input: []*kopia.ManifestEntry{ input: []kopia.ManifestEntry{
{ {
Manifest: &snapshot.Manifest{ Manifest: &snapshot.Manifest{
ID: "id1", ID: "id1",
@ -1163,7 +1145,7 @@ func (suite *BackupManifestUnitSuite) TestBackupOperation_VerifyDistinctBases()
}, },
{ {
name: "MultipleManifestsSameReasonOneIncomplete", name: "MultipleManifestsSameReasonOneIncomplete",
input: []*kopia.ManifestEntry{ input: []kopia.ManifestEntry{
{ {
Manifest: &snapshot.Manifest{ Manifest: &snapshot.Manifest{
ID: "id1", ID: "id1",
@ -1250,13 +1232,13 @@ func (suite *BackupManifestUnitSuite) TestBackupOperation_CollectMetadata() {
table := []struct { table := []struct {
name string name string
inputMan *kopia.ManifestEntry inputMan kopia.ManifestEntry
inputFiles []string inputFiles []string
expected []path.Path expected []path.Path
}{ }{
{ {
name: "SingleReasonSingleFile", name: "SingleReasonSingleFile",
inputMan: &kopia.ManifestEntry{ inputMan: kopia.ManifestEntry{
Manifest: &snapshot.Manifest{}, Manifest: &snapshot.Manifest{},
Reasons: []kopia.Reason{ Reasons: []kopia.Reason{
{ {
@ -1271,7 +1253,7 @@ func (suite *BackupManifestUnitSuite) TestBackupOperation_CollectMetadata() {
}, },
{ {
name: "SingleReasonMultipleFiles", name: "SingleReasonMultipleFiles",
inputMan: &kopia.ManifestEntry{ inputMan: kopia.ManifestEntry{
Manifest: &snapshot.Manifest{}, Manifest: &snapshot.Manifest{},
Reasons: []kopia.Reason{ Reasons: []kopia.Reason{
{ {
@ -1286,7 +1268,7 @@ func (suite *BackupManifestUnitSuite) TestBackupOperation_CollectMetadata() {
}, },
{ {
name: "MultipleReasonsMultipleFiles", name: "MultipleReasonsMultipleFiles",
inputMan: &kopia.ManifestEntry{ inputMan: kopia.ManifestEntry{
Manifest: &snapshot.Manifest{}, Manifest: &snapshot.Manifest{},
Reasons: []kopia.Reason{ Reasons: []kopia.Reason{
{ {