forked from TrueCloudLab/restic
index: misc cleanups
This commit is contained in:
parent
68fa0e0305
commit
72482ce5bd
2 changed files with 9 additions and 6 deletions
|
@ -11,7 +11,7 @@ import (
|
||||||
// ForAllIndexes loads all index files in parallel and calls the given callback.
|
// 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
|
// 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.
|
// 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 {
|
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
|
// decoding an index can take quite some time such that this can be both CPU- or IO-bound
|
||||||
|
|
|
@ -23,12 +23,15 @@ type MasterIndex struct {
|
||||||
|
|
||||||
// NewMasterIndex creates a new master index.
|
// NewMasterIndex creates a new master index.
|
||||||
func NewMasterIndex() *MasterIndex {
|
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.
|
// 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
|
mi.idx = []*Index{NewIndex()}
|
||||||
// situation that only two indexes exist which are saved and merged concurrently.
|
mi.idx[0].Finalize()
|
||||||
idx := []*Index{NewIndex()}
|
|
||||||
idx[0].Finalize()
|
|
||||||
return &MasterIndex{idx: idx, pendingBlobs: restic.NewBlobSet()}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mi *MasterIndex) MarkCompressed() {
|
func (mi *MasterIndex) MarkCompressed() {
|
||||||
|
|
Loading…
Reference in a new issue