Skip to content

Commit

Permalink
migrate off of recoil
Browse files Browse the repository at this point in the history
  • Loading branch information
garethgeorge committed Feb 1, 2024
1 parent 023e98d commit 8739b7d
Show file tree
Hide file tree
Showing 21 changed files with 522 additions and 267 deletions.
10 changes: 10 additions & 0 deletions internal/oplog/indexutil/indexutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,13 @@ func CollectLastN(lastN int) Collector {
return ids
}
}

func Reversed(collector Collector) Collector {
return func(iter IndexIterator) []int64 {
ids := collector(iter)
for i, j := 0, len(ids)-1; i < j; i, j = i+1, j-1 {
ids[i], ids[j] = ids[j], ids[i]
}
return ids
}
}
4 changes: 4 additions & 0 deletions internal/oplog/oplog.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const (
)

var ErrNotExist = errors.New("operation does not exist")
var ErrStopIteration = errors.New("stop iteration")

var (
SystemBucket = []byte("oplog.system") // system stores metadata
Expand Down Expand Up @@ -373,6 +374,9 @@ func (o *OpLog) forOpsByIds(tx *bolt.Tx, ids []int64, do func(*v1.Operation) err
return err
}
if err := do(op); err != nil {
if err == ErrStopIteration {
break
}
return err
}
}
Expand Down
4 changes: 3 additions & 1 deletion internal/orchestrator/taskprune.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

v1 "github.com/garethgeorge/backrest/gen/go/v1"
"github.com/garethgeorge/backrest/internal/hook"
"github.com/garethgeorge/backrest/internal/oplog"
"github.com/garethgeorge/backrest/internal/oplog/indexutil"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -84,9 +85,10 @@ func (t *PruneTask) shouldRun(now time.Time) (bool, error) {

func (t *PruneTask) getNextPruneTime(repo *RepoOrchestrator, policy *v1.PrunePolicy) (time.Time, error) {
var lastPruneTime time.Time
t.orch.OpLog.ForEachByRepo(t.plan.Repo, indexutil.CollectLastN(100), func(op *v1.Operation) error {
t.orch.OpLog.ForEachByRepo(t.plan.Repo, indexutil.Reversed(indexutil.CollectAll()), func(op *v1.Operation) error {
if _, ok := op.Op.(*v1.Operation_OperationPrune); ok {
lastPruneTime = time.Unix(0, op.UnixTimeStartMs*int64(time.Millisecond))
return oplog.ErrStopIteration
}
return nil
})
Expand Down
8 changes: 3 additions & 5 deletions internal/orchestrator/taskstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

v1 "github.com/garethgeorge/backrest/gen/go/v1"
"github.com/garethgeorge/backrest/internal/hook"
"github.com/garethgeorge/backrest/internal/oplog"
"github.com/garethgeorge/backrest/internal/oplog/indexutil"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -41,13 +42,10 @@ func (t *StatsTask) Name() string {

func (t *StatsTask) shouldRun() (bool, error) {
var bytesSinceLastStat int64 = -1
if err := t.orch.OpLog.ForEachByRepo(t.plan.Repo, indexutil.CollectLastN(50), func(op *v1.Operation) error {
if err := t.orch.OpLog.ForEachByRepo(t.plan.Repo, indexutil.Reversed(indexutil.CollectAll()), func(op *v1.Operation) error {
if _, ok := op.Op.(*v1.Operation_OperationStats); ok {
bytesSinceLastStat = 0
return oplog.ErrStopIteration
} else if backup, ok := op.Op.(*v1.Operation_OperationBackup); ok && backup.OperationBackup.LastStatus != nil {
if bytesSinceLastStat == -1 {
return nil
}
if summary, ok := backup.OperationBackup.LastStatus.Entry.(*v1.BackupProgressEntry_Summary); ok {
bytesSinceLastStat += summary.Summary.DataAdded
}
Expand Down
Loading

0 comments on commit 8739b7d

Please sign in to comment.