Skip to content

Commit fcd565d

Browse files
committed
DPL CCDB: handle the Cache-Valid-Until header
This will not recheck the etag and consider the cache valid until the timestamp in milliseconds in the Cache-Valid-Until is not passed by the data timestamp.
1 parent ff671de commit fcd565d

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

Framework/CCDBSupport/src/CCDBHelpers.cxx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ namespace o2::framework
3333
struct CCDBFetcherHelper {
3434
struct CCDBCacheInfo {
3535
std::string etag;
36+
size_t cacheValidUntil = 0;
37+
size_t cachePopulatedAt = 0;
3638
size_t cacheMiss = 0;
3739
size_t cacheHit = 0;
3840
size_t minSize = -1ULL;
@@ -176,6 +178,11 @@ auto getOrbitResetTime(o2::pmr::vector<char> const& v) -> Long64_t
176178
return (*ctp)[0];
177179
};
178180

181+
bool isOnlineRun(DataTakingContext const& dtc)
182+
{
183+
return dtc.deploymentMode == DeploymentMode::OnlineAUX || dtc.deploymentMode == DeploymentMode::OnlineDDS || dtc.deploymentMode == DeploymentMode::OnlineECS;
184+
}
185+
179186
auto populateCacheWith(std::shared_ptr<CCDBFetcherHelper> const& helper,
180187
int64_t timestamp,
181188
TimingInfo& timingInfo,
@@ -186,6 +193,8 @@ auto populateCacheWith(std::shared_ptr<CCDBFetcherHelper> const& helper,
186193
int objCnt = -1;
187194
// We use the timeslice, so that we hook into the same interval as the rest of the
188195
// callback.
196+
static bool isOnline = isOnlineRun(dtc);
197+
189198
auto sid = _o2_signpost_id_t{(int64_t)timingInfo.timeslice};
190199
O2_SIGNPOST_START(ccdb, sid, "populateCacheWith", "Starting to populate cache with CCDB objects");
191200
for (auto& route : helper->routes) {
@@ -217,7 +226,14 @@ auto populateCacheWith(std::shared_ptr<CCDBFetcherHelper> const& helper,
217226
const auto url2uuid = helper->mapURL2UUID.find(path);
218227
if (url2uuid != helper->mapURL2UUID.end()) {
219228
etag = url2uuid->second.etag;
220-
checkValidity = std::abs(int(timingInfo.tfCounter - url2uuid->second.lastCheckedTF)) >= chRate;
229+
// We check validity every chRate timeslices or if the cache is expired
230+
uint64_t validUntil = url2uuid->second.cacheValidUntil;
231+
// When the cache was populated. If the cache was populated after the timestamp, we need to check validity.
232+
uint64_t cachePopulatedAt = url2uuid->second.cachePopulatedAt;
233+
// If timestamp is before the time the element was cached or after the claimed validity, we need to check validity, again
234+
// when online.
235+
bool cacheExpired = (validUntil <= timestamp) && (timestamp <= cachePopulatedAt);
236+
checkValidity = (std::abs(int(timingInfo.tfCounter - url2uuid->second.lastCheckedTF)) >= chRate) && (isOnline || cacheExpired);
221237
} else {
222238
checkValidity = true; // never skip check if the cache is empty
223239
}
@@ -240,6 +256,7 @@ auto populateCacheWith(std::shared_ptr<CCDBFetcherHelper> const& helper,
240256
helper->mapURL2UUID[path].lastCheckedTF = timingInfo.tfCounter;
241257
if (etag.empty()) {
242258
helper->mapURL2UUID[path].etag = headers["ETag"]; // update uuid
259+
helper->mapURL2UUID[path].cachePopulatedAt = timestamp;
243260
helper->mapURL2UUID[path].cacheMiss++;
244261
helper->mapURL2UUID[path].minSize = std::min(v.size(), helper->mapURL2UUID[path].minSize);
245262
helper->mapURL2UUID[path].maxSize = std::max(v.size(), helper->mapURL2UUID[path].maxSize);
@@ -251,6 +268,7 @@ auto populateCacheWith(std::shared_ptr<CCDBFetcherHelper> const& helper,
251268
if (v.size()) { // but should be overridden by fresh object
252269
// somewhere here pruneFromCache should be called
253270
helper->mapURL2UUID[path].etag = headers["ETag"]; // update uuid
271+
helper->mapURL2UUID[path].cachePopulatedAt = timestamp;
254272
helper->mapURL2UUID[path].cacheMiss++;
255273
helper->mapURL2UUID[path].minSize = std::min(v.size(), helper->mapURL2UUID[path].minSize);
256274
helper->mapURL2UUID[path].maxSize = std::max(v.size(), helper->mapURL2UUID[path].maxSize);
@@ -260,6 +278,9 @@ auto populateCacheWith(std::shared_ptr<CCDBFetcherHelper> const& helper,
260278
// one could modify the adoptContainer to take optional old cacheID to clean:
261279
// mapURL2DPLCache[URL] = ctx.outputs().adoptContainer(output, std::move(outputBuffer), DataAllocator::CacheStrategy::Always, mapURL2DPLCache[URL]);
262280
continue;
281+
} else {
282+
// Only once the etag is actually used, we get the information on how long the object is valid
283+
helper->mapURL2UUID[path].cacheValidUntil = headers["Cache-Valid-Until"].empty() ? 0 : std::stoul(headers["Cache-Valid-Until"]);
263284
}
264285
}
265286
// cached object is fine

0 commit comments

Comments
 (0)