165 std::vector<CCDBFetcherHelper::FetchOp>
const& ops,
168 DataAllocator& allocator) -> std::vector<CCDBFetcherHelper::Response>
176 O2_SIGNPOST_START(ccdb, sid,
"populateCacheWith",
"Starting to populate cache with CCDB objects");
177 std::vector<Response> responses;
178 for (
auto&
op : ops) {
179 int64_t timestampToUse =
op.timestamp;
184 auto&&
v = allocator.makeVector<
char>(
output);
185 std::map<std::string, std::string> metadata;
186 std::map<std::string, std::string> headers;
187 std::string
path =
op.url;
188 std::string
etag =
"";
189 int chRate = helper->queryPeriodGlo;
190 bool checkValidity =
false;
191 if (
op.runDependent > 0) {
192 if (
op.runDependent == 1) {
193 metadata[
"runNumber"] = std::format(
"{}",
op.runNumber);
194 }
else if (
op.runDependent == 2) {
195 timestampToUse =
op.runNumber;
197 LOGP(fatal,
"Undefined ccdb-run-dependent option {} for spec {}/{}/{}",
op.runDependent,
198 concrete.origin.as<std::string>(), concrete.description.as<std::string>(),
int(concrete.subSpec));
201 for (
auto m :
op.metadata) {
202 O2_SIGNPOST_EVENT_EMIT(ccdb, sid,
"populateCacheWith",
"Adding metadata %{public}s: %{public}s to the request",
m.key.data(),
m.value.data());
203 metadata[
m.key] =
m.value;
205 if (
op.queryRate != 0) {
206 chRate =
op.queryRate * helper->queryPeriodFactor;
209 const auto url2uuid = helper->mapURL2UUID.find(
path);
210 if (url2uuid != helper->mapURL2UUID.end()) {
211 etag = url2uuid->second.etag;
213 uint64_t validUntil = url2uuid->second.cacheValidUntil;
218 bool cacheExpired = (validUntil <= timestampToUse) || (
op.timestamp <
cachePopulatedAt);
219 if (isOnline || cacheExpired) {
220 if (!helper->useTFSlice) {
221 checkValidity = chRate > 0 ? (std::abs(
int(timingInfo.tfCounter - url2uuid->second.lastCheckedTF)) >= chRate) : (timingInfo.tfCounter % -chRate) == 0;
223 checkValidity = chRate > 0 ? (std::abs(
int(timingInfo.timeslice - url2uuid->second.lastCheckedSlice)) >= chRate) : (timingInfo.timeslice % -chRate) == 0;
224 if (!checkValidity && helper->useTFSlice > std::abs(chRate)) {
225 checkValidity = std::abs(
int(timingInfo.tfCounter) - url2uuid->second.lastCheckedTF) > helper->useTFSlice;
230 checkValidity =
true;
233 O2_SIGNPOST_EVENT_EMIT(ccdb, sid,
"populateCacheWith",
"checkValidity is %{public}s for tf%{public}s %zu of %{public}s", checkValidity ?
"true" :
"false", helper->useTFSlice ?
"ID" :
"Slice", helper->useTFSlice ? timingInfo.timeslice : timingInfo.tfCounter,
path.data());
235 const auto& api = helper->getAPI(
path);
236 if (checkValidity && (!api.isSnapshotMode() ||
etag.empty())) {
237 LOGP(detail,
"Loading {} for timestamp {}",
path, timestampToUse);
238 api.loadFileToMemory(
v,
path, metadata, timestampToUse, &headers,
etag, helper->createdNotAfter, helper->createdNotBefore);
239 if ((headers.count(
"Error") != 0) || (
etag.empty() &&
v.empty())) {
240 LOGP(fatal,
"Unable to find CCDB object {}/{}",
path, timestampToUse);
245 if (headers.find(
"default") != headers.end()) {
246 LOGP(detail,
"******** Default entry used for {} ********",
path);
248 helper->mapURL2UUID[
path].lastCheckedTF = timingInfo.tfCounter;
249 helper->mapURL2UUID[
path].lastCheckedSlice = timingInfo.timeslice;
251 helper->mapURL2UUID[
path].etag = headers[
"ETag"];
252 helper->mapURL2UUID[
path].cachePopulatedAt = timestampToUse;
253 helper->mapURL2UUID[
path].cacheMiss++;
254 helper->mapURL2UUID[
path].size =
v.size();
255 helper->mapURL2UUID[
path].minSize = std::min(
v.size(), helper->mapURL2UUID[
path].minSize);
256 helper->mapURL2UUID[
path].maxSize = std::max(
v.size(), helper->mapURL2UUID[
path].maxSize);
257 auto size =
v.size();
258 helper->totalFetchedBytes +=
size;
259 helper->totalRequestedBytes +=
size;
260 api.appendFlatHeader(
v, headers);
262 helper->mapURL2DPLCache[
path] = cacheId;
263 responses.emplace_back(
Response{.
id = cacheId, .size =
size, .request =
nullptr});
264 O2_SIGNPOST_EVENT_EMIT(ccdb, sid,
"populateCacheWith",
"Caching %{public}s for %{public}s (DPL id %" PRIu64
", size %zu)",
path.data(), headers[
"ETag"].data(), cacheId.value,
size);
268 helper->mapURL2UUID[
path].etag = headers[
"ETag"];
269 helper->mapURL2UUID[
path].cachePopulatedAt = timestampToUse;
270 helper->mapURL2UUID[
path].cacheValidUntil = headers[
"Cache-Valid-Until"].empty() ? 0 : std::stoul(headers[
"Cache-Valid-Until"]);
271 helper->mapURL2UUID[
path].cacheMiss++;
272 helper->mapURL2UUID[
path].size =
v.size();
273 helper->mapURL2UUID[
path].minSize = std::min(
v.size(), helper->mapURL2UUID[
path].minSize);
274 helper->mapURL2UUID[
path].maxSize = std::max(
v.size(), helper->mapURL2UUID[
path].maxSize);
275 auto size =
v.size();
276 helper->totalFetchedBytes +=
size;
277 helper->totalRequestedBytes +=
size;
278 api.appendFlatHeader(
v, headers);
280 helper->mapURL2DPLCache[
path] = cacheId;
281 responses.emplace_back(
Response{.
id = cacheId, .size =
size, .request =
nullptr});
282 O2_SIGNPOST_EVENT_EMIT(ccdb, sid,
"populateCacheWith",
"Caching %{public}s for %{public}s (DPL id %" PRIu64
")",
path.data(), headers[
"ETag"].data(), cacheId.value);
286 helper->mapURL2UUID[
path].cacheValidUntil = headers[
"Cache-Valid-Until"].empty() ? 0 : std::stoul(headers[
"Cache-Valid-Until"]);
290 auto cacheId = helper->mapURL2DPLCache[
path];
291 O2_SIGNPOST_EVENT_EMIT(ccdb, sid,
"populateCacheWith",
"Reusing %{public}s for %{public}s (DPL id %" PRIu64
")",
path.data(), headers[
"ETag"].data(), cacheId.value);
292 helper->mapURL2UUID[
path].cacheHit++;
293 responses.emplace_back(
Response{.
id = cacheId, .size = helper->mapURL2UUID[
path].size, .request =
nullptr});
297 O2_SIGNPOST_END(ccdb, sid,
"populateCacheWith",
"Finished populating cache with CCDB objects");
#define O2_DECLARE_DYNAMIC_LOG(name)
#define O2_SIGNPOST_END(log, id, name, format,...)
#define O2_SIGNPOST_EVENT_EMIT(log, id, name, format,...)
#define O2_SIGNPOST_START(log, id, name, format,...)
DeploymentMode deploymentMode
Where we thing this is running.