mirror of
https://github.com/octoleo/restic.git
synced 2024-12-23 03:18:55 +00:00
repository: Save pack files for trees in cache
This commit is contained in:
parent
62ba9f1950
commit
7a5fde8f5a
@ -89,8 +89,8 @@ func (r *packerManager) insertPacker(p *Packer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// savePacker stores p in the backend.
|
// savePacker stores p in the backend.
|
||||||
func (r *Repository) savePacker(p *Packer) error {
|
func (r *Repository) savePacker(t restic.BlobType, p *Packer) error {
|
||||||
debug.Log("save packer with %d blobs (%d bytes)\n", p.Packer.Count(), p.Packer.Size())
|
debug.Log("save packer for %v with %d blobs (%d bytes)\n", t, p.Packer.Count(), p.Packer.Size())
|
||||||
_, err := p.Packer.Finalize()
|
_, err := p.Packer.Finalize()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -112,6 +112,20 @@ func (r *Repository) savePacker(p *Packer) error {
|
|||||||
|
|
||||||
debug.Log("saved as %v", h)
|
debug.Log("saved as %v", h)
|
||||||
|
|
||||||
|
if t == restic.TreeBlob && r.Cache != nil {
|
||||||
|
debug.Log("saving tree pack file in cache")
|
||||||
|
|
||||||
|
_, err = p.tmpfile.Seek(0, 0)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "Seek")
|
||||||
|
}
|
||||||
|
|
||||||
|
err := r.Cache.Save(h, p.tmpfile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
err = p.tmpfile.Close()
|
err = p.tmpfile.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "close tempfile")
|
return errors.Wrap(err, "close tempfile")
|
||||||
|
@ -223,7 +223,7 @@ func (r *Repository) SaveAndEncrypt(ctx context.Context, t restic.BlobType, data
|
|||||||
}
|
}
|
||||||
|
|
||||||
// else write the pack to the backend
|
// else write the pack to the backend
|
||||||
return *id, r.savePacker(packer)
|
return *id, r.savePacker(t, packer)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SaveJSONUnpacked serialises item as JSON and encrypts and saves it in the
|
// SaveJSONUnpacked serialises item as JSON and encrypts and saves it in the
|
||||||
@ -262,20 +262,27 @@ func (r *Repository) SaveUnpacked(ctx context.Context, t restic.FileType, p []by
|
|||||||
|
|
||||||
// Flush saves all remaining packs.
|
// Flush saves all remaining packs.
|
||||||
func (r *Repository) Flush() error {
|
func (r *Repository) Flush() error {
|
||||||
for _, pm := range []*packerManager{r.dataPM, r.treePM} {
|
pms := []struct {
|
||||||
pm.pm.Lock()
|
t restic.BlobType
|
||||||
|
pm *packerManager
|
||||||
|
}{
|
||||||
|
{restic.DataBlob, r.dataPM},
|
||||||
|
{restic.TreeBlob, r.treePM},
|
||||||
|
}
|
||||||
|
|
||||||
debug.Log("manually flushing %d packs", len(pm.packers))
|
for _, p := range pms {
|
||||||
for _, p := range pm.packers {
|
p.pm.pm.Lock()
|
||||||
err := r.savePacker(p)
|
|
||||||
|
debug.Log("manually flushing %d packs", len(p.pm.packers))
|
||||||
|
for _, packer := range p.pm.packers {
|
||||||
|
err := r.savePacker(p.t, packer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
pm.pm.Unlock()
|
p.pm.pm.Unlock()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pm.packers = pm.packers[:0]
|
p.pm.packers = p.pm.packers[:0]
|
||||||
|
p.pm.pm.Unlock()
|
||||||
pm.pm.Unlock()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user