-
Notifications
You must be signed in to change notification settings - Fork 0
/
repair.go
64 lines (52 loc) · 1.63 KB
/
repair.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright 2016 Stellar Development Foundation and contributors. Licensed
// under the Apache License, Version 2.0. See the COPYING file at the root
// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0
package archivist
import (
"log"
"fmt"
)
func Repair(src *Archive, dst *Archive, opts *CommandOptions) error {
state, e := dst.GetRootHAS()
if e != nil {
return e
}
opts.Range = opts.Range.Clamp(state.Range())
log.Printf("Starting scan for repair")
var errs uint32
errs += noteError(dst.ScanCheckpoints(opts))
log.Printf("Examining checkpoint files for gaps")
missingCheckpointFiles := dst.CheckCheckpointFilesMissing(opts)
repairedHistory := false
for cat, missing := range missingCheckpointFiles {
for _, chk := range missing {
pth := CategoryCheckpointPath(cat, chk)
if !categoryRequired(cat) && !src.backend.Exists(pth) {
log.Printf("Skipping nonexistent, optional %s file %s", cat, pth)
continue
}
log.Printf("Repairing %s", pth)
errs += noteError(copyPath(src, dst, pth, opts))
if cat == "history" {
repairedHistory = true
}
}
}
if repairedHistory {
log.Printf("Re-running checkpoing-file scan, for bucket repair")
dst.ClearCachedInfo()
errs += noteError(dst.ScanCheckpoints(opts))
}
errs += noteError(dst.ScanBuckets(opts))
log.Printf("Examining buckets referenced by checkpoints")
missingBuckets := dst.CheckBucketsMissing()
for bkt, _ := range missingBuckets {
pth := BucketPath(bkt)
log.Printf("Repairing %s", pth)
errs += noteError(copyPath(src, dst, pth, opts))
}
if errs != 0 {
return fmt.Errorf("%d errors while repairing", errs)
}
return nil
}