From 72482ce5bd173ed5a8a4e9dda393925e24c3196b Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sun, 19 May 2024 20:36:16 +0200 Subject: [PATCH] index: misc cleanups --- internal/index/index_parallel.go | 2 +- internal/index/master_index.go | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/internal/index/index_parallel.go b/internal/index/index_parallel.go index d51d5930f..3d5621a2d 100644 --- a/internal/index/index_parallel.go +++ b/internal/index/index_parallel.go @@ -11,7 +11,7 @@ import ( // ForAllIndexes loads all index files in parallel and calls the given callback. // It is guaranteed that the function is not run concurrently. If the callback // returns an error, this function is cancelled and also returns that error. -func ForAllIndexes(ctx context.Context, lister restic.Lister, repo restic.ListerLoaderUnpacked, +func ForAllIndexes(ctx context.Context, lister restic.Lister, repo restic.LoaderUnpacked, fn func(id restic.ID, index *Index, oldFormat bool, err error) error) error { // decoding an index can take quite some time such that this can be both CPU- or IO-bound diff --git a/internal/index/master_index.go b/internal/index/master_index.go index 17e681411..a5ee40b52 100644 --- a/internal/index/master_index.go +++ b/internal/index/master_index.go @@ -23,12 +23,15 @@ type MasterIndex struct { // NewMasterIndex creates a new master index. func NewMasterIndex() *MasterIndex { + mi := &MasterIndex{pendingBlobs: restic.NewBlobSet()} + mi.clear() + return mi +} + +func (mi *MasterIndex) clear() { // Always add an empty final index, such that MergeFinalIndexes can merge into this. - // Note that removing this index could lead to a race condition in the rare - // situation that only two indexes exist which are saved and merged concurrently. - idx := []*Index{NewIndex()} - idx[0].Finalize() - return &MasterIndex{idx: idx, pendingBlobs: restic.NewBlobSet()} + mi.idx = []*Index{NewIndex()} + mi.idx[0].Finalize() } func (mi *MasterIndex) MarkCompressed() {