forked from TrueCloudLab/restic
Merge pull request #354 from restic/fix-index
Save new packs in index atomically
This commit is contained in:
commit
867fc5bd4b
2 changed files with 19 additions and 2 deletions
|
@ -109,6 +109,22 @@ func (idx *Index) Store(blob PackedBlob) {
|
|||
idx.store(blob)
|
||||
}
|
||||
|
||||
// StoreBlobs saves information about the blobs to the index in one atomic transaction.
|
||||
func (idx *Index) StoreBlobs(blobs []PackedBlob) {
|
||||
idx.m.Lock()
|
||||
defer idx.m.Unlock()
|
||||
|
||||
if idx.final {
|
||||
panic("store new item in finalized index")
|
||||
}
|
||||
|
||||
debug.Log("Index.StoreBlobs", "stored %d blobs", len(blobs))
|
||||
|
||||
for _, blob := range blobs {
|
||||
idx.store(blob)
|
||||
}
|
||||
}
|
||||
|
||||
// Lookup queries the index for the blob ID and returns a PackedBlob.
|
||||
func (idx *Index) Lookup(id backend.ID) (pb PackedBlob, err error) {
|
||||
idx.m.Lock()
|
||||
|
|
|
@ -268,9 +268,9 @@ func (r *Repository) savePacker(p *pack.Packer) error {
|
|||
debug.Log("Repo.savePacker", "saved as %v", sid.Str())
|
||||
|
||||
// update blobs in the index
|
||||
var packedBlobs []PackedBlob
|
||||
for _, b := range p.Blobs() {
|
||||
debug.Log("Repo.savePacker", " updating blob %v to pack %v", b.ID.Str(), sid.Str())
|
||||
r.idx.Current().Store(PackedBlob{
|
||||
packedBlobs = append(packedBlobs, PackedBlob{
|
||||
Type: b.Type,
|
||||
ID: b.ID,
|
||||
PackID: sid,
|
||||
|
@ -279,6 +279,7 @@ func (r *Repository) savePacker(p *pack.Packer) error {
|
|||
})
|
||||
r.idx.RemoveFromInFlight(b.ID)
|
||||
}
|
||||
r.idx.Current().StoreBlobs(packedBlobs)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue