forked from TrueCloudLab/restic
repository: add Save method to MasterIndex interface
This commit is contained in:
parent
a77d5c4d11
commit
ed8aa15376
5 changed files with 11 additions and 12 deletions
|
@ -596,10 +596,8 @@ func prune(opts PruneOptions, gopts GlobalOptions, repo restic.Repository, usedB
|
||||||
func writeIndexFiles(gopts GlobalOptions, repo restic.Repository, removePacks restic.IDSet, extraObsolete restic.IDs) (restic.IDSet, error) {
|
func writeIndexFiles(gopts GlobalOptions, repo restic.Repository, removePacks restic.IDSet, extraObsolete restic.IDs) (restic.IDSet, error) {
|
||||||
Verbosef("rebuilding index\n")
|
Verbosef("rebuilding index\n")
|
||||||
|
|
||||||
idx := (repo.Index()).(*repository.MasterIndex)
|
bar := newProgressMax(!gopts.Quiet, 0, "packs processed")
|
||||||
packcount := uint64(len(idx.Packs(removePacks)))
|
obsoleteIndexes, err := repo.Index().Save(gopts.ctx, repo, removePacks, extraObsolete, bar)
|
||||||
bar := newProgressMax(!gopts.Quiet, packcount, "packs processed")
|
|
||||||
obsoleteIndexes, err := idx.Save(gopts.ctx, repo, removePacks, extraObsolete, bar)
|
|
||||||
bar.Done()
|
bar.Done()
|
||||||
return obsoleteIndexes, err
|
return obsoleteIndexes, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -321,7 +321,9 @@ const saveIndexParallelism = 4
|
||||||
// The new index contains the IDs of all known indexes in the "supersedes"
|
// The new index contains the IDs of all known indexes in the "supersedes"
|
||||||
// field. The IDs are also returned in the IDSet obsolete.
|
// field. The IDs are also returned in the IDSet obsolete.
|
||||||
// After calling this function, you should remove the obsolete index files.
|
// After calling this function, you should remove the obsolete index files.
|
||||||
func (mi *MasterIndex) Save(ctx context.Context, repo restic.Repository, packBlacklist restic.IDSet, extraObsolete restic.IDs, p *progress.Counter) (obsolete restic.IDSet, err error) {
|
func (mi *MasterIndex) Save(ctx context.Context, repo restic.SaverUnpacked, packBlacklist restic.IDSet, extraObsolete restic.IDs, p *progress.Counter) (obsolete restic.IDSet, err error) {
|
||||||
|
p.SetMax(uint64(len(mi.Packs(packBlacklist))))
|
||||||
|
|
||||||
mi.idxMutex.Lock()
|
mi.idxMutex.Lock()
|
||||||
defer mi.idxMutex.Unlock()
|
defer mi.idxMutex.Unlock()
|
||||||
|
|
||||||
|
|
|
@ -291,14 +291,12 @@ func BenchmarkMasterIndexLookupMultipleIndexUnknown(b *testing.B) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkMasterIndexLookupParallel(b *testing.B) {
|
func BenchmarkMasterIndexLookupParallel(b *testing.B) {
|
||||||
mIdx := repository.NewMasterIndex()
|
|
||||||
|
|
||||||
for _, numindices := range []int{25, 50, 100} {
|
for _, numindices := range []int{25, 50, 100} {
|
||||||
var lookupBh restic.BlobHandle
|
var lookupBh restic.BlobHandle
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
rng := rand.New(rand.NewSource(0))
|
rng := rand.New(rand.NewSource(0))
|
||||||
mIdx, lookupBh = createRandomMasterIndex(b, rng, numindices, 10000)
|
mIdx, lookupBh := createRandomMasterIndex(b, rng, numindices, 10000)
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
|
|
||||||
name := fmt.Sprintf("known,indices=%d", numindices)
|
name := fmt.Sprintf("known,indices=%d", numindices)
|
||||||
|
@ -361,7 +359,7 @@ func testIndexSave(t *testing.T, version uint) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
obsoletes, err := repo.Index().(*repository.MasterIndex).Save(context.TODO(), repo, nil, nil, nil)
|
obsoletes, err := repo.Index().Save(context.TODO(), repo, nil, nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to save new index: %v", err)
|
t.Fatalf("unable to save new index: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -192,9 +192,7 @@ func rebuildIndex(t *testing.T, repo restic.Repository) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = (repo.Index()).(*repository.MasterIndex).
|
_, err = repo.Index().Save(context.TODO(), repo, restic.NewIDSet(), nil, nil)
|
||||||
Save(context.TODO(), repo, restic.NewIDSet(), nil, nil)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/restic/restic/internal/crypto"
|
"github.com/restic/restic/internal/crypto"
|
||||||
|
"github.com/restic/restic/internal/ui/progress"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Repository stores data in a backend. It provides high-level functions and
|
// Repository stores data in a backend. It provides high-level functions and
|
||||||
|
@ -82,4 +83,6 @@ type MasterIndex interface {
|
||||||
// blocks any modification of the index.
|
// blocks any modification of the index.
|
||||||
Each(ctx context.Context) <-chan PackedBlob
|
Each(ctx context.Context) <-chan PackedBlob
|
||||||
ListPacks(ctx context.Context, packs IDSet) <-chan PackBlobs
|
ListPacks(ctx context.Context, packs IDSet) <-chan PackBlobs
|
||||||
|
|
||||||
|
Save(ctx context.Context, repo SaverUnpacked, packBlacklist IDSet, extraObsolete IDs, p *progress.Counter) (obsolete IDSet, err error)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue