Skip to content

Commit 9068537

Browse files
CcdbApi: Fixed logReading in vectoredLoadFileTomemory (#12276)
* CcdbApi: Fixed logReading in vectoredLoadFileTomemory * CcdbDownloader: Better transfer info logging * Formatting fix * Removed whitespace
1 parent 3672317 commit 9068537

3 files changed

Lines changed: 40 additions & 14 deletions

File tree

CCDB/include/CCDB/CCDBDownloader.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ typedef struct DownloaderRequestData {
5151
long timestamp;
5252
HeaderObjectPair_t hoPair;
5353
std::map<std::string, std::string>* headers;
54+
std::string userAgent;
5455

5556
std::function<bool(std::string)> localContentCallback;
5657
bool errorflag = false;
@@ -208,6 +209,11 @@ class CCDBDownloader
208209
*/
209210
void runLoop(bool noWait);
210211

212+
/**
213+
* Returns a message describing the transfer an it's result.
214+
*/
215+
std::string prepareLogMessage(std::string host_url, std::string userAgent, const std::string& path, long ts, const std::map<std::string, std::string>* headers, long httpCode) const;
216+
211217
/**
212218
* Leaves only the protocol and host part of the url, discrading path and metadata.
213219
*/

CCDB/src/CCDBDownloader.cxx

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -493,21 +493,25 @@ void CCDBDownloader::transferFinished(CURL* easy_handle, CURLcode curlCode)
493493
curl_easy_getinfo(easy_handle, CURLINFO_EFFECTIVE_URL, &url);
494494
LOG(debug) << "Transfer for " << url << " finished with code " << httpCode << "\n";
495495

496+
std::string currentHost = requestData->hosts[performData->hostInd];
497+
std::string loggingMessage = prepareLogMessage(currentHost, requestData->userAgent, requestData->path, requestData->timestamp, requestData->headers, httpCode);
498+
496499
// Get alternative locations for the same host
497500
auto locations = getLocations(&(requestData->hoPair.header));
498501

499502
// React to received http code
500-
if (404 == httpCode) {
501-
LOG(error) << "Requested resource does not exist: " << url;
502-
} else if (304 == httpCode) {
503-
LOGP(debug, "Object exists but I am not serving it since it's already in your possession");
504-
contentRetrieved = true;
505-
} else if (300 <= httpCode && httpCode < 400 && performData->locInd < locations.size()) {
506-
followRedirect(performData, easy_handle, locations, rescheduled, contentRetrieved);
507-
} else if (200 <= httpCode && httpCode < 300) {
508-
contentRetrieved = true;
503+
if (200 <= httpCode && httpCode < 400) {
504+
LOG(debug) << loggingMessage;
505+
if (304 == httpCode) {
506+
LOGP(debug, "Object exists but I am not serving it since it's already in your possession");
507+
contentRetrieved = true;
508+
} else if (300 <= httpCode && httpCode < 400 && performData->locInd < locations.size()) {
509+
followRedirect(performData, easy_handle, locations, rescheduled, contentRetrieved);
510+
} else if (200 <= httpCode && httpCode < 300) {
511+
contentRetrieved = true;
512+
}
509513
} else {
510-
LOG(error) << "Error in fetching object " << url << ", curl response code:" << httpCode;
514+
LOG(error) << loggingMessage;
511515
}
512516

513517
// Check if content was retrieved, or scheduled to be retrieved
@@ -694,4 +698,21 @@ void CCDBDownloader::asynchSchedule(CURL* handle, size_t* requestCounter)
694698
// return codeVector;
695699
}
696700

701+
std::string CCDBDownloader::prepareLogMessage(std::string host_url, std::string userAgent, const std::string& path, long ts, const std::map<std::string, std::string>* headers, long httpCode) const
702+
{
703+
std::string upath{path};
704+
if (headers) {
705+
auto ent = headers->find("Valid-From");
706+
if (ent != headers->end()) {
707+
upath += "/" + ent->second;
708+
}
709+
ent = headers->find("ETag");
710+
if (ent != headers->end()) {
711+
upath += "/" + ent->second;
712+
}
713+
}
714+
upath.erase(remove(upath.begin(), upath.end(), '\"'), upath.end());
715+
return fmt::format("CcdbDownloader finished transfer {}{}{} for {} (agent_id: {}) with http code: {}", host_url, (host_url.back() == '/') ? "" : "/", upath, (ts < 0) ? getCurrentTimestamp() : ts, userAgent, httpCode);
716+
}
717+
697718
} // namespace o2

CCDB/src/CcdbApi.cxx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,6 +1533,7 @@ void CcdbApi::scheduleDownload(RequestContext& requestContext, size_t* requestCo
15331533
data->path = requestContext.path;
15341534
data->timestamp = requestContext.timestamp;
15351535
data->localContentCallback = localContentCallback;
1536+
data->userAgent = mUniqueAgentID;
15361537

15371538
curl_easy_setopt(curl_handle, CURLOPT_URL, fullUrl.c_str());
15381539
initCurlOptionsForRetrieve(curl_handle, (void*)(&data->hoPair), writeCallback, false);
@@ -1671,8 +1672,6 @@ void CcdbApi::vectoredLoadFileToMemory(std::vector<RequestContext>& requestConte
16711672
// navigateSourcesAndLoadFile either retrieves file from snapshot immediately, or schedules it to be downloaded when mDownloader->runLoop is ran at a later time
16721673
auto& requestContext = requestContexts.at(i);
16731674
navigateSourcesAndLoadFile(requestContext, fromSnapshots.at(i), &requestCounter);
1674-
logReading(requestContext.path, requestContext.timestamp, &requestContext.headers,
1675-
fmt::format("{}{}", requestContext.considerSnapshot ? "load to memory" : "retrieve", fromSnapshots.at(i) ? " from snapshot" : ""));
16761675
}
16771676

16781677
// Download the rest
@@ -1683,12 +1682,12 @@ void CcdbApi::vectoredLoadFileToMemory(std::vector<RequestContext>& requestConte
16831682
// Save snapshots
16841683
for (int i = 0; i < requestContexts.size(); i++) {
16851684
auto& requestContext = requestContexts.at(i);
1685+
logReading(requestContext.path, requestContext.timestamp, &requestContext.headers,
1686+
fmt::format("{}{}", requestContext.considerSnapshot ? "load to memory" : "retrieve", fromSnapshots.at(i) ? " from snapshot" : ""));
16861687
if (!requestContext.dest.empty()) {
16871688
if (requestContext.considerSnapshot && fromSnapshots.at(i) != 2) {
16881689
saveSnapshot(requestContext);
16891690
}
1690-
} else {
1691-
LOG(warning) << "Did not receive content for " << requestContext.path << "\n"; // Temporarily demoted to warning, since it floods the infologger
16921691
}
16931692
}
16941693
}

0 commit comments

Comments
 (0)