Skip to content

Commit 22c7835

Browse files
njacazioshahor02
authored andcommitted
Add CCDB limitation to If-Not-Before
1 parent e51a642 commit 22c7835

4 files changed

Lines changed: 47 additions & 17 deletions

File tree

CCDB/include/CCDB/BasicCCDBManager.h

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ class BasicCCDBManager
101101
/// reset the object upper validity limit
102102
void resetCreatedNotAfter() { mCreatedNotAfter = 0; }
103103

104+
/// set the object upper validity limit
105+
void setCreatedNotBefore(long v) { mCreatedNotBefore = v; }
106+
107+
/// get the object upper validity limit
108+
long getCreatedNotBefore() const { return mCreatedNotBefore; }
109+
110+
/// reset the object upper validity limit
111+
void resetCreatedNotBefore() { mCreatedNotBefore = 0; }
112+
104113
private:
105114
BasicCCDBManager(std::string const& path) : mCCDBAccessor{}
106115
{
@@ -110,22 +119,27 @@ class BasicCCDBManager
110119
// we access the CCDB via the CURL based C++ API
111120
o2::ccdb::CcdbApi mCCDBAccessor;
112121
std::unordered_map<std::string, CachedObject> mCache; //! map for {path, CachedObject} associations
113-
std::map<std::string, std::string> mMetaData; // some dummy object needed to talk to CCDB API
114-
std::map<std::string, std::string> mHeaders; // headers to retrieve tags
115-
long mTimestamp{o2::ccdb::getCurrentTimestamp()}; // timestamp to be used for query (by default "now")
116-
bool mCanDefault = false; // whether default is ok --> useful for testing purposes done standalone/isolation
117-
bool mCachingEnabled = true; // whether caching is enabled
118-
long mCreatedNotAfter = 0; // upper limit for object creation timestamp (TimeMachine mode)
122+
std::map<std::string, std::string> mMetaData; // some dummy object needed to talk to CCDB API
123+
std::map<std::string, std::string> mHeaders; // headers to retrieve tags
124+
long mTimestamp{o2::ccdb::getCurrentTimestamp()}; // timestamp to be used for query (by default "now")
125+
bool mCanDefault = false; // whether default is ok --> useful for testing purposes done standalone/isolation
126+
bool mCachingEnabled = true; // whether caching is enabled
127+
long mCreatedNotAfter = 0; // upper limit for object creation timestamp (TimeMachine mode) - If-Not-After HTTP header
128+
long mCreatedNotBefore = 0; // lower limit for object creation timestamp (TimeMachine mode) - If-Not-Before HTTP header
119129
};
120130

121131
template <typename T>
122132
T* BasicCCDBManager::getForTimeStamp(std::string const& path, long timestamp)
123133
{
124134
if (!isCachingEnabled()) {
125-
return mCCDBAccessor.retrieveFromTFileAny<T>(path, mMetaData, timestamp, nullptr, "", mCreatedNotAfter ? std::to_string(mCreatedNotAfter) : "");
135+
return mCCDBAccessor.retrieveFromTFileAny<T>(path, mMetaData, timestamp, nullptr, "",
136+
mCreatedNotAfter ? std::to_string(mCreatedNotAfter) : "",
137+
mCreatedNotBefore ? std::to_string(mCreatedNotBefore) : "");
126138
}
127139
auto& cached = mCache[path];
128-
T* ptr = mCCDBAccessor.retrieveFromTFileAny<T>(path, mMetaData, timestamp, &mHeaders, cached.uuid, mCreatedNotAfter ? std::to_string(mCreatedNotAfter) : "");
140+
T* ptr = mCCDBAccessor.retrieveFromTFileAny<T>(path, mMetaData, timestamp, &mHeaders, cached.uuid,
141+
mCreatedNotAfter ? std::to_string(mCreatedNotAfter) : "",
142+
mCreatedNotBefore ? std::to_string(mCreatedNotBefore) : "");
129143
if (ptr) { // new object was shipped, old one (if any) is not valid anymore
130144
cached.objPtr.reset(ptr);
131145
cached.uuid = mHeaders["ETag"];

CCDB/include/CCDB/CcdbApi.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,14 @@ class CcdbApi //: public DatabaseInterface
149149
* @param timestamp Timestamp of the object to retrieve. If omitted, current timestamp is used.
150150
* @param headers Map to be populated with the headers we received, if it is not null.
151151
* @param optional etag from previous call
152-
* @param optional createdNotAfter time limit for the object creation timestamp (TimeMachine mode)
152+
* @param optional createdNotAfter upper time limit for the object creation timestamp (TimeMachine mode)
153+
* @param optional createdNotBefore lower time limit for the object creation timestamp (TimeMachine mode)
153154
* @return the object, or nullptr if none were found.
154155
* @deprecated in favour of retrieveFromTFileAny as it is not limited to TObjects.
155156
*/
156157
TObject* retrieveFromTFile(std::string const& path, std::map<std::string, std::string> const& metadata,
157158
long timestamp = -1, std::map<std::string, std::string>* headers = nullptr, std::string const& etag = "",
158-
const std::string& createdNotAfter = "") const;
159+
const std::string& createdNotAfter = "", const std::string& createdNotBefore = "") const;
159160

160161
/**
161162
* Retrieve object at the given path for the given timestamp.
@@ -165,13 +166,14 @@ class CcdbApi //: public DatabaseInterface
165166
* @param timestamp Timestamp of the object to retrieve. If omitted, current timestamp is used.
166167
* @param headers Map to be populated with the headers we received, if it is not null.
167168
* @param optional etag from previous call
168-
* @param optional createdNotAfter time limit for the object creation timestamp (TimeMachine mode)
169+
* @param optional createdNotAfter upper time limit for the object creation timestamp (TimeMachine mode)
170+
* @param optional createdNotBefore lower time limit for the object creation timestamp (TimeMachine mode)
169171
* @return the object, or nullptr if none were found or type does not match serialized type.
170172
*/
171173
template <typename T>
172174
T* retrieveFromTFileAny(std::string const& path, std::map<std::string, std::string> const& metadata,
173175
long timestamp = -1, std::map<std::string, std::string>* headers = nullptr, std::string const& etag = "",
174-
const std::string& createdNotAfter = "") const;
176+
const std::string& createdNotAfter = "", const std::string& createdNotBefore = "") const;
175177

176178
/**
177179
* Delete all versions of the object at this path.
@@ -365,7 +367,7 @@ class CcdbApi //: public DatabaseInterface
365367
*/
366368
void* retrieveFromTFile(std::type_info const&, std::string const& path, std::map<std::string, std::string> const& metadata,
367369
long timestamp = -1, std::map<std::string, std::string>* headers = nullptr, std::string const& etag = "",
368-
const std::string& createdNotAfter = "") const;
370+
const std::string& createdNotAfter = "", const std::string& createdNotBefore = "") const;
369371

370372
/**
371373
* A helper function to extract object from a local ROOT file
@@ -391,9 +393,9 @@ class CcdbApi //: public DatabaseInterface
391393
template <typename T>
392394
T* CcdbApi::retrieveFromTFileAny(std::string const& path, std::map<std::string, std::string> const& metadata,
393395
long timestamp, std::map<std::string, std::string>* headers, std::string const& etag,
394-
const std::string& createdNotAfter) const
396+
const std::string& createdNotAfter, const std::string& createdNotBefore) const
395397
{
396-
return static_cast<T*>(retrieveFromTFile(typeid(T), path, metadata, timestamp, headers, etag, createdNotAfter));
398+
return static_cast<T*>(retrieveFromTFile(typeid(T), path, metadata, timestamp, headers, etag, createdNotAfter, createdNotBefore));
397399
}
398400

399401
} // namespace ccdb

CCDB/src/CcdbApi.cxx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ size_t header_map_callback(char* buffer, size_t size, size_t nitems, void* userd
407407

408408
TObject* CcdbApi::retrieveFromTFile(std::string const& path, std::map<std::string, std::string> const& metadata,
409409
long timestamp, std::map<std::string, std::string>* headers, std::string const& etag,
410-
const std::string& createdNotAfter) const
410+
const std::string& createdNotAfter, const std::string& createdNotBefore) const
411411
{
412412
// Note : based on https://curl.haxx.se/libcurl/c/getinmemory.html
413413
// Thus it does not comply to our coding guidelines as it is a copy paste.
@@ -451,6 +451,10 @@ TObject* CcdbApi::retrieveFromTFile(std::string const& path, std::map<std::strin
451451
list = curl_slist_append(list, ("If-Not-After: " + createdNotAfter).c_str());
452452
}
453453

454+
if (!createdNotBefore.empty()) {
455+
list = curl_slist_append(list, ("If-Not-Before: " + createdNotBefore).c_str());
456+
}
457+
454458
// setup curl for headers handling
455459
if (headers != nullptr) {
456460
list = curl_slist_append(list, ("If-None-Match: " + to_string(timestamp)).c_str());
@@ -642,7 +646,7 @@ void* CcdbApi::extractFromLocalFile(std::string const& filename, TClass const* t
642646
void* CcdbApi::retrieveFromTFile(std::type_info const& tinfo, std::string const& path,
643647
std::map<std::string, std::string> const& metadata, long timestamp,
644648
std::map<std::string, std::string>* headers, std::string const& etag,
645-
const std::string& createdNotAfter) const
649+
const std::string& createdNotAfter, const std::string& createdNotBefore) const
646650
{
647651
// We need the TClass for this type; will verify if dictionary exists
648652
auto tcl = TClass::GetClass(tinfo);
@@ -695,6 +699,10 @@ void* CcdbApi::retrieveFromTFile(std::type_info const& tinfo, std::string const&
695699
list = curl_slist_append(list, ("If-Not-After: " + createdNotAfter).c_str());
696700
}
697701

702+
if (!createdNotBefore.empty()) {
703+
list = curl_slist_append(list, ("If-Not-Before: " + createdNotBefore).c_str());
704+
}
705+
698706
// setup curl for headers handling
699707
if (headers != nullptr) {
700708
list = curl_slist_append(list, ("If-None-Match: " + to_string(timestamp)).c_str());

CCDB/test/testBasicCCDBManager.cxx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ BOOST_AUTO_TEST_CASE(TestBasicCCDBManager)
105105
BOOST_CHECK(!objA); // make sure correct object is not loaded
106106
cdb.resetCreatedNotAfter(); // resetting upper validity limit
107107

108+
// get object in TimeMachine mode in the future
109+
cdb.setCreatedNotBefore(4108971600); // set upper object validity
110+
objA = cdb.get<std::string>(pathA); // should not be loaded
111+
BOOST_CHECK(!objA); // make sure correct object is not loaded
112+
cdb.resetCreatedNotBefore(); // resetting upper validity limit
113+
108114
// disable cache at all (will also clean it)
109115
cdb.setCachingEnabled(false);
110116
objA = cdb.get<std::string>(pathA); // will be loaded from scratch, w/o filling the cache

0 commit comments

Comments
 (0)