mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-20 05:13:58 +00:00
[core] Add more logging to the downloader
Signed-off-by: Konstantin Pastbin <konstantin.pastbin@gmail.com>
This commit is contained in:
committed by
Konstantin Pastbin
parent
6d0c52afcc
commit
ec1d2e6c82
@@ -147,14 +147,14 @@ string ChunksDownloadStrategy::ChunkFinished(bool success, RangeT const & range)
|
|||||||
url = m_servers[s].m_url;
|
url = m_servers[s].m_url;
|
||||||
if (success)
|
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
|
// mark server as free and chunk as ready
|
||||||
m_servers[s].m_chunkIndex = SERVER_READY;
|
m_servers[s].m_chunkIndex = SERVER_READY;
|
||||||
res.first->m_status = CHUNK_COMPLETE;
|
res.first->m_status = CHUNK_COMPLETE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LOG(LINFO, ("Thread for url", m_servers[s].m_url,
|
LOG(LWARNING, ("Failed to dl chunk", m_servers[s].m_chunkIndex, "via", m_servers[s].m_url));
|
||||||
"failed to download chunk number", m_servers[s].m_chunkIndex));
|
|
||||||
// remove failed server and mark chunk as free
|
// remove failed server and mark chunk as free
|
||||||
m_servers.erase(m_servers.begin() + s);
|
m_servers.erase(m_servers.begin() + s);
|
||||||
res.first->m_status = CHUNK_FREE;
|
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;
|
range.second = m_chunks[i+1].m_pos - 1;
|
||||||
|
|
||||||
m_chunks[i].m_status = CHUNK_DOWNLOADING;
|
m_chunks[i].m_status = CHUNK_DOWNLOADING;
|
||||||
|
LOG(LDEBUG, ("Download chunk", server->m_chunkIndex, "via", outUrl));
|
||||||
return ENextChunk;
|
return ENextChunk;
|
||||||
|
|
||||||
case CHUNK_DOWNLOADING:
|
case CHUNK_DOWNLOADING:
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ public:
|
|||||||
void AddChunk(RangeT const & range, ChunkStatusT status);
|
void AddChunk(RangeT const & range, ChunkStatusT status);
|
||||||
|
|
||||||
void SaveChunks(int64_t fileSize, std::string const & fName);
|
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.
|
/// @return Already downloaded size.
|
||||||
int64_t LoadOrInitChunks(std::string const & fName, int64_t fileSize, int64_t chunkSize);
|
int64_t LoadOrInitChunks(std::string const & fName, int64_t fileSize, int64_t chunkSize);
|
||||||
|
|
||||||
@@ -81,7 +82,7 @@ public:
|
|||||||
EDownloadFailed,
|
EDownloadFailed,
|
||||||
EDownloadSucceeded
|
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);
|
ResultT NextChunk(std::string & outUrl, RangeT & range);
|
||||||
};
|
};
|
||||||
} // namespace downloader
|
} // namespace downloader
|
||||||
|
|||||||
@@ -139,6 +139,7 @@ class FileHttpRequest : public HttpRequest, public IHttpThreadCallback
|
|||||||
size_t m_goodChunksCount;
|
size_t m_goodChunksCount;
|
||||||
bool m_doCleanProgressFiles;
|
bool m_doCleanProgressFiles;
|
||||||
|
|
||||||
|
// Starts a thread per each free/available server.
|
||||||
ChunksDownloadStrategy::ResultT StartThreads()
|
ChunksDownloadStrategy::ResultT StartThreads()
|
||||||
{
|
{
|
||||||
string url;
|
string url;
|
||||||
@@ -198,6 +199,7 @@ class FileHttpRequest : public HttpRequest, public IHttpThreadCallback
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Saves current chunks' statuses into a resume file.
|
||||||
void SaveResumeChunks()
|
void SaveResumeChunks()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ public:
|
|||||||
Callback && onProgress = Callback());
|
Callback && onProgress = Callback());
|
||||||
|
|
||||||
/// Download file to filePath.
|
/// 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).
|
/// @param[in] fileSize Correct file size (needed for resuming and reserving).
|
||||||
static HttpRequest * GetFile(std::vector<std::string> const & urls,
|
static HttpRequest * GetFile(std::vector<std::string> const & urls,
|
||||||
std::string const & filePath, int64_t fileSize,
|
std::string const & filePath, int64_t fileSize,
|
||||||
|
|||||||
@@ -166,6 +166,7 @@ MetaConfig MapFilesDownloader::LoadMetaConfig()
|
|||||||
|
|
||||||
if (!metaServerUrl.empty())
|
if (!metaServerUrl.empty())
|
||||||
{
|
{
|
||||||
|
LOG(LINFO, ("Requesting metaserver", metaServerUrl));
|
||||||
platform::HttpClient request(metaServerUrl);
|
platform::HttpClient request(metaServerUrl);
|
||||||
request.SetRawHeader("X-OM-DataVersion", std::to_string(m_dataVersion));
|
request.SetRawHeader("X-OM-DataVersion", std::to_string(m_dataVersion));
|
||||||
request.SetRawHeader("X-OM-AppVersion", pl.Version());
|
request.SetRawHeader("X-OM-AppVersion", pl.Version());
|
||||||
@@ -179,7 +180,11 @@ MetaConfig MapFilesDownloader::LoadMetaConfig()
|
|||||||
{
|
{
|
||||||
metaConfig = downloader::ParseMetaConfig(pl.DefaultUrlsJSON());
|
metaConfig = downloader::ParseMetaConfig(pl.DefaultUrlsJSON());
|
||||||
CHECK(metaConfig, ());
|
CHECK(metaConfig, ());
|
||||||
LOG(LWARNING, ("Can't get meta configuration from request, using default servers:", metaConfig->m_serversList));
|
LOG(LWARNING, ("Can't get metaserver configuration, using default servers:", metaConfig->m_serversList));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LOG(LINFO, ("Got servers list:", metaConfig->m_serversList));
|
||||||
}
|
}
|
||||||
CHECK(!metaConfig->m_serversList.empty(), ());
|
CHECK(!metaConfig->m_serversList.empty(), ());
|
||||||
return *metaConfig;
|
return *metaConfig;
|
||||||
|
|||||||
@@ -32,8 +32,9 @@ public:
|
|||||||
|
|
||||||
virtual ~MapFilesDownloader() = default;
|
virtual ~MapFilesDownloader() = default;
|
||||||
|
|
||||||
/// Asynchronously downloads a map file, periodically invokes
|
/// Asynchronously downloads a map file (first queries the metaserver
|
||||||
/// onProgress callback and finally invokes onDownloaded
|
/// for the map servers list, if it haven't been done before),
|
||||||
|
/// periodically invokes onProgress callback and finally invokes onDownloaded
|
||||||
/// callback. Both callbacks will be invoked on the main thread.
|
/// callback. Both callbacks will be invoked on the main thread.
|
||||||
void DownloadMapFile(QueuedCountry && queuedCountry);
|
void DownloadMapFile(QueuedCountry && queuedCountry);
|
||||||
|
|
||||||
@@ -53,16 +54,19 @@ public:
|
|||||||
* @brief Async file download as string buffer (for small files only).
|
* @brief Async file download as string buffer (for small files only).
|
||||||
* Request can be skipped if current servers list is empty.
|
* Request can be skipped if current servers list is empty.
|
||||||
* Callback will be skipped on download error.
|
* Callback will be skipped on download error.
|
||||||
|
* NOTE: not in use at the moment.
|
||||||
* @param[in] url Final url part like "index.json" or "maps/210415/countries.txt".
|
* @param[in] url Final url part like "index.json" or "maps/210415/countries.txt".
|
||||||
* @param[in] forceReset True - force reset current request, if any.
|
* @param[in] forceReset True - force reset current request, if any.
|
||||||
*/
|
*/
|
||||||
void DownloadAsString(std::string url, std::function<bool (std::string const &)> && callback, bool forceReset = false);
|
void DownloadAsString(std::string url, std::function<bool (std::string const &)> && callback, bool forceReset = false);
|
||||||
|
|
||||||
|
// Used in tests only.
|
||||||
void SetServersList(ServersList const & serversList);
|
void SetServersList(ServersList const & serversList);
|
||||||
|
|
||||||
void SetDownloadingPolicy(DownloadingPolicy * policy);
|
void SetDownloadingPolicy(DownloadingPolicy * policy);
|
||||||
void SetDataVersion(int64_t version) { m_dataVersion = version; }
|
void SetDataVersion(int64_t version) { m_dataVersion = version; }
|
||||||
|
|
||||||
/// @name Legacy functions for Android resourses downloading routine.
|
/// @name Legacy functions for Android resources downloading routine (initial World download).
|
||||||
/// @{
|
/// @{
|
||||||
void EnsureMetaConfigReady(std::function<void ()> && callback);
|
void EnsureMetaConfigReady(std::function<void ()> && callback);
|
||||||
std::vector<std::string> MakeUrlListLegacy(std::string const & fileName) const;
|
std::vector<std::string> MakeUrlListLegacy(std::string const & fileName) const;
|
||||||
@@ -70,9 +74,11 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool IsDownloadingAllowed() const;
|
bool IsDownloadingAllowed() const;
|
||||||
|
// Produces download urls for all servers.
|
||||||
std::vector<std::string> MakeUrlList(std::string const & relativeUrl) const;
|
std::vector<std::string> MakeUrlList(std::string const & relativeUrl) const;
|
||||||
|
|
||||||
// Synchronously loads list of servers by http client.
|
// Synchronously loads a list of map servers from the metaserver.
|
||||||
|
// On dl failure fallbacks to the hardcoded list.
|
||||||
MetaConfig LoadMetaConfig();
|
MetaConfig LoadMetaConfig();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ void MapFilesDownloaderWithPing::GetMetaConfig(MetaConfigCallback const & callba
|
|||||||
CHECK(!metaConfig.m_serversList.empty(), ());
|
CHECK(!metaConfig.m_serversList.empty(), ());
|
||||||
|
|
||||||
// Sort the list of servers by latency.
|
// Sort the list of servers by latency.
|
||||||
|
/// @todo(pastk:: actually the sort order is used only in MapFilesDownloader::DownloadAsString()
|
||||||
|
/// to get e.g. countries.txt but this code is not enabled at the moment.
|
||||||
auto const sorted = Pinger::ExcludeUnavailableAndSortEndpoints(metaConfig.m_serversList);
|
auto const sorted = Pinger::ExcludeUnavailableAndSortEndpoints(metaConfig.m_serversList);
|
||||||
// Keep the original list if all servers are unavailable.
|
// Keep the original list if all servers are unavailable.
|
||||||
if (!sorted.empty())
|
if (!sorted.empty())
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ int64_t DoPing(std::string const & url)
|
|||||||
return kInvalidPing;
|
return kInvalidPing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOG(LDEBUG, ("Pinging server", url));
|
||||||
platform::HttpClient request(url);
|
platform::HttpClient request(url);
|
||||||
request.SetHttpMethod("HEAD");
|
request.SetHttpMethod("HEAD");
|
||||||
request.SetTimeout(kTimeoutInSeconds);
|
request.SetTimeout(kTimeoutInSeconds);
|
||||||
@@ -34,7 +35,7 @@ int64_t DoPing(std::string const & url)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LOG(LWARNING, ("Request to server", url, "failed with code =", request.ErrorCode(), "; redirection =", request.WasRedirected()));
|
LOG(LWARNING, ("Ping to server", url, "failed with code =", request.ErrorCode(), "; wasRedirected =", request.WasRedirected()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return kInvalidPing;
|
return kInvalidPing;
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ class Pinger
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using Endpoints = std::vector<std::string>;
|
using Endpoints = std::vector<std::string>;
|
||||||
// Returns list of available endpoints. Works synchronously.
|
// Pings all endpoints and a returns latency-sorted list of available ones. Works synchronously.
|
||||||
static Endpoints ExcludeUnavailableAndSortEndpoints(Endpoints const & urls);
|
static Endpoints ExcludeUnavailableAndSortEndpoints(Endpoints const & urls);
|
||||||
};
|
};
|
||||||
} // namespace storage
|
} // namespace storage
|
||||||
|
|||||||
Reference in New Issue
Block a user