Skip to content

Commit

Permalink
feat: forget soft-deletes operations associated with removed snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
garethgeorge committed Dec 2, 2023
1 parent b513b08 commit f3dc7ff
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion internal/oplog/oplog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions internal/orchestrator/forget.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion internal/orchestrator/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f3dc7ff

Please sign in to comment.