Skip to content

Commit 67059d1

Browse files
committed
Revert "CcdbApi.loadFileToMemory changed to a vectored operation"
This reverts commit ec9ee0b.
1 parent 5708f66 commit 67059d1

File tree

6 files changed

+234
-648
lines changed

6 files changed

+234
-648
lines changed

CCDB/include/CCDB/CCDBDownloader.h

Lines changed: 8 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111
#ifndef O2_CCDBDOWNLOADER_H_
1212
#define O2_CCDBDOWNLOADER_H_
1313

14-
#if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__ROOTCLING__) && !defined(__CLING__)
15-
#include "MemoryResources/MemoryResources.h"
16-
#endif
17-
1814
#include <cstdio>
1915
#include <cstdlib>
2016
#include <curl/curl.h>
@@ -25,8 +21,6 @@
2521
#include <mutex>
2622
#include <condition_variable>
2723
#include <unordered_map>
28-
#include <map>
29-
#include <functional>
3024

3125
typedef struct uv_loop_s uv_loop_t;
3226
typedef struct uv_timer_s uv_timer_t;
@@ -38,25 +32,6 @@ typedef struct uv_handle_s uv_handle_t;
3832
namespace o2::ccdb
3933
{
4034

41-
#if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__ROOTCLING__) && !defined(__CLING__)
42-
struct HeaderObjectPair_t {
43-
std::multimap<std::string, std::string> header;
44-
o2::pmr::vector<char>* object = nullptr;
45-
int counter = 0;
46-
};
47-
48-
typedef struct DownloaderRequestData {
49-
std::vector<std::string> hosts;
50-
std::string path;
51-
long timestamp;
52-
HeaderObjectPair_t hoPair;
53-
std::map<std::string, std::string>* headers;
54-
55-
std::function<bool(std::string)> localContentCallback;
56-
bool errorflag = false;
57-
} DownloaderRequestData;
58-
#endif
59-
6035
/*
6136
Some functions below aren't member functions of CCDBDownloader because both curl and libuv require callback functions which have to be either static or non-member.
6237
Because non-static functions are used in the functions below, they must be non-member.
@@ -158,14 +133,6 @@ class CCDBDownloader
158133
*/
159134
std::vector<CURLcode> batchBlockingPerform(std::vector<CURL*> const& handleVector);
160135

161-
/**
162-
* Schedules an asynchronous transfer but doesn't perform it.
163-
*
164-
* @param handle Handle to be performed on.
165-
* @param requestCounter Counter shared by a batch of CURL handles.
166-
*/
167-
void asynchSchedule(CURL* handle, size_t* requestCounter);
168-
169136
/**
170137
* Limits the number of parallel connections. Should be used only if no transfers are happening.
171138
*/
@@ -209,14 +176,6 @@ class CCDBDownloader
209176
void runLoop(bool noWait);
210177

211178
private:
212-
/**
213-
* Returns a vector of possible content locations based on the redirect headers.
214-
*
215-
* @param baseUrl Content path.
216-
* @param headerMap Map containing response headers.
217-
*/
218-
std::vector<std::string> getLocations(std::string baseUrl, std::multimap<std::string, std::string>* headerMap) const;
219-
220179
std::string mUserAgentId = "CCDBDownloader";
221180
/**
222181
* Sets up internal UV loop.
@@ -248,7 +207,8 @@ class CCDBDownloader
248207
*/
249208
enum RequestType {
250209
BLOCKING,
251-
ASYNCHRONOUS
210+
ASYNCHRONOUS,
211+
ASYNCHRONOUS_WITH_CALLBACK
252212
};
253213

254214
/**
@@ -270,19 +230,20 @@ class CCDBDownloader
270230

271231
DataForSocket mSocketData;
272232

273-
#if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__ROOTCLING__) && !defined(__CLING__)
274233
/**
275234
* Structure which is stored in a easy_handle. It carries information about the request which the easy_handle is part of.
235+
* All easy handles coming from one request have an identical PerformData structure.
276236
*/
277237
typedef struct PerformData {
238+
std::condition_variable* cv;
239+
bool* completionFlag;
278240
CURLcode* codeDestination;
241+
void (*cbFun)(void*);
242+
std::thread* cbThread;
243+
void* cbData;
279244
size_t* requestsLeft;
280245
RequestType type;
281-
int hostInd;
282-
int locInd;
283-
DownloaderRequestData* requestData;
284246
} PerformData;
285-
#endif
286247

287248
/**
288249
* Called by CURL in order to close a socket. It will be called by CURL even if a timeout timer closed the socket beforehand.
@@ -292,20 +253,6 @@ class CCDBDownloader
292253
*/
293254
static void closesocketCallback(void* clientp, curl_socket_t item);
294255

295-
#if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__ROOTCLING__) && !defined(__CLING__)
296-
// Reschedules the transfer to be performed with a different host.
297-
void tryNewHost(PerformData* performData, CURL* easy_handle);
298-
299-
// Retrieves content from either alien, cvmfs or local storage using a callback to CCDBApi.
300-
void getLocalContent(PerformData* performData, std::string& newUrl, std::string& newLocation, bool& contentRetrieved, std::vector<std::string>& locations);
301-
302-
// Continues a transfer via a http redirect.
303-
void httpRedirect(PerformData* performData, std::string& newUrl, std::string& newLocation, CURL* easy_handle);
304-
305-
// Continues a transfer via a redirect. The redirect can point to a local file, alien file or a http address.
306-
void followRedirect(PerformData* performData, CURL* easy_handle, std::vector<std::string>& locations, bool& rescheduled, bool& contentRetrieved);
307-
#endif
308-
309256
/**
310257
* Is used to react to polling file descriptors in poll_handle.
311258
*
@@ -375,12 +322,10 @@ class CCDBDownloader
375322
*/
376323
void checkMultiInfo();
377324

378-
#if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__ROOTCLING__) && !defined(__CLING__)
379325
/**
380326
* Set openSocketCallback and closeSocketCallback with appropriate arguments. Stores data inside the CURL handle.
381327
*/
382328
void setHandleOptions(CURL* handle, PerformData* data);
383-
#endif
384329

385330
/**
386331
* Create structure holding information about a socket including a poll handle assigned to it

CCDB/include/CCDB/CcdbApi.h

Lines changed: 4 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,18 @@
2424
#include <TObject.h>
2525
#include <TMessage.h>
2626
#include "CCDB/CcdbObjectInfo.h"
27+
#include "CCDB/CCDBDownloader.h"
2728
#include <CommonUtils/ConfigurableParam.h>
2829
#include <type_traits>
2930
#include <vector>
3031

3132
#if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__ROOTCLING__) && !defined(__CLING__)
3233
#include "MemoryResources/MemoryResources.h"
33-
#include <boost/interprocess/sync/named_semaphore.hpp>
3434
#include <TJAlienCredentials.h>
3535
#else
3636
class TJAlienCredentials;
3737
#endif
3838

39-
#include "CCDB/CCDBDownloader.h"
40-
4139
class TFile;
4240
class TGrid;
4341

@@ -344,43 +342,14 @@ class CcdbApi //: public DatabaseInterface
344342
TObject* retrieveFromTFile(std::string const& path, std::map<std::string, std::string> const& metadata, long timestamp,
345343
std::map<std::string, std::string>* headers, std::string const& etag,
346344
const std::string& createdNotAfter, const std::string& createdNotBefore) const;
345+
347346
#if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__ROOTCLING__) && !defined(__CLING__)
348-
typedef struct RequestContext {
349-
o2::pmr::vector<char>& dest;
350-
std::string path;
351-
std::map<std::string, std::string> const& metadata;
352-
long timestamp;
353-
std::map<std::string, std::string>& headers;
354-
std::string etag;
355-
std::string createdNotAfter;
356-
std::string createdNotBefore;
357-
bool considerSnapshot;
358-
359-
RequestContext(o2::pmr::vector<char>& d,
360-
std::map<std::string, std::string> const& m,
361-
std::map<std::string, std::string>& h)
362-
: dest(d), metadata(m), headers(h) {}
363-
} RequestContext;
364-
365-
// Stores file associated with requestContext as a snapshot.
366-
void saveSnapshot(RequestContext& requestContext) const;
367-
368-
// Schedules download via CCDBDownloader, but doesn't perform it until mUVLoop is ran.
369-
void scheduleDownload(RequestContext& requestContext, size_t* requestCounter) const;
370-
371-
void getFromSnapshot(bool createSnapshot, std::string const& path,
372-
long timestamp, std::map<std::string, std::string> headers,
373-
std::string& snapshotpath, o2::pmr::vector<char>& dest, int& fromSnapshot, std::string const& etag) const;
374-
void releaseNamedSemaphore(boost::interprocess::named_semaphore* sem, std::string path) const;
375-
boost::interprocess::named_semaphore* createNamedSempahore(std::string path) const;
376347
void loadFileToMemory(o2::pmr::vector<char>& dest, const std::string& path, std::map<std::string, std::string>* localHeaders = nullptr) const;
377348
void loadFileToMemory(o2::pmr::vector<char>& dest, std::string const& path,
378349
std::map<std::string, std::string> const& metadata, long timestamp,
379350
std::map<std::string, std::string>* headers, std::string const& etag,
380351
const std::string& createdNotAfter, const std::string& createdNotBefore, bool considerSnapshot = true) const;
381-
382-
// Loads files from alien and cvmfs into given destination.
383-
bool loadLocalContentToMemory(o2::pmr::vector<char>& dest, std::string& url) const;
352+
void navigateURLsAndLoadFileToMemory(o2::pmr::vector<char>& dest, CURL* curl_handle, std::string const& url, std::map<string, string>* headers) const;
384353

385354
// the failure to load the file to memory is signaled by 0 size and non-0 capacity
386355
static bool isMemoryFileInvalid(const o2::pmr::vector<char>& v) { return v.size() == 0 && v.capacity() > 0; }
@@ -395,36 +364,12 @@ class CcdbApi //: public DatabaseInterface
395364
}
396365
return obj;
397366
}
398-
399-
/**
400-
* Retrieves files either as snapshot or schedules them to be downloaded via CCDBDownloader.
401-
*
402-
* @param requestContext Structure giving details about the transfer.
403-
* @param fromSnapshot After navigateSourcesAndLoadFile returns signals whether file was retrieved from snapshot.
404-
* @param requestCounter Pointer to the variable storing the number of requests to be done.
405-
*/
406-
void navigateSourcesAndLoadFile(RequestContext& requestContext, int& fromSnapshot, size_t* requestCounter) const;
407-
408-
/**
409-
* Retrieves files described via RequestContexts into memory. Downloads are performed in parallel via CCDBDownloader.
410-
*
411-
* @param requestContext Structure giving details about the transfer.
412-
*/
413-
void vectoredLoadFileToMemory(std::vector<RequestContext>& requestContext) const;
414367
#endif
415368

416369
private:
417370
// Sets the unique agent ID
418371
void setUniqueAgentID();
419372

420-
/**
421-
* Schedules download of data associated with the curl_handle. Doing that increments the requestCounter by 1. Requests are performed by running the mUVLoop
422-
*
423-
* @param handle CURL handle associated with the request.
424-
* @param requestCounter Pointer to the variable storing the number of requests to be done.
425-
*/
426-
void asynchPerform(CURL* handle, size_t* requestCounter) const;
427-
428373
// internal helper function to update a CCDB file with meta information
429374
static void updateMetaInformationInLocalFile(std::string const& filename, std::map<std::string, std::string> const* headers, CCDBQuery const* querysummary = nullptr);
430375

@@ -605,7 +550,7 @@ class CcdbApi //: public DatabaseInterface
605550
CURLcode CURL_perform(CURL* handle) const;
606551

607552
mutable CCDBDownloader* mDownloader = nullptr; //! the multi-handle (async) CURL downloader
608-
bool mIsCCDBDownloaderPreferred = false;
553+
bool mIsCCDBDownloaderEnabled = false;
609554
/// Base URL of the CCDB (with port)
610555
std::string mUniqueAgentID{}; // Unique User-Agent ID communicated to server for logging
611556
std::string mUrl{};

0 commit comments

Comments
 (0)