2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-28 13:00:53 +00:00

Process packs in order of first appearance

This commit is contained in:
Michael Eischer 2020-08-15 17:41:55 +02:00
parent fe69b83074
commit 2e7d475029

View File

@ -101,6 +101,10 @@ func (r *fileRestorer) forEachBlob(blobIDs []restic.ID, fn func(packID restic.ID
func (r *fileRestorer) restoreFiles(ctx context.Context) error { func (r *fileRestorer) restoreFiles(ctx context.Context) error {
packs := make(map[restic.ID]*packInfo) // all packs packs := make(map[restic.ID]*packInfo) // all packs
// Process packs in order of first access. While this cannot guarantee
// that file chunks are restored sequentially, it offers a good enough
// approximation to shorten restore times by up to 19% in some test.
var packOrder restic.IDs
// create packInfo from fileInfo // create packInfo from fileInfo
for _, file := range r.files { for _, file := range r.files {
@ -123,6 +127,7 @@ func (r *fileRestorer) restoreFiles(ctx context.Context) error {
files: make(map[*fileInfo]struct{}), files: make(map[*fileInfo]struct{}),
} }
packs[packID] = pack packs[packID] = pack
packOrder = append(packOrder, packID)
} }
pack.files[file] = struct{}{} pack.files[file] = struct{}{}
}) })
@ -157,7 +162,8 @@ func (r *fileRestorer) restoreFiles(ctx context.Context) error {
} }
// the main restore loop // the main restore loop
for _, pack := range packs { for _, id := range packOrder {
pack := packs[id]
select { select {
case <-ctx.Done(): case <-ctx.Done():
return ctx.Err() return ctx.Err()