Skip to content

Commit 5681b79

Browse files
committed
Merge branch 'dev' into stable-sync
2 parents 6035df9 + 924ed29 commit 5681b79

File tree

638 files changed

+12611
-5265
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

638 files changed

+12611
-5265
lines changed

.github/workflows/clean-test.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ name: Clean PR checks
3939
description: build/O2/o2-cs8
4040
type: boolean
4141
default: true
42-
'check_build/O2/o2-dataflow':
43-
description: build/O2/o2-dataflow
44-
type: boolean
45-
default: true
4642
'check_build/O2/o2-dataflow-cs8':
4743
description: build/O2/o2-dataflow-cs8
4844
type: boolean

Algorithm/include/Algorithm/PageParser.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,12 @@ class PageParser
255255
return mElement;
256256
}
257257
// comparison
258-
bool operator==(const SelfType& rh)
258+
bool operator==(const SelfType& rh) const
259259
{
260260
return mPosition == rh.mPosition;
261261
}
262262
// comparison
263-
bool operator!=(const SelfType& rh)
263+
bool operator!=(const SelfType& rh) const
264264
{
265265
return mPosition != rh.mPosition;
266266
}

CCDB/include/CCDB/CCDBDownloader.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ 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;
56-
bool errorflag = false;
5757
} DownloaderRequestData;
5858
#endif
5959

@@ -208,12 +208,17 @@ class CCDBDownloader
208208
*/
209209
void runLoop(bool noWait);
210210

211-
private:
211+
/**
212+
* Returns a message describing the transfer an it's result.
213+
*/
214+
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;
215+
212216
/**
213217
* Leaves only the protocol and host part of the url, discrading path and metadata.
214218
*/
215219
std::string trimHostUrl(std::string full_host_url) const;
216220

221+
private:
217222
/**
218223
* Recognizes whether the address is a full url, or a partial one (like for example "/Task/Detector/1") and combines it with potentialHost if needed.
219224
*/

CCDB/include/CCDB/CcdbApi.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ class CcdbApi //: public DatabaseInterface
6464
/// \brief Default destructor
6565
virtual ~CcdbApi();
6666

67+
// Delete copy and copy assignment constructor
68+
CcdbApi(const CcdbApi&) = delete;
69+
void operator=(const CcdbApi&) = delete;
70+
6771
const std::string getUniqueAgentID() const { return mUniqueAgentID; }
6872

6973
static bool checkAlienToken();
@@ -369,7 +373,7 @@ class CcdbApi //: public DatabaseInterface
369373
void scheduleDownload(RequestContext& requestContext, size_t* requestCounter) const;
370374

371375
void getFromSnapshot(bool createSnapshot, std::string const& path,
372-
long timestamp, std::map<std::string, std::string> headers,
376+
long timestamp, std::map<std::string, std::string>& headers,
373377
std::string& snapshotpath, o2::pmr::vector<char>& dest, int& fromSnapshot, std::string const& etag) const;
374378
void releaseNamedSemaphore(boost::interprocess::named_semaphore* sem, std::string path) const;
375379
boost::interprocess::named_semaphore* createNamedSempahore(std::string path) const;

CCDB/src/CCDBDownloader.cxx

Lines changed: 59 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -403,30 +403,37 @@ std::string CCDBDownloader::trimHostUrl(std::string full_host_url) const
403403
{
404404
CURLU* host_url = curl_url();
405405
curl_url_set(host_url, CURLUPART_URL, full_host_url.c_str(), 0);
406-
// Get host part
406+
407+
// Get host part (the only critical part)
407408
char* host;
408409
CURLUcode host_result = curl_url_get(host_url, CURLUPART_HOST, &host, 0);
409-
std::string host_name;
410-
if (host_result == CURLUE_OK) {
411-
// Host part present
412-
host_name = host;
413-
curl_free(host);
414-
} else {
415-
LOG(error) << "CCDBDownloader: Malformed url detected when processing redirect, could not identify the host part: " << host;
410+
if (host_result != CURLUE_OK) {
411+
LOG(error) << "CCDBDownloader: Malformed url detected when processing redirect, could not identify the host part: " << full_host_url;
416412
curl_url_cleanup(host_url);
417413
return "";
418414
}
419415
// Get scheme (protocol) part
420416
char* scheme;
421417
CURLUcode scheme_result = curl_url_get(host_url, CURLUPART_SCHEME, &scheme, 0);
418+
// Get port
419+
char* port;
420+
CURLUcode port_result = curl_url_get(host_url, CURLUPART_PORT, &port, 0);
421+
422422
curl_url_cleanup(host_url);
423+
424+
// Assemble parts
425+
std::string trimmed_url = "";
423426
if (scheme_result == CURLUE_OK) {
424-
// If protocol present combine with host
425-
curl_free(scheme);
426-
return scheme + std::string("://") + host_name;
427-
} else {
428-
return host_name;
427+
trimmed_url += scheme + std::string("://");
428+
free(scheme);
429+
}
430+
trimmed_url += host;
431+
free(host);
432+
if (port_result == CURLUE_OK) {
433+
trimmed_url += std::string(":") + port;
434+
free(port);
429435
}
436+
return trimmed_url;
430437
}
431438

432439
std::string CCDBDownloader::prepareRedirectedURL(std::string address, std::string potentialHost) const
@@ -469,38 +476,36 @@ void CCDBDownloader::transferFinished(CURL* easy_handle, CURLcode curlCode)
469476
} break;
470477
case ASYNCHRONOUS: {
471478
DownloaderRequestData* requestData = performData->requestData;
472-
473479
if (requestData->headers) {
474480
for (auto& p : requestData->hoPair.header) {
475481
(*requestData->headers)[p.first] = p.second;
476482
}
477483
}
478-
if (requestData->errorflag && requestData->headers) {
479-
(*requestData->headers)["Error"] = "An error occurred during retrieval";
480-
}
481-
482484
// Log that transfer finished
483485
long httpCode;
484486
curl_easy_getinfo(easy_handle, CURLINFO_RESPONSE_CODE, &httpCode);
485487
char* url;
486488
curl_easy_getinfo(easy_handle, CURLINFO_EFFECTIVE_URL, &url);
487489
LOG(debug) << "Transfer for " << url << " finished with code " << httpCode << "\n";
490+
std::string currentHost = requestData->hosts[performData->hostInd];
491+
std::string loggingMessage = prepareLogMessage(currentHost, requestData->userAgent, requestData->path, requestData->timestamp, requestData->headers, httpCode);
488492

489493
// Get alternative locations for the same host
490494
auto locations = getLocations(&(requestData->hoPair.header));
491495

492496
// React to received http code
493-
if (404 == httpCode) {
494-
LOG(error) << "Requested resource does not exist: " << url;
495-
} else if (304 == httpCode) {
496-
LOGP(debug, "Object exists but I am not serving it since it's already in your possession");
497-
contentRetrieved = true;
498-
} else if (300 <= httpCode && httpCode < 400 && performData->locInd < locations.size()) {
499-
followRedirect(performData, easy_handle, locations, rescheduled, contentRetrieved);
500-
} else if (200 <= httpCode && httpCode < 300) {
501-
contentRetrieved = true;
497+
if (200 <= httpCode && httpCode < 400) {
498+
LOG(debug) << loggingMessage;
499+
if (304 == httpCode) {
500+
LOGP(debug, "Object exists but I am not serving it since it's already in your possession");
501+
contentRetrieved = true;
502+
} else if (300 <= httpCode && httpCode < 400 && performData->locInd < locations.size()) {
503+
followRedirect(performData, easy_handle, locations, rescheduled, contentRetrieved);
504+
} else if (200 <= httpCode && httpCode < 300) {
505+
contentRetrieved = true;
506+
}
502507
} else {
503-
LOG(error) << "Error in fetching object " << url << ", curl response code:" << httpCode;
508+
LOG(error) << loggingMessage;
504509
}
505510

506511
// Check if content was retrieved, or scheduled to be retrieved
@@ -516,12 +521,18 @@ void CCDBDownloader::transferFinished(CURL* easy_handle, CURLcode curlCode)
516521

517522
if (!rescheduled) {
518523
// No more transfers will be done for this request, do cleanup specific for ASYNCHRONOUS calls
519-
--(*performData->requestsLeft);
520-
delete requestData;
521-
delete performData->codeDestination;
522524
if (!contentRetrieved) {
525+
if (requestData->hoPair.object) {
526+
requestData->hoPair.object->clear();
527+
}
528+
if (requestData->headers) {
529+
(*requestData->headers)["Error"] = "An error occurred during retrieval";
530+
}
523531
LOGP(alarm, "Curl request to {}, response code: {}", url, httpCode);
524532
}
533+
--(*performData->requestsLeft);
534+
delete requestData;
535+
delete performData->codeDestination;
525536
}
526537
} break;
527538
}
@@ -687,4 +698,21 @@ void CCDBDownloader::asynchSchedule(CURL* handle, size_t* requestCounter)
687698
// return codeVector;
688699
}
689700

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+
690718
} // namespace o2

CCDB/src/CcdbApi.cxx

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ void CcdbApi::init(std::string const& host)
147147
// In addition, we can monitor exactly which objects are fetched and what is their content.
148148
// One can also distribute so obtained caches to sites without network access.
149149
//
150+
// THE INFORMATION BELOW IS TEMPORARILY WRONG: the functionality of checking the validity if IGNORE_VALIDITYCHECK_OF_CCDB_LOCALCACHE
151+
// is NOT set is broken. At the moment the code is modified to behave as if the IGNORE_VALIDITYCHECK_OF_CCDB_LOCALCACHE is always set
152+
// whenever the ALICEO2_CCDB_LOCALCACHE is defined.
153+
//
150154
// When used with the DPL CCDB fetcher (i.e. loadFileToMemory is called), in order to prefer the available snapshot w/o its validity
151155
// check an extra variable IGNORE_VALIDITYCHECK_OF_CCDB_LOCALCACHE must be defined, otherwhise the object will be fetched from the
152156
// server after the validity check and new snapshot will be created if needed
@@ -161,7 +165,7 @@ void CcdbApi::init(std::string const& host)
161165
}
162166
snapshotReport = fmt::format("(cache snapshots to dir={}", mSnapshotCachePath);
163167
}
164-
if (getenv("IGNORE_VALIDITYCHECK_OF_CCDB_LOCALCACHE")) {
168+
if (cachedir) { // || getenv("IGNORE_VALIDITYCHECK_OF_CCDB_LOCALCACHE")) {
165169
mPreferSnapshotCache = true;
166170
if (mSnapshotCachePath.empty()) {
167171
LOGP(fatal, "IGNORE_VALIDITYCHECK_OF_CCDB_LOCALCACHE is defined but the ALICEO2_CCDB_LOCALCACHE is not");
@@ -252,6 +256,10 @@ int CcdbApi::storeAsTFile_impl(const void* obj, std::type_info const& tinfo, std
252256
std::vector<char>::size_type maxSize) const
253257
{
254258
// We need the TClass for this type; will verify if dictionary exists
259+
if (!obj) {
260+
LOGP(error, "nullptr is provided for object {}/{}/{}", path, startValidityTimestamp, endValidityTimestamp);
261+
return -1;
262+
}
255263
CcdbObjectInfo info;
256264
auto img = createObjectImage(obj, tinfo, &info);
257265
return storeAsBinaryFile(img->data(), img->size(), info.getFileName(), info.getObjectType(),
@@ -372,6 +380,10 @@ int CcdbApi::storeAsTFile(const TObject* rootObject, std::string const& path, st
372380
long startValidityTimestamp, long endValidityTimestamp, std::vector<char>::size_type maxSize) const
373381
{
374382
// Prepare file
383+
if (!rootObject) {
384+
LOGP(error, "nullptr is provided for object {}/{}/{}", path, startValidityTimestamp, endValidityTimestamp);
385+
return -1;
386+
}
375387
CcdbObjectInfo info;
376388
auto img = createObjectImage(rootObject, &info);
377389
return storeAsBinaryFile(img->data(), img->size(), info.getFileName(), info.getObjectType(), path, metadata, startValidityTimestamp, endValidityTimestamp, maxSize);
@@ -1486,12 +1498,6 @@ void CcdbApi::scheduleDownload(RequestContext& requestContext, size_t* requestCo
14861498
auto data = new DownloaderRequestData(); // Deleted in transferFinished of CCDBDownloader.cxx
14871499
data->hoPair.object = &requestContext.dest;
14881500

1489-
auto signalError = [&chunk = requestContext.dest, &errorflag = data->errorflag]() {
1490-
chunk.clear();
1491-
chunk.reserve(1);
1492-
errorflag = true;
1493-
};
1494-
14951501
std::function<bool(std::string)> localContentCallback = [this, &requestContext](std::string url) {
14961502
return this->loadLocalContentToMemory(requestContext.dest, url);
14971503
};
@@ -1533,6 +1539,7 @@ void CcdbApi::scheduleDownload(RequestContext& requestContext, size_t* requestCo
15331539
data->path = requestContext.path;
15341540
data->timestamp = requestContext.timestamp;
15351541
data->localContentCallback = localContentCallback;
1542+
data->userAgent = mUniqueAgentID;
15361543

15371544
curl_easy_setopt(curl_handle, CURLOPT_URL, fullUrl.c_str());
15381545
initCurlOptionsForRetrieve(curl_handle, (void*)(&data->hoPair), writeCallback, false);
@@ -1570,7 +1577,7 @@ void CcdbApi::releaseNamedSemaphore(boost::interprocess::named_semaphore* sem, s
15701577
}
15711578

15721579
void CcdbApi::getFromSnapshot(bool createSnapshot, std::string const& path,
1573-
long timestamp, std::map<std::string, std::string> headers,
1580+
long timestamp, std::map<std::string, std::string>& headers,
15741581
std::string& snapshotpath, o2::pmr::vector<char>& dest, int& fromSnapshot, std::string const& etag) const
15751582
{
15761583
if (createSnapshot) { // create named semaphore
@@ -1580,9 +1587,10 @@ void CcdbApi::getFromSnapshot(bool createSnapshot, std::string const& path,
15801587
logStream << "CCDB-access[" << getpid() << "] of " << mUniqueAgentID << " to " << path << " timestamp " << timestamp << " for load to memory\n";
15811588
}
15821589
}
1583-
15841590
if (mInSnapshotMode) { // file must be there, otherwise a fatal will be produced;
1585-
loadFileToMemory(dest, getSnapshotFile(mSnapshotTopPath, path), &headers);
1591+
if (etag.empty()) {
1592+
loadFileToMemory(dest, getSnapshotFile(mSnapshotTopPath, path), &headers);
1593+
}
15861594
fromSnapshot = 1;
15871595
} else if (mPreferSnapshotCache && std::filesystem::exists(snapshotpath)) {
15881596
// if file is available, use it, otherwise cache it below from the server. Do this only when etag is empty since otherwise the object was already fetched and cached
@@ -1671,8 +1679,6 @@ void CcdbApi::vectoredLoadFileToMemory(std::vector<RequestContext>& requestConte
16711679
// navigateSourcesAndLoadFile either retrieves file from snapshot immediately, or schedules it to be downloaded when mDownloader->runLoop is ran at a later time
16721680
auto& requestContext = requestContexts.at(i);
16731681
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" : ""));
16761682
}
16771683

16781684
// Download the rest
@@ -1683,12 +1689,12 @@ void CcdbApi::vectoredLoadFileToMemory(std::vector<RequestContext>& requestConte
16831689
// Save snapshots
16841690
for (int i = 0; i < requestContexts.size(); i++) {
16851691
auto& requestContext = requestContexts.at(i);
1692+
logReading(requestContext.path, requestContext.timestamp, &requestContext.headers,
1693+
fmt::format("{}{}", requestContext.considerSnapshot ? "load to memory" : "retrieve", fromSnapshots.at(i) ? " from snapshot" : ""));
16861694
if (!requestContext.dest.empty()) {
16871695
if (requestContext.considerSnapshot && fromSnapshots.at(i) != 2) {
16881696
saveSnapshot(requestContext);
16891697
}
1690-
} else {
1691-
LOG(warning) << "Did not receive content for " << requestContext.path << "\n"; // Temporarily demoted to warning, since it floods the infologger
16921698
}
16931699
}
16941700
}

CCDB/test/testCcdbApiDownloader.cxx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,5 +381,15 @@ BOOST_AUTO_TEST_CASE(external_loop_test)
381381
delete uvLoop;
382382
}
383383

384+
BOOST_AUTO_TEST_CASE(trim_host_url_test)
385+
{
386+
CCDBDownloader downloader;
387+
BOOST_CHECK(downloader.trimHostUrl("http://localhost:8080") == "http://localhost:8080");
388+
BOOST_CHECK(downloader.trimHostUrl("http://localhost") == "http://localhost");
389+
BOOST_CHECK(downloader.trimHostUrl("http://localhost:8080/some/path") == "http://localhost:8080");
390+
BOOST_CHECK(downloader.trimHostUrl("http://localhost/some/path") == "http://localhost");
391+
BOOST_CHECK(downloader.trimHostUrl("http://localhost:8080/Task/Detector/1?HTTPOnly=true") == "http://localhost:8080");
392+
}
393+
384394
} // namespace ccdb
385395
} // namespace o2

Common/Constants/include/CommonConstants/MathConstants.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace constants
2323
namespace math
2424
{
2525
constexpr float Almost0 = 1.17549e-38;
26-
constexpr float Almost1 = 1.f - Almost0;
26+
constexpr float Almost1 = 1.f - 1.0e-6;
2727
constexpr float VeryBig = 1.f / Almost0;
2828

2929
constexpr float PI = 3.14159274101257324e+00f;

0 commit comments

Comments
 (0)