Skip to content

Commit

Permalink
[disk] pass the actual logical blob size to FileLocationBase
Browse files Browse the repository at this point in the history
availableOrTryProxy returns -1 for foundSize if the blob is not available
in the disk cache. If we then get a hit from the proxy backend, we should
have the actual foundSize. We should then use that (not -1) when calling
FileLocationBase to construct the filename to store the blob in locally.

This might fix #420.
  • Loading branch information
mostynb committed Apr 6, 2021
1 parent 590ffd1 commit 1cccbcf
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions cache/disk/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -844,15 +844,15 @@ func (c *Cache) get(kind cache.EntryKind, hash string, size int64, offset int64,
return nil, -1, nil
}

r, foundLogicalSize, err := c.proxy.Get(kind, hash)
r, foundSize, err := c.proxy.Get(kind, hash)
if r != nil {
defer r.Close()
}
if err != nil || r == nil {
return nil, -1, err
}

if isSizeMismatch(size, foundLogicalSize) {
if isSizeMismatch(size, foundSize) || foundSize < 0 {
return nil, -1, nil
}

Expand Down Expand Up @@ -892,23 +892,23 @@ func (c *Cache) get(kind cache.EntryKind, hash string, size int64, offset int64,
}
} else { // Compressed CAS blob.
if zstd {
rc, err = casblob.GetZstdReadCloser(rcf, foundLogicalSize, offset)
rc, err = casblob.GetZstdReadCloser(rcf, foundSize, offset)
} else {
rc, err = casblob.GetUncompressedReadCloser(rcf, foundLogicalSize, offset)
rc, err = casblob.GetUncompressedReadCloser(rcf, foundSize, offset)
}
}
if err != nil {
return nil, -1, err
}

unreserve, removeTempfile, err = c.commit(key, legacy, blobFile, size, foundLogicalSize, sizeOnDisk, random)
unreserve, removeTempfile, err = c.commit(key, legacy, blobFile, size, foundSize, sizeOnDisk, random)
if err != nil {
rc.Close()
rc = nil
foundSize = -1
}

return rc, foundLogicalSize, err
return rc, foundSize, err
}

// Contains returns true if the `hash` key exists in the cache, and
Expand Down

0 comments on commit 1cccbcf

Please sign in to comment.