Rework index decode and handling old format

This commit is contained in:
Alexander Neumann
2015-08-08 12:22:17 +02:00
parent 356bb62243
commit eb73182fcf
8 changed files with 180 additions and 48 deletions

View File

@@ -3,6 +3,7 @@ package checker
import (
"errors"
"fmt"
"os"
"sync"
"github.com/restic/restic"
@@ -58,15 +59,26 @@ func (c *Checker) LoadIndex() error {
indexCh := make(chan indexRes)
worker := func(id string, done <-chan struct{}) error {
worker := func(id backend.ID, done <-chan struct{}) error {
debug.Log("LoadIndex", "worker got index %v", id)
idx, err := repository.LoadIndex(c.repo, id)
idx, err := repository.LoadIndexWithDecoder(c.repo, id.String(), repository.DecodeIndex)
if err == repository.ErrOldIndexFormat {
debug.Log("LoadIndex", "old index format found, converting")
fmt.Fprintf(os.Stderr, "convert index %v to new format\n", id.Str())
id, err = repository.ConvertIndex(c.repo, id)
if err != nil {
return err
}
idx, err = repository.LoadIndexWithDecoder(c.repo, id.String(), repository.DecodeIndex)
}
if err != nil {
return err
}
select {
case indexCh <- indexRes{Index: idx, ID: id}:
case indexCh <- indexRes{Index: idx, ID: id.String()}:
case <-done:
}
@@ -77,7 +89,8 @@ func (c *Checker) LoadIndex() error {
go func() {
defer close(indexCh)
debug.Log("LoadIndex", "start loading indexes in parallel")
perr = repository.FilesInParallel(c.repo.Backend(), backend.Index, defaultParallelism, worker)
perr = repository.FilesInParallel(c.repo.Backend(), backend.Index, defaultParallelism,
repository.ParallelWorkFuncParseID(worker))
debug.Log("LoadIndex", "loading indexes finished, error: %v", perr)
}()

View File

@@ -91,8 +91,8 @@ func TestUnreferencedPack(t *testing.T) {
WithTestEnvironment(t, checkerTestData, func(repodir string) {
repo := OpenLocalRepo(t, repodir)
// index 8eb5 only references pack 60e0
indexID := "8eb5b61062bf8e959f244fba0c971108bc8d4d2a4b236f71a704998e28cc5cf6"
// index 3f1a only references pack 60e0
indexID := "3f1abfcb79c6f7d0a3be517d2c83c8562fba64ef2c8e9a3544b4edaf8b5e3b44"
packID := "60e0438dcb978ec6860cc1f8c43da648170ee9129af8f650f876bad19f8f788e"
OK(t, repo.Backend().Remove(backend.Index, indexID))

Binary file not shown.