Revert "Merge fix/restore-cache-readat"
All checks were successful
check / check (push) Successful in 4s
All checks were successful
check / check (push) Successful in 4s
This reverts commit44c9008e7e, reversing changes made tob55d5763ad.
This commit is contained in:
@@ -569,22 +569,14 @@ func (v *Vaultik) restoreRegularFile(
|
|||||||
return fmt.Errorf("getting blob %s: %w", blobChunk.BlobID, err)
|
return fmt.Errorf("getting blob %s: %w", blobChunk.BlobID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the blob isn't on disk yet, download it (one full readout
|
// Download and decrypt blob if not cached
|
||||||
// of the plaintext into memory), write it to the cache, and
|
|
||||||
// satisfy THIS chunk from the in-memory copy. Subsequent files
|
|
||||||
// needing chunks from the same blob hit the ReadAt branch and
|
|
||||||
// read only the bytes they actually want — never the whole
|
|
||||||
// blob — which is the difference between sub-millisecond chunk
|
|
||||||
// extraction and ~1 s per cache hit on a 10 GB blob.
|
|
||||||
blobHashStr := blob.Hash.String()
|
blobHashStr := blob.Hash.String()
|
||||||
var chunkData []byte
|
|
||||||
t0 = time.Now()
|
t0 = time.Now()
|
||||||
blobInCache := blobCache.Has(blobHashStr)
|
blobData, ok := blobCache.Get(blobHashStr)
|
||||||
cacheGetDur += time.Since(t0)
|
cacheGetDur += time.Since(t0)
|
||||||
|
if !ok {
|
||||||
if !blobInCache {
|
|
||||||
t0 = time.Now()
|
t0 = time.Now()
|
||||||
blobData, err := v.downloadBlob(ctx, blobHashStr, blob.CompressedSize, identity)
|
blobData, err = v.downloadBlob(ctx, blobHashStr, blob.CompressedSize, identity)
|
||||||
downloadDur += time.Since(t0)
|
downloadDur += time.Since(t0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("downloading blob %s: %w", blobHashStr[:16], err)
|
return fmt.Errorf("downloading blob %s: %w", blobHashStr[:16], err)
|
||||||
@@ -597,22 +589,17 @@ func (v *Vaultik) restoreRegularFile(
|
|||||||
downloadCount++
|
downloadCount++
|
||||||
result.BlobsDownloaded++
|
result.BlobsDownloaded++
|
||||||
result.BytesDownloaded += blob.CompressedSize
|
result.BytesDownloaded += blob.CompressedSize
|
||||||
|
|
||||||
if blobChunk.Offset+blobChunk.Length > int64(len(blobData)) {
|
|
||||||
return fmt.Errorf("chunk %s extends beyond blob data (offset=%d, length=%d, blob_size=%d)",
|
|
||||||
fc.ChunkHash[:16], blobChunk.Offset, blobChunk.Length, len(blobData))
|
|
||||||
}
|
|
||||||
chunkData = blobData[blobChunk.Offset : blobChunk.Offset+blobChunk.Length]
|
|
||||||
} else {
|
} else {
|
||||||
cacheHitCount++
|
cacheHitCount++
|
||||||
t0 = time.Now()
|
|
||||||
chunkData, err = blobCache.ReadAt(blobHashStr, blobChunk.Offset, blobChunk.Length)
|
|
||||||
cacheGetDur += time.Since(t0)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("reading chunk %s from cached blob %s: %w", fc.ChunkHash[:16], blobHashStr[:16], err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Extract chunk from blob
|
||||||
|
if blobChunk.Offset+blobChunk.Length > int64(len(blobData)) {
|
||||||
|
return fmt.Errorf("chunk %s extends beyond blob data (offset=%d, length=%d, blob_size=%d)",
|
||||||
|
fc.ChunkHash[:16], blobChunk.Offset, blobChunk.Length, len(blobData))
|
||||||
|
}
|
||||||
|
chunkData := blobData[blobChunk.Offset : blobChunk.Offset+blobChunk.Length]
|
||||||
|
|
||||||
// Write chunk to output file
|
// Write chunk to output file
|
||||||
t0 = time.Now()
|
t0 = time.Now()
|
||||||
n, err := outFile.Write(chunkData)
|
n, err := outFile.Write(chunkData)
|
||||||
|
|||||||
Reference in New Issue
Block a user