Skip to content

Commit 9fa4c3d

Browse files
committed
DPL CCDB: avoid duplicated code
1 parent 00279c7 commit 9fa4c3d

File tree

1 file changed

+15
-32
lines changed

1 file changed

+15
-32
lines changed

Framework/CCDBSupport/src/CCDBHelpers.cxx

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -308,19 +308,7 @@ auto populateCacheWith(std::shared_ptr<CCDBFetcherHelper> const& helper,
308308
LOGP(detail, "******** Default entry used for {} ********", path);
309309
}
310310
helper->mapURL2UUID[path].lastCheckedTF = timingInfo.tfCounter;
311-
if (etag.empty()) {
312-
helper->mapURL2UUID[path].etag = headers["ETag"]; // update uuid
313-
helper->mapURL2UUID[path].cachePopulatedAt = timestampToUse;
314-
helper->mapURL2UUID[path].cacheMiss++;
315-
helper->mapURL2UUID[path].minSize = std::min(v.size(), helper->mapURL2UUID[path].minSize);
316-
helper->mapURL2UUID[path].maxSize = std::max(v.size(), helper->mapURL2UUID[path].maxSize);
317-
api.appendFlatHeader(v, headers);
318-
auto cacheId = allocator.adoptContainer(output, std::move(v), DataAllocator::CacheStrategy::Always, header::gSerializationMethodCCDB);
319-
helper->mapURL2DPLCache[path] = cacheId;
320-
O2_SIGNPOST_EVENT_EMIT(ccdb, sid, "populateCacheWith", "Caching %{public}s for %{public}s (DPL id %" PRIu64 ")", path.data(), headers["ETag"].data(), cacheId.value);
321-
continue;
322-
}
323-
if (v.size()) { // but should be overridden by fresh object
311+
if (etag.empty() || v.size()) { // but should be overridden by fresh object
324312
// somewhere here pruneFromCache should be called
325313
helper->mapURL2UUID[path].etag = headers["ETag"]; // update uuid
326314
helper->mapURL2UUID[path].cachePopulatedAt = timestampToUse;
@@ -330,15 +318,16 @@ auto populateCacheWith(std::shared_ptr<CCDBFetcherHelper> const& helper,
330318
helper->mapURL2UUID[path].maxSize = std::max(v.size(), helper->mapURL2UUID[path].maxSize);
331319
api.appendFlatHeader(v, headers);
332320
auto cacheId = allocator.adoptContainer(output, std::move(v), DataAllocator::CacheStrategy::Always, header::gSerializationMethodCCDB);
321+
if (v.size()) {
322+
// one could modify the adoptContainer to take optional old cacheID to clean:
323+
// mapURL2DPLCache[URL] = ctx.outputs().adoptContainer(output, std::move(outputBuffer), DataAllocator::CacheStrategy::Always, mapURL2DPLCache[URL]);
324+
}
333325
helper->mapURL2DPLCache[path] = cacheId;
334326
O2_SIGNPOST_EVENT_EMIT(ccdb, sid, "populateCacheWith", "Caching %{public}s for %{public}s (DPL id %" PRIu64 ")", path.data(), headers["ETag"].data(), cacheId.value);
335-
// one could modify the adoptContainer to take optional old cacheID to clean:
336-
// mapURL2DPLCache[URL] = ctx.outputs().adoptContainer(output, std::move(outputBuffer), DataAllocator::CacheStrategy::Always, mapURL2DPLCache[URL]);
337327
continue;
338-
} else {
339-
// Only once the etag is actually used, we get the information on how long the object is valid
340-
helper->mapURL2UUID[path].cacheValidUntil = headers["Cache-Valid-Until"].empty() ? 0 : std::stoul(headers["Cache-Valid-Until"]);
341328
}
329+
// Only once the etag is actually used, we get the information on how long the object is valid
330+
helper->mapURL2UUID[path].cacheValidUntil = headers["Cache-Valid-Until"].empty() ? 0 : std::stoul(headers["Cache-Valid-Until"]);
342331
}
343332
// cached object is fine
344333
auto cacheId = helper->mapURL2DPLCache[path];
@@ -401,18 +390,9 @@ AlgorithmSpec CCDBHelpers::fetchFromCCDB()
401390
// FIXME: I should send a dummy message.
402391
return;
403392
}
404-
if (etag.empty()) {
405-
helper->mapURL2UUID[path].etag = headers["ETag"]; // update uuid
406-
helper->mapURL2UUID[path].cacheMiss++;
407-
helper->mapURL2UUID[path].minSize = std::min(v.size(), helper->mapURL2UUID[path].minSize);
408-
helper->mapURL2UUID[path].maxSize = std::max(v.size(), helper->mapURL2UUID[path].maxSize);
409-
newOrbitResetTime = getOrbitResetTime(v);
410-
api.appendFlatHeader(v, headers);
411-
auto cacheId = allocator.adoptContainer(output, std::move(v), DataAllocator::CacheStrategy::Always, header::gSerializationMethodNone);
412-
helper->mapURL2DPLCache[path] = cacheId;
413-
O2_SIGNPOST_EVENT_EMIT(ccdb, sid, "fetchFromCCDB", "Caching %{public}s for %{public}s (DPL id %" PRIu64 ")", path.data(), headers["ETag"].data(), cacheId.value);
414-
} else if (v.size()) { // but should be overridden by fresh object
415-
// somewhere here pruneFromCache should be called
393+
394+
if (etag.empty() || v.size()) {
395+
// Overwrite on cache miss
416396
helper->mapURL2UUID[path].etag = headers["ETag"]; // update uuid
417397
helper->mapURL2UUID[path].cacheMiss++;
418398
helper->mapURL2UUID[path].minSize = std::min(v.size(), helper->mapURL2UUID[path].minSize);
@@ -421,9 +401,12 @@ AlgorithmSpec CCDBHelpers::fetchFromCCDB()
421401
api.appendFlatHeader(v, headers);
422402
auto cacheId = allocator.adoptContainer(output, std::move(v), DataAllocator::CacheStrategy::Always, header::gSerializationMethodNone);
423403
helper->mapURL2DPLCache[path] = cacheId;
404+
if (v.size()) { // but should be overridden by fresh object
405+
// somewhere here pruneFromCache should be called
406+
// one could modify the adoptContainer to take optional old cacheID to clean:
407+
// mapURL2DPLCache[URL] = ctx.outputs().adoptContainer(output, std::move(outputBuffer), DataAllocator::CacheStrategy::Always, mapURL2DPLCache[URL]);
408+
}
424409
O2_SIGNPOST_EVENT_EMIT(ccdb, sid, "fetchFromCCDB", "Caching %{public}s for %{public}s (DPL id %" PRIu64 ")", path.data(), headers["ETag"].data(), cacheId.value);
425-
// one could modify the adoptContainer to take optional old cacheID to clean:
426-
// mapURL2DPLCache[URL] = ctx.outputs().adoptContainer(output, std::move(outputBuffer), DataAllocator::CacheStrategy::Always, mapURL2DPLCache[URL]);
427410
}
428411
// cached object is fine
429412
}

0 commit comments

Comments
 (0)