From 7b8e42a763c9ce572c2423b4851e823974f614cb Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sun, 25 Oct 2015 21:51:46 +0100 Subject: [PATCH 1/3] Silence rebuild-index tests --- cmd/restic/integration_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/restic/integration_test.go b/cmd/restic/integration_test.go index 24f8e52db..c2d5f7197 100644 --- a/cmd/restic/integration_test.go +++ b/cmd/restic/integration_test.go @@ -99,6 +99,7 @@ func cmdCheckOutput(t testing.TB, global GlobalOptions) string { } func cmdRebuildIndex(t testing.TB, global GlobalOptions) { + global.stdout = ioutil.Discard cmd := &CmdRebuildIndex{global: &global} OK(t, cmd.Execute(nil)) } From 734ae7fcb8064d5e2fe9488f2ad575262f8c89ec Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sun, 25 Oct 2015 21:51:57 +0100 Subject: [PATCH 2/3] Add test for corner case It was observed that a restic repository still contained overlapping indexes after `rebuild-index` has been called. This is caused by instantly forgetting that blobs have already been saved once a full index has been written during index rebuilding. This commit adds a (failing) test that shows the behaviour. --- cmd/restic/integration_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cmd/restic/integration_test.go b/cmd/restic/integration_test.go index c2d5f7197..fa95eca92 100644 --- a/cmd/restic/integration_test.go +++ b/cmd/restic/integration_test.go @@ -18,6 +18,7 @@ import ( "github.com/restic/restic/backend" "github.com/restic/restic/debug" "github.com/restic/restic/filter" + "github.com/restic/restic/repository" . "github.com/restic/restic/test" ) @@ -683,3 +684,8 @@ func TestRebuildIndex(t *testing.T) { } }) } + +func TestRebuildIndexAlwaysFull(t *testing.T) { + repository.IndexFull = func(*repository.Index) bool { return true } + TestRebuildIndex(t) +} From 74cd134b54c946ba2fb23ab713dc9cb6be52849a Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sun, 25 Oct 2015 22:34:22 +0100 Subject: [PATCH 3/3] rebuild index: remember already stored blobs --- cmd/restic/cmd_rebuild_index.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/cmd/restic/cmd_rebuild_index.go b/cmd/restic/cmd_rebuild_index.go index 5444cacb2..bcce5d61f 100644 --- a/cmd/restic/cmd_rebuild_index.go +++ b/cmd/restic/cmd_rebuild_index.go @@ -61,6 +61,12 @@ func (cmd CmdRebuildIndex) RebuildIndex() error { combinedIndex := repository.NewIndex() packsDone := backend.NewIDSet() + type Blob struct { + id backend.ID + tpe pack.BlobType + } + blobsDone := make(map[Blob]struct{}) + i := 0 for indexID := range indexIDs { 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()) for packedBlob := range idx.Each(done) { - combinedIndex.Store(packedBlob.Type, packedBlob.ID, packedBlob.PackID, packedBlob.Offset, packedBlob.Length) 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)