Merge pull request #214 from macdanny/issue-207-retry-download

Retry downloads with corrupted content up to three times.
This commit is contained in:
gilbertchen
2017-10-05 22:28:12 -04:00
committed by GitHub

View File

@@ -324,6 +324,8 @@ func (downloader *ChunkDownloader) Download(threadIndex int, task ChunkDownloadT
LOG_DEBUG("CHUNK_FOSSIL", "Chunk %s has been marked as a fossil", chunkID) LOG_DEBUG("CHUNK_FOSSIL", "Chunk %s has been marked as a fossil", chunkID)
} }
const MaxDownloadAttempts = 3
for downloadAttempt := 0;; downloadAttempt++ {
err = downloader.storage.DownloadFile(threadIndex, chunkPath, chunk) err = downloader.storage.DownloadFile(threadIndex, chunkPath, chunk)
if err != nil { if err != nil {
LOG_ERROR("UPLOAD_FATAL", "Failed to download the chunk %s: %v", chunkID, err) LOG_ERROR("UPLOAD_FATAL", "Failed to download the chunk %s: %v", chunkID, err)
@@ -332,15 +334,30 @@ func (downloader *ChunkDownloader) Download(threadIndex int, task ChunkDownloadT
err = chunk.Decrypt(downloader.config.ChunkKey, task.chunkHash) err = chunk.Decrypt(downloader.config.ChunkKey, task.chunkHash)
if err != nil { if err != nil {
if downloadAttempt < MaxDownloadAttempts {
LOG_WARN("RETRY_DOWNLOAD", "Failed to decrypt the chunk %s: %v", chunkID, err)
chunk.Reset(false)
continue
} else {
LOG_ERROR("UPLOAD_CHUNK", "Failed to decrypt the chunk %s: %v", chunkID, err) LOG_ERROR("UPLOAD_CHUNK", "Failed to decrypt the chunk %s: %v", chunkID, err)
return false return false
} }
}
actualChunkID := chunk.GetID() actualChunkID := chunk.GetID()
if actualChunkID != chunkID { if actualChunkID != chunkID {
if downloadAttempt < MaxDownloadAttempts {
LOG_WARN("RETRY_DOWNLOAD", "The chunk %s has a hash id of %s", chunkID, actualChunkID)
chunk.Reset(false)
continue
} else {
LOG_FATAL("UPLOAD_CORRUPTED", "The chunk %s has a hash id of %s", chunkID, actualChunkID) LOG_FATAL("UPLOAD_CORRUPTED", "The chunk %s has a hash id of %s", chunkID, actualChunkID)
return false return false
} }
}
break
}
if len(cachedPath) > 0 { if len(cachedPath) > 0 {
// Save a copy to the local snapshot cache // Save a copy to the local snapshot cache