[core] Add more logging to the downloader

Signed-off-by: Konstantin Pastbin <konstantin.pastbin@gmail.com>
This commit is contained in:
Konstantin Pastbin
2025-07-02 21:17:26 +07:00
committed by Konstantin Pastbin
parent 6d0c52afcc
commit ec1d2e6c82
9 changed files with 29 additions and 10 deletions

View File

@@ -147,14 +147,14 @@ string ChunksDownloadStrategy::ChunkFinished(bool success, RangeT const & range)
url = m_servers[s].m_url;
if (success)
{
LOG(LDEBUG, ("Completed chunk", m_servers[s].m_chunkIndex, "via", m_servers[s].m_url));
// mark server as free and chunk as ready
m_servers[s].m_chunkIndex = SERVER_READY;
res.first->m_status = CHUNK_COMPLETE;
}
else
{
LOG(LINFO, ("Thread for url", m_servers[s].m_url,
"failed to download chunk number", m_servers[s].m_chunkIndex));
LOG(LWARNING, ("Failed to dl chunk", m_servers[s].m_chunkIndex, "via", m_servers[s].m_url));
// remove failed server and mark chunk as free
m_servers.erase(m_servers.begin() + s);
res.first->m_status = CHUNK_FREE;
@@ -201,6 +201,7 @@ ChunksDownloadStrategy::NextChunk(string & outUrl, RangeT & range)
range.second = m_chunks[i+1].m_pos - 1;
m_chunks[i].m_status = CHUNK_DOWNLOADING;
LOG(LDEBUG, ("Download chunk", server->m_chunkIndex, "via", outUrl));
return ENextChunk;
case CHUNK_DOWNLOADING:

View File

@@ -65,6 +65,7 @@ public:
void AddChunk(RangeT const & range, ChunkStatusT status);
void SaveChunks(int64_t fileSize, std::string const & fName);
/// Inits the chunks list or loads from the resume file if there is an unfinished download.
/// @return Already downloaded size.
int64_t LoadOrInitChunks(std::string const & fName, int64_t fileSize, int64_t chunkSize);
@@ -81,7 +82,7 @@ public:
EDownloadFailed,
EDownloadSucceeded
};
/// Should be called until returns ENextChunk
/// Get next chunk url ready to download. Should be called until returns ENextChunk.
ResultT NextChunk(std::string & outUrl, RangeT & range);
};
} // namespace downloader

View File

@@ -139,6 +139,7 @@ class FileHttpRequest : public HttpRequest, public IHttpThreadCallback
size_t m_goodChunksCount;
bool m_doCleanProgressFiles;
// Starts a thread per each free/available server.
ChunksDownloadStrategy::ResultT StartThreads()
{
string url;
@@ -198,6 +199,7 @@ class FileHttpRequest : public HttpRequest, public IHttpThreadCallback
}
}
// Saves current chunks' statuses into a resume file.
void SaveResumeChunks()
{
try

View File

@@ -53,6 +53,7 @@ public:
Callback && onProgress = Callback());
/// Download file to filePath.
/// Pulls chunks simultaneously from all available servers, 1 thread per server.
/// @param[in] fileSize Correct file size (needed for resuming and reserving).
static HttpRequest * GetFile(std::vector<std::string> const & urls,
std::string const & filePath, int64_t fileSize,