Skip to content

Commit 3534a2d

Browse files
authored
Merge branch 'dev' into monopoles
2 parents 399d3ac + 626c2ad commit 3534a2d

641 files changed

Lines changed: 30966 additions & 8464 deletions

File tree

Some content is hidden

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

.clang-format

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,7 @@ UseTab: Never
5454
# Do not format protobuf files
5555
Language: Proto
5656
DisableFormat: true
57+
---
58+
# Do not format JSON configuration files
59+
Language: Json
60+
DisableFormat: true

.github/workflows/clean-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ name: Clean PR checks
2424
type: boolean
2525
default: true
2626
'check_build/O2/fullCI_slc9':
27-
description: build/O2/fullCI
27+
description: build/O2/fullCI_slc9
2828
type: boolean
2929
default: true
3030
'check_build/O2/o2-dataflow-slc9':

.github/workflows/stale.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
stale:
88
runs-on: ubuntu-latest
99
steps:
10-
- uses: actions/stale@v10
10+
- uses: actions/stale@v11
1111
with:
1212
repo-token: ${{ secrets.GITHUB_TOKEN }}
1313
stale-pr-message: 'This PR did not have any update in the last 30 days. Is it still needed? Unless further action in will be closed in 5 days.'

CCDB/include/CCDB/CCDBDownloader.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ typedef struct DownloaderRequestData {
5353
HeaderObjectPair_t hoPair;
5454
std::map<std::string, std::string>* headers;
5555
std::string userAgent;
56-
curl_slist* optionsList;
56+
// One header list per entry of `hosts`, parallel to it. Per host and not one
57+
// shared list because the gate token a broker expects is per endpoint: a
58+
// multi-host pool can mix them, and tryNewHost() swapping only the URL left
59+
// the second host receiving the first host's token -- answered 401, so the
60+
// failover silently retrieved nothing (testCcdbApi multi_host_test).
61+
std::vector<curl_slist*> optionsLists;
5762

5863
std::function<bool(std::string)> localContentCallback;
5964
} DownloaderRequestData;
@@ -304,7 +309,8 @@ class CCDBDownloader
304309
int hostInd;
305310
int locInd;
306311
DownloaderRequestData* requestData;
307-
curl_slist** options;
312+
// Freed by transferFinished; indexed by hostInd, see DownloaderRequestData.
313+
std::vector<curl_slist*>* options;
308314
} PerformData;
309315
#endif
310316

CCDB/include/CCDB/CcdbApi.h

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
#define PROJECT_CCDBAPI_H
1919

2020
#include <string>
21+
#include <string_view>
2122
#include <memory>
2223
#include <map>
23-
#include <curl/curl.h>
2424
#include <TObject.h>
2525
#include <TMessage.h>
2626
#include "CCDB/CcdbObjectInfo.h"
@@ -36,17 +36,20 @@
3636
class TJAlienCredentials;
3737
#endif
3838

39-
#include "CCDB/CCDBDownloader.h"
39+
// libcurl and the downloader are implementation details of CcdbApi.cxx;
40+
// only opaque handles appear below, so neither header is needed here.
41+
struct curl_slist;
4042

4143
class TFile;
42-
class TGrid;
44+
#include <TGrid.h>
4345

4446
namespace o2
4547
{
4648
namespace ccdb
4749
{
4850

4951
class CCDBQuery;
52+
class CCDBDownloader;
5053

5154
/**
5255
* Interface to the CCDB.
@@ -56,6 +59,9 @@ class CCDBQuery;
5659
* @todo handle errors and exceptions
5760
* @todo extend code coverage
5861
*/
62+
/// stands in for libcurl's `typedef void CURL` without including <curl/curl.h>
63+
using CurlHandle = void;
64+
5965
class CcdbApi //: public DatabaseInterface
6066
{
6167
public:
@@ -341,7 +347,7 @@ class CcdbApi //: public DatabaseInterface
341347
* @param curl curl handler
342348
* @return
343349
*/
344-
static void curlSetSSLOptions(CURL* curl);
350+
static void curlSetSSLOptions(CurlHandle* curl);
345351

346352
TObject* retrieve(std::string const& path, std::map<std::string, std::string> const& metadata, long timestamp) const;
347353

@@ -441,7 +447,7 @@ class CcdbApi //: public DatabaseInterface
441447
* @param handle CURL handle associated with the request.
442448
* @param requestCounter Pointer to the variable storing the number of requests to be done.
443449
*/
444-
void asynchPerform(CURL* handle, size_t* requestCounter) const;
450+
void asynchPerform(CurlHandle* handle, size_t* requestCounter) const;
445451

446452
// internal helper function to update a CCDB file with meta information
447453
static void updateMetaInformationInLocalFile(std::string const& filename, std::map<std::string, std::string> const* headers, CCDBQuery const* querysummary = nullptr);
@@ -477,7 +483,7 @@ class CcdbApi //: public DatabaseInterface
477483
* @param endValidityTimestamp End of validity. If omitted or negative, current timestamp + 1 day is used.
478484
* @return The full url to store an object (url / startValidity / endValidity / [metadata &]* )
479485
*/
480-
std::string getFullUrlForStorage(CURL* curl, const std::string& path, const std::string& objtype,
486+
std::string getFullUrlForStorage(CurlHandle* curl, const std::string& path, const std::string& objtype,
481487
const std::map<std::string, std::string>& metadata,
482488
long startValidityTimestamp = -1, long endValidityTimestamp = -1, int hostIndex = 0) const;
483489

@@ -488,7 +494,7 @@ class CcdbApi //: public DatabaseInterface
488494
* @param timestamp When the object we retrieve must be valid. If omitted or negative, the current timestamp is used.
489495
* @return The full url to store an object (url / startValidity / endValidity / [metadata &]* )
490496
*/
491-
std::string getFullUrlForRetrieval(CURL* curl, const std::string& path, const std::map<std::string, std::string>& metadata,
497+
std::string getFullUrlForRetrieval(CurlHandle* curl, const std::string& path, const std::map<std::string, std::string>& metadata,
492498
long timestamp = -1, int hostIndex = 0) const;
493499

494500
public:
@@ -563,25 +569,24 @@ class CcdbApi //: public DatabaseInterface
563569

564570
/// Queries the CCDB server and navigates through possible redirects until binary content is found; Retrieves content as instance
565571
/// given by tinfo if that is possible. Returns nullptr if something fails...
566-
void* navigateURLsAndRetrieveContent(CURL*, std::string const& url, std::type_info const& tinfo, std::map<std::string, std::string>* headers) const;
572+
void* navigateURLsAndRetrieveContent(CurlHandle*, std::string const& url, std::type_info const& tinfo, std::map<std::string, std::string>* headers) const;
567573

568574
// helper that interprets a content chunk as TMemFile and extracts the object therefrom
569575
static void* interpretAsTMemFileAndExtract(char* contentptr, size_t contentsize, std::type_info const& tinfo);
570576

571577
/**
572-
* Initialization of CURL
573-
*/
578+
* Initialization of CurlHandle*/
574579
void curlInit();
575580

576581
// convert type_info to TClass, throw on failure
577582
static TClass* tinfo2TClass(std::type_info const& tinfo);
578583

579584
typedef size_t (*CurlWriteCallback)(void*, size_t, size_t, void*);
580585

581-
void initCurlOptionsForRetrieve(CURL* curlHandle, void* pointer, CurlWriteCallback writeCallback, bool followRedirect = true) const;
586+
void initCurlOptionsForRetrieve(CurlHandle* curlHandle, void* pointer, CurlWriteCallback writeCallback, bool followRedirect = true) const;
582587

583588
/// initialize HTTPS header information for the CURL handle. Needs to be given an existing curl_slist* pointer to work with (may be nullptr), which needs to be free by the caller.
584-
void initCurlHTTPHeaderOptionsForRetrieve(CURL* curlHandle, curl_slist*& option_list, long timestamp, std::map<std::string, std::string>* headers, std::string const& etag, const std::string& createdNotAfter, const std::string& createdNotBefore) const;
589+
void initCurlHTTPHeaderOptionsForRetrieve(CurlHandle* curlHandle, curl_slist*& option_list, long timestamp, std::map<std::string, std::string>* headers, std::string const& etag, const std::string& createdNotAfter, const std::string& createdNotBefore, std::string_view url) const;
585590

586591
bool receiveToFile(FILE* fileHandle, std::string const& path, std::map<std::string, std::string> const& metadata,
587592
long timestamp, std::map<std::string, std::string>* headers = nullptr, std::string const& etag = "",
@@ -627,7 +632,7 @@ class CcdbApi //: public DatabaseInterface
627632

628633
// tmp helper and single point of entry for a CURL perform call
629634
// helps to switch between easy handle perform and multi handles in a single place
630-
CURLcode CURL_perform(CURL* handle) const;
635+
int CURL_perform(CurlHandle* handle) const; // returns a CURLcode
631636

632637
mutable CCDBDownloader* mDownloader = nullptr; //! the multi-handle (async) CURL downloader
633638
bool mIsCCDBDownloaderPreferred = false;

CCDB/src/CCDBDownloader.cxx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,14 @@ void CCDBDownloader::tryNewHost(PerformData* performData, CURL* easy_handle)
365365
LOG(debug) << "Connecting to another host " << newUrl << "\n";
366366
requestData->hoPair.header.clear();
367367
curl_easy_setopt(easy_handle, CURLOPT_URL, newUrl.c_str());
368+
// The headers travel with the host, not with the request: a broker mints its
369+
// gate token per endpoint, so carrying the previous host's list here is what
370+
// made the failover arrive unauthenticated. The lists are built per host by
371+
// CcdbApi::scheduleDownload, which is where the token table is visible.
372+
if (performData->hostInd < static_cast<int>(requestData->optionsLists.size())) {
373+
curl_easy_setopt(easy_handle, CURLOPT_HTTPHEADER,
374+
requestData->optionsLists.at(performData->hostInd));
375+
}
368376
mHandlesToBeAdded.push_back(easy_handle);
369377
}
370378

@@ -568,7 +576,9 @@ void CCDBDownloader::transferFinished(CURL* easy_handle, CURLcode curlCode)
568576
}
569577
}
570578
--(*performData->requestsLeft);
571-
curl_slist_free_all(*performData->options);
579+
for (auto* optionList : *performData->options) {
580+
curl_slist_free_all(optionList);
581+
}
572582
delete requestData;
573583
delete performData->codeDestination;
574584
curl_easy_cleanup(easy_handle);
@@ -729,7 +739,7 @@ void CCDBDownloader::asynchSchedule(CURL* handle, size_t* requestCounter)
729739
curl_easy_getinfo(handle, CURLINFO_PRIVATE, &requestData);
730740
headerMap = &(requestData->hoPair.header);
731741
hostsPool = &(requestData->hosts);
732-
auto* options = &(requestData->optionsList);
742+
auto* options = &(requestData->optionsLists);
733743

734744
// Prepare temporary data about transfer
735745
auto* data = new CCDBDownloader::PerformData(); // Freed in transferFinished

0 commit comments

Comments
 (0)