issue 7244: delete incomplete snapshot automatically for kopia uploader

Signed-off-by: Lyndon-Li <lyonghui@vmware.com>
This commit is contained in:
Lyndon-Li
2023-12-22 14:59:27 +08:00
parent ee345cf281
commit 60d2c62c1a
4 changed files with 13 additions and 4 deletions

View File

@@ -0,0 +1 @@
Fix issue #7244. By the end of the upload, check the outstanding incomplete snapshots and delete them by calling ApplyRetentionPolicy

View File

@@ -45,6 +45,7 @@ import (
)
// All function mainly used to make testing more convenient
var applyRetentionPolicyFunc = policy.ApplyRetentionPolicy
var treeForSourceFunc = policy.TreeForSource
var setPolicyFunc = policy.SetPolicy
var saveSnapshotFunc = snapshot.SaveSnapshot
@@ -291,6 +292,11 @@ func SnapshotSource(
return "", 0, errors.Wrapf(err, "Failed to save kopia manifest %v", manifest.ID)
}
_, err = applyRetentionPolicyFunc(ctx, rep, sourceInfo, true)
if err != nil {
return "", 0, errors.Wrapf(err, "Failed to apply kopia retention policy for si %v", sourceInfo)
}
if err = rep.Flush(ctx); err != nil {
return "", 0, errors.Wrapf(err, "Failed to flush kopia repository")
}

View File

@@ -60,6 +60,7 @@ func injectSnapshotFuncs() *snapshotMockes {
repoWriterMock: &repomocks.RepositoryWriter{},
}
applyRetentionPolicyFunc = s.policyMock.ApplyRetentionPolicy
setPolicyFunc = s.policyMock.SetPolicy
treeForSourceFunc = s.policyMock.TreeForSource
loadSnapshotFunc = s.snapshotMock.LoadSnapshot

View File

@@ -19,6 +19,7 @@ package mocks
import (
"context"
"github.com/kopia/kopia/repo/manifest"
"github.com/kopia/kopia/snapshot/policy"
"github.com/stretchr/testify/mock"
@@ -56,15 +57,15 @@ func (_m *Policy) TreeForSource(ctx context.Context, rep repo.Repository, si sna
}
// ApplyRetentionPolicy provides a mock function with given fields: ctx, rep, sourceInfo, reallyDelete
func (_m *Policy) ApplyRetentionPolicy(ctx context.Context, rep repo.RepositoryWriter, sourceInfo snapshot.SourceInfo, reallyDelete bool) ([]*snapshot.Manifest, error) {
func (_m *Policy) ApplyRetentionPolicy(ctx context.Context, rep repo.RepositoryWriter, sourceInfo snapshot.SourceInfo, reallyDelete bool) ([]manifest.ID, error) {
ret := _m.Called(ctx, rep, sourceInfo, reallyDelete)
var r0 []*snapshot.Manifest
if rf, ok := ret.Get(0).(func(context.Context, repo.RepositoryWriter, snapshot.SourceInfo, bool) []*snapshot.Manifest); ok {
var r0 []manifest.ID
if rf, ok := ret.Get(0).(func(context.Context, repo.RepositoryWriter, snapshot.SourceInfo, bool) []manifest.ID); ok {
r0 = rf(ctx, rep, sourceInfo, reallyDelete)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]*snapshot.Manifest)
r0 = ret.Get(0).([]manifest.ID)
}
}