additional logging for hash cache

This commit is contained in:
Jarek Kowalski
2018-03-12 16:49:45 -07:00
parent 0fa823976f
commit f4c9749246
2 changed files with 18 additions and 0 deletions

View File

@@ -5,6 +5,7 @@
"io"
"github.com/kopia/kopia/internal/jsonstream"
"github.com/rs/zerolog/log"
)
// Reader supports reading a stream of hash cache entries.
@@ -25,6 +26,7 @@ type reader struct {
// FindEntry looks for an entry with a given name in hash cache stream and returns it or nil if not found.
func (hcr *reader) FindEntry(relativeName string) *Entry {
for hcr.nextEntry != nil && isLess(hcr.nextEntry.Name, relativeName) {
log.Debug().Msgf("skipping %v while looking for %v", hcr.nextEntry.Name, relativeName)
hcr.readahead()
}
@@ -35,6 +37,12 @@ func (hcr *reader) FindEntry(relativeName string) *Entry {
return e
}
if hcr.nextEntry == nil {
log.Debug().Msgf("end of cache while looking for %v", relativeName)
return nil
}
log.Debug().Msgf("skipping %v while looking for %v", hcr.nextEntry.Name, relativeName)
return nil
}
@@ -56,6 +64,8 @@ func (hcr *reader) readahead() {
*e = Entry{}
if err := hcr.reader.Read(e); err == nil {
hcr.nextEntry = e
} else if err != io.EOF {
log.Debug().Msgf("unable to read next hash cache entry: %v", err)
}
}
@@ -99,5 +109,6 @@ func Open(r io.Reader) Reader {
hcr.nextEntry = nil
hcr.first = true
hcr.readahead()
log.Debug().Msgf("nextEntry: %v", hcr.nextEntry)
return &hcr
}

View File

@@ -347,6 +347,8 @@ func uploadDirInternal(
// Avoid hashing by reusing previous object ID.
de, hash, err = newDirEntry(e, cachedEntry.ObjectID), cachedEntry.Hash, nil
} else {
log.Debug().Msgf("hash cache miss for %v", entryRelativePath)
switch entry := entry.(type) {
case fs.Symlink:
de, hash, err = u.uploadSymlinkInternal(entry, entryRelativePath)
@@ -430,8 +432,13 @@ func (u *Uploader) Upload(
u.cacheReader = hashcache.Open(nil)
u.stats = Stats{}
if old != nil {
log.Debug().Msgf("opening hash cache: %v", old.HashCacheID)
if r, err := u.repo.Objects.Open(old.HashCacheID); err == nil {
u.cacheReader = hashcache.Open(r)
log.Debug().Msgf("opened hash cache: %v", old.HashCacheID)
} else {
log.Warn().Msgf("unable to open hash cache %v: %v", old.HashCacheID, err)
}
}