mirror of
https://github.com/octoleo/restic.git
synced 2024-11-11 07:41:03 +00:00
cache: Improve debug logs
This commit is contained in:
parent
1eaad6cebb
commit
809e218d20
20
internal/cache/backend.go
vendored
20
internal/cache/backend.go
vendored
@ -50,14 +50,14 @@ var autoCacheTypes = map[restic.FileType]struct{}{
|
|||||||
|
|
||||||
// Save stores a new file is the backend and the cache.
|
// Save stores a new file is the backend and the cache.
|
||||||
func (b *Backend) Save(ctx context.Context, h restic.Handle, rd io.Reader) (err error) {
|
func (b *Backend) Save(ctx context.Context, h restic.Handle, rd io.Reader) (err error) {
|
||||||
debug.Log("cache Save(%v)", h)
|
|
||||||
if _, ok := autoCacheTypes[h.Type]; !ok {
|
if _, ok := autoCacheTypes[h.Type]; !ok {
|
||||||
return b.Backend.Save(ctx, h, rd)
|
return b.Backend.Save(ctx, h, rd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
debug.Log("Save(%v): auto-store in the cache", h)
|
||||||
wr, err := b.Cache.SaveWriter(h)
|
wr, err := b.Cache.SaveWriter(h)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
debug.Log("unable to save object to cache: %v", err)
|
debug.Log("unable to save %v to cache: %v", h, err)
|
||||||
return b.Backend.Save(ctx, h, rd)
|
return b.Backend.Save(ctx, h, rd)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ func (b *Backend) Save(ctx context.Context, h restic.Handle, rd io.Reader) (err
|
|||||||
err = wr.Close()
|
err = wr.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
debug.Log("cache writer returned error: %v", err)
|
debug.Log("cache writer returned error: %v", err)
|
||||||
b.Cache.Remove(h)
|
_ = b.Cache.Remove(h)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -89,7 +89,12 @@ func (b *Backend) Load(ctx context.Context, h restic.Handle, length int, offset
|
|||||||
return b.Cache.Load(h, length, offset)
|
return b.Cache.Load(h, length, offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
debug.Log("Load(%v, %v, %v) delegated to backend", h, length, offset)
|
// partial file requested
|
||||||
|
if offset != 0 || length != 0 {
|
||||||
|
debug.Log("Load(%v, %v, %v): partial file requested, delegating to backend", h, length, offset)
|
||||||
|
return b.Backend.Load(ctx, h, length, offset)
|
||||||
|
}
|
||||||
|
|
||||||
rd, err := b.Backend.Load(ctx, h, length, offset)
|
rd, err := b.Backend.Load(ctx, h, length, offset)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if b.Backend.IsNotExist(err) {
|
if b.Backend.IsNotExist(err) {
|
||||||
@ -100,14 +105,7 @@ func (b *Backend) Load(ctx context.Context, h restic.Handle, length int, offset
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// only cache complete files
|
|
||||||
if offset != 0 || length != 0 {
|
|
||||||
debug.Log("won't store partial file %v", h)
|
|
||||||
return rd, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, ok := autoCacheFiles[h.Type]; !ok {
|
if _, ok := autoCacheFiles[h.Type]; !ok {
|
||||||
debug.Log("wrong type for auto store %v", h)
|
|
||||||
return rd, nil
|
return rd, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user