forked from TrueCloudLab/restic
Merge pull request #325 from restic/fix-rebuild-index
rebuild-index: Remember already stored blobs
This commit is contained in:
commit
4bc81c2bd2
2 changed files with 23 additions and 1 deletions
|
@ -61,6 +61,12 @@ func (cmd CmdRebuildIndex) RebuildIndex() error {
|
||||||
combinedIndex := repository.NewIndex()
|
combinedIndex := repository.NewIndex()
|
||||||
packsDone := backend.NewIDSet()
|
packsDone := backend.NewIDSet()
|
||||||
|
|
||||||
|
type Blob struct {
|
||||||
|
id backend.ID
|
||||||
|
tpe pack.BlobType
|
||||||
|
}
|
||||||
|
blobsDone := make(map[Blob]struct{})
|
||||||
|
|
||||||
i := 0
|
i := 0
|
||||||
for indexID := range indexIDs {
|
for indexID := range indexIDs {
|
||||||
cmd.global.Printf(" loading index %v\n", i)
|
cmd.global.Printf(" loading index %v\n", i)
|
||||||
|
@ -74,8 +80,17 @@ func (cmd CmdRebuildIndex) RebuildIndex() error {
|
||||||
debug.Log("RebuildIndex.RebuildIndex", "adding blobs from index %v", indexID.Str())
|
debug.Log("RebuildIndex.RebuildIndex", "adding blobs from index %v", indexID.Str())
|
||||||
|
|
||||||
for packedBlob := range idx.Each(done) {
|
for packedBlob := range idx.Each(done) {
|
||||||
combinedIndex.Store(packedBlob.Type, packedBlob.ID, packedBlob.PackID, packedBlob.Offset, packedBlob.Length)
|
|
||||||
packsDone.Insert(packedBlob.PackID)
|
packsDone.Insert(packedBlob.PackID)
|
||||||
|
b := Blob{
|
||||||
|
id: packedBlob.ID,
|
||||||
|
tpe: packedBlob.Type,
|
||||||
|
}
|
||||||
|
if _, ok := blobsDone[b]; ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
blobsDone[b] = struct{}{}
|
||||||
|
combinedIndex.Store(packedBlob.Type, packedBlob.ID, packedBlob.PackID, packedBlob.Offset, packedBlob.Length)
|
||||||
}
|
}
|
||||||
|
|
||||||
combinedIndex.AddToSupersedes(indexID)
|
combinedIndex.AddToSupersedes(indexID)
|
||||||
|
|
|
@ -18,6 +18,7 @@ import (
|
||||||
"github.com/restic/restic/backend"
|
"github.com/restic/restic/backend"
|
||||||
"github.com/restic/restic/debug"
|
"github.com/restic/restic/debug"
|
||||||
"github.com/restic/restic/filter"
|
"github.com/restic/restic/filter"
|
||||||
|
"github.com/restic/restic/repository"
|
||||||
. "github.com/restic/restic/test"
|
. "github.com/restic/restic/test"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -99,6 +100,7 @@ func cmdCheckOutput(t testing.TB, global GlobalOptions) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func cmdRebuildIndex(t testing.TB, global GlobalOptions) {
|
func cmdRebuildIndex(t testing.TB, global GlobalOptions) {
|
||||||
|
global.stdout = ioutil.Discard
|
||||||
cmd := &CmdRebuildIndex{global: &global}
|
cmd := &CmdRebuildIndex{global: &global}
|
||||||
OK(t, cmd.Execute(nil))
|
OK(t, cmd.Execute(nil))
|
||||||
}
|
}
|
||||||
|
@ -682,3 +684,8 @@ func TestRebuildIndex(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRebuildIndexAlwaysFull(t *testing.T) {
|
||||||
|
repository.IndexFull = func(*repository.Index) bool { return true }
|
||||||
|
TestRebuildIndex(t)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue