mirror of
https://github.com/garethgeorge/backrest.git
synced 2026-09-23 00:15:45 +00:00
feat: forget soft-deletes operations associated with removed snapshots
This commit is contained in:
@@ -71,7 +71,7 @@ func NewOpLog(databasePath string) (*OpLog, error) {
|
||||
|
||||
// Create the buckets if they don't exist
|
||||
for _, bucket := range [][]byte{
|
||||
SystemBucket, OpLogBucket, RepoIndexBucket, PlanIndexBucket, SnapshotIndexBucket,
|
||||
SystemBucket, OpLogBucket, OpLogSoftDeleteBucket, RepoIndexBucket, PlanIndexBucket, SnapshotIndexBucket,
|
||||
} {
|
||||
if _, err := tx.CreateBucketIfNotExists(bucket); err != nil {
|
||||
return fmt.Errorf("creating bucket %s: %s", string(bucket), err)
|
||||
|
||||
@@ -82,6 +82,14 @@ func (t *ForgetTask) Run(ctx context.Context) error {
|
||||
|
||||
for _, forgot := range forgot {
|
||||
if e := t.orchestrator.OpLog.ForEachBySnapshotId(forgot.Id, indexutil.CollectAll(), func(op *v1.Operation) error {
|
||||
if indexOp, ok := op.Op.(*v1.Operation_OperationIndexSnapshot); ok {
|
||||
indexOp.OperationIndexSnapshot.Forgot = true
|
||||
if err := t.orchestrator.OpLog.Update(op); err != nil {
|
||||
return fmt.Errorf("mark index snapshot %v as forgotten: %w", op.Id, err)
|
||||
}
|
||||
}
|
||||
|
||||
// Soft delete the operation (can be recovered if necessary, todo: implement recovery).
|
||||
return t.orchestrator.OpLog.Delete(op.Id)
|
||||
}); e != nil {
|
||||
err = multierror.Append(err, fmt.Errorf("cleanup snapshot %v: %w", forgot.Id, e))
|
||||
|
||||
@@ -119,7 +119,7 @@ func (r *RepoOrchestrator) Forget(ctx context.Context, plan *v1.Plan) ([]*v1.Res
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("get snapshots for repo %v: %w", r.repoConfig.Id, err)
|
||||
}
|
||||
l.Debug("Forget result", zap.Any("result", result))
|
||||
l.Debug("Forget result", zap.Int("forgot", len(result.Remove)), zap.Int("keep", len(result.Keep)))
|
||||
|
||||
var forgotten []*v1.ResticSnapshot
|
||||
for _, snapshot := range result.Remove {
|
||||
|
||||
Reference in New Issue
Block a user