165 std::vector<CCDBFetcherHelper::FetchOp>
const& ops,
168 DataAllocator& allocator) -> std::vector<CCDBFetcherHelper::Response>
175 O2_SIGNPOST_START(ccdb, sid,
"populateCacheWith",
"Starting to populate cache with CCDB objects");
176 std::vector<Response> responses;
177 for (
auto const&
op : ops) {
178 int64_t timestampToUse =
op.timestamp;
182 auto&&
v = allocator.makeVector<
char>(
output);
183 std::map<std::string, std::string> metadata;
184 std::map<std::string, std::string> headers;
185 std::string
path =
op.url;
186 std::string
etag =
"";
187 int chRate = helper->queryPeriodGlo;
188 bool checkValidity =
false;
189 if (
op.runDependent > 0) {
190 if (
op.runDependent == 1) {
191 metadata[
"runNumber"] = std::format(
"{}",
op.runNumber);
192 }
else if (
op.runDependent == 2) {
193 timestampToUse =
op.runNumber;
195 LOGP(fatal,
"Undefined ccdb-run-dependent option {} for spec {}/{}/{}",
op.runDependent,
196 concrete.origin.as<std::string>(), concrete.description.as<std::string>(),
int(concrete.subSpec));
199 for (
auto const&
m :
op.metadata) {
200 O2_SIGNPOST_EVENT_EMIT(ccdb, sid,
"populateCacheWith",
"Adding metadata %{public}s: %{public}s to the request",
m.key.data(),
m.value.data());
201 metadata[
m.key] =
m.value;
203 if (
op.queryRate != 0) {
204 chRate =
op.queryRate * helper->queryPeriodFactor;
207 const auto url2uuid = helper->mapURL2UUID.find(
path);
208 if (url2uuid != helper->mapURL2UUID.end()) {
209 etag = url2uuid->second.etag;
211 uint64_t validUntil = url2uuid->second.cacheValidUntil;
216 bool cacheExpired = (validUntil <= (uint64_t)timestampToUse) || ((uint64_t)
op.timestamp <
cachePopulatedAt);
217 if (isOnline || cacheExpired) {
218 if (!helper->useTFSlice) {
219 checkValidity = chRate > 0 ? (std::abs(
int(timingInfo.tfCounter - url2uuid->second.lastCheckedTF)) >= chRate) : (timingInfo.tfCounter % -chRate) == 0;
221 checkValidity = chRate > 0 ? (std::abs(
int(timingInfo.timeslice - url2uuid->second.lastCheckedSlice)) >= chRate) : (timingInfo.timeslice % -chRate) == 0;
222 if (!checkValidity && helper->useTFSlice > std::abs(chRate)) {
223 checkValidity = std::abs(
int(timingInfo.tfCounter) - url2uuid->second.lastCheckedTF) > helper->useTFSlice;
228 checkValidity =
true;
231 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());
233 const auto& api = helper->getAPI(
path);
234 if (checkValidity && (!api.isSnapshotMode() ||
etag.empty())) {
235 LOGP(detail,
"Loading {} for timestamp {}",
path, timestampToUse);
236 api.loadFileToMemory(
v,
path, metadata, timestampToUse, &headers,
etag, helper->createdNotAfter, helper->createdNotBefore);
237 if ((headers.count(
"Error") != 0) || (
etag.empty() &&
v.empty())) {
238 LOGP(fatal,
"Unable to find CCDB object {}/{}",
path, timestampToUse);
243 if (headers.find(
"default") != headers.end()) {
244 LOGP(detail,
"******** Default entry used for {} ********",
path);
246 helper->mapURL2UUID[
path].lastCheckedTF = timingInfo.tfCounter;
247 helper->mapURL2UUID[
path].lastCheckedSlice = timingInfo.timeslice;
249 helper->mapURL2UUID[
path].etag = headers[
"ETag"];
250 helper->mapURL2UUID[
path].cachePopulatedAt = timestampToUse;
251 helper->mapURL2UUID[
path].cacheMiss++;
252 helper->mapURL2UUID[
path].size =
v.size();
253 helper->mapURL2UUID[
path].minSize = std::min(
v.size(), helper->mapURL2UUID[
path].minSize);
254 helper->mapURL2UUID[
path].maxSize = std::max(
v.size(), helper->mapURL2UUID[
path].maxSize);
255 auto size =
v.size();
256 helper->totalFetchedBytes +=
size;
257 helper->totalRequestedBytes +=
size;
258 api.appendFlatHeader(
v, headers);
260 helper->mapURL2DPLCache[
path] = cacheId;
261 responses.emplace_back(
Response{.
id = cacheId, .size =
size, .request =
nullptr});
262 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);
266 helper->mapURL2UUID[
path].etag = headers[
"ETag"];
267 helper->mapURL2UUID[
path].cachePopulatedAt = timestampToUse;
268 helper->mapURL2UUID[
path].cacheValidUntil = headers[
"Cache-Valid-Until"].empty() ? 0 : std::stoul(headers[
"Cache-Valid-Until"]);
269 helper->mapURL2UUID[
path].cacheMiss++;
270 helper->mapURL2UUID[
path].size =
v.size();
271 helper->mapURL2UUID[
path].minSize = std::min(
v.size(), helper->mapURL2UUID[
path].minSize);
272 helper->mapURL2UUID[
path].maxSize = std::max(
v.size(), helper->mapURL2UUID[
path].maxSize);
273 auto size =
v.size();
274 helper->totalFetchedBytes +=
size;
275 helper->totalRequestedBytes +=
size;
276 api.appendFlatHeader(
v, headers);
278 helper->mapURL2DPLCache[
path] = cacheId;
279 responses.emplace_back(
Response{.
id = cacheId, .size =
size, .request =
nullptr});
280 O2_SIGNPOST_EVENT_EMIT(ccdb, sid,
"populateCacheWith",
"Caching %{public}s for %{public}s (DPL id %" PRIu64
")",
path.data(), headers[
"ETag"].data(), cacheId.value);
284 helper->mapURL2UUID[
path].cacheValidUntil = headers[
"Cache-Valid-Until"].empty() ? 0 : std::stoul(headers[
"Cache-Valid-Until"]);
288 auto cacheId = helper->mapURL2DPLCache[
path];
289 O2_SIGNPOST_EVENT_EMIT(ccdb, sid,
"populateCacheWith",
"Reusing %{public}s for %{public}s (DPL id %" PRIu64
")",
path.data(), headers[
"ETag"].data(), cacheId.value);
290 helper->mapURL2UUID[
path].cacheHit++;
291 responses.emplace_back(
Response{.
id = cacheId, .size = helper->mapURL2UUID[
path].size, .request =
nullptr});
295 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.