Skip to content

Commit 5acfb86

Browse files
committed
Optionaly use TF slice instead of TFcounter for CCDB cache validation
1 parent f37a28b commit 5acfb86

File tree

4 files changed

+23
-11
lines changed

4 files changed

+23
-11
lines changed

Framework/CCDBSupport/src/CCDBFetcherHelper.cxx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,12 @@ void CCDBFetcherHelper::initialiseHelper(CCDBFetcherHelper& helper, ConfigParamR
5151
auto defHost = options.get<std::string>("condition-backend");
5252
auto checkRate = options.get<int>("condition-tf-per-query");
5353
auto checkMult = options.get<int>("condition-tf-per-query-multiplier");
54+
helper.useTFSlice = options.get<bool>("condition-use-slice-for-prescaling");
5455
helper.timeToleranceMS = options.get<int64_t>("condition-time-tolerance");
5556
helper.queryPeriodGlo = checkRate > 0 ? checkRate : std::numeric_limits<int>::max();
5657
helper.queryPeriodFactor = checkMult > 0 ? checkMult : 1;
58+
LOGP(info, "CCDB Backend at: {}, validity check for every {} TF{}{}", defHost, helper.queryPeriodGlo, helper.useTFSlice ? "(slice!)" : "",
59+
helper.queryPeriodFactor == 1 ? std::string{} : fmt::format(", (query for high-rate objects downscaled by {})", helper.queryPeriodFactor));
5760
LOGP(info, "CCDB Backend at: {}, validity check for every {} TF{}", defHost, helper.queryPeriodGlo, helper.queryPeriodFactor == 1 ? std::string{} : fmt::format(", (query for high-rate objects downscaled by {})", helper.queryPeriodFactor));
5861
LOGP(info, "Hook to enable signposts for CCDB messages at {}", (void*)&private_o2_log_ccdb->stacktrace);
5962
auto remapString = options.get<std::string>("condition-remap");
@@ -196,6 +199,7 @@ auto CCDBFetcherHelper::populateCacheWith(std::shared_ptr<CCDBFetcherHelper> con
196199
}
197200

198201
const auto url2uuid = helper->mapURL2UUID.find(path);
202+
uint32_t counter = helper->useTFSlice ? timingInfo.slice : timingInfo.tfCounter;
199203
if (url2uuid != helper->mapURL2UUID.end()) {
200204
etag = url2uuid->second.etag;
201205
// We check validity every chRate timeslices or if the cache is expired
@@ -205,12 +209,12 @@ auto CCDBFetcherHelper::populateCacheWith(std::shared_ptr<CCDBFetcherHelper> con
205209
// If timestamp is before the time the element was cached or after the claimed validity, we need to check validity, again
206210
// when online.
207211
bool cacheExpired = (validUntil <= timestampToUse) || (op.timestamp < cachePopulatedAt);
208-
checkValidity = (std::abs(int(timingInfo.tfCounter - url2uuid->second.lastCheckedTF)) >= chRate) && (isOnline || cacheExpired);
212+
checkValidity = (std::abs(int(counter - url2uuid->second.lastCheckedTF)) >= chRate) && (isOnline || cacheExpired);
209213
} else {
210214
checkValidity = true; // never skip check if the cache is empty
211215
}
212216

213-
O2_SIGNPOST_EVENT_EMIT(ccdb, sid, "populateCacheWith", "checkValidity is %{public}s for tfID %d of %{public}s", checkValidity ? "true" : "false", timingInfo.tfCounter, path.data());
217+
O2_SIGNPOST_EVENT_EMIT(ccdb, sid, "populateCacheWith", "checkValidity is %{public}s for tf%{public}s %d of %{public}s", checkValidity ? "true" : "false", helper->useTFSlice ? "ID" : "Slice", counter, path.data());
214218

215219
const auto& api = helper->getAPI(path);
216220
if (checkValidity && (!api.isSnapshotMode() || etag.empty())) { // in the snapshot mode the object needs to be fetched only once
@@ -225,7 +229,7 @@ auto CCDBFetcherHelper::populateCacheWith(std::shared_ptr<CCDBFetcherHelper> con
225229
if (headers.find("default") != headers.end()) {
226230
LOGP(detail, "******** Default entry used for {} ********", path);
227231
}
228-
helper->mapURL2UUID[path].lastCheckedTF = timingInfo.tfCounter;
232+
helper->mapURL2UUID[path].lastCheckedTF = counter;
229233
if (etag.empty()) {
230234
helper->mapURL2UUID[path].etag = headers["ETag"]; // update uuid
231235
helper->mapURL2UUID[path].cachePopulatedAt = timestampToUse;

Framework/CCDBSupport/src/CCDBFetcherHelper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ struct CCDBFetcherHelper {
9494
int queryPeriodGlo = 1;
9595
int queryPeriodFactor = 1;
9696
int64_t timeToleranceMS = 5000;
97+
bool useTFSlice = false;
9798

9899
o2::ccdb::CcdbApi& getAPI(const std::string& path);
99100
static void initialiseHelper(CCDBFetcherHelper& helper, ConfigParamRegistry const& options);

Framework/CCDBSupport/src/CCDBHelpers.cxx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ struct CCDBFetcherHelper {
6060
int queryPeriodGlo = 1;
6161
int queryPeriodFactor = 1;
6262
int64_t timeToleranceMS = 5000;
63+
bool useTFSlice = false;
6364

6465
o2::ccdb::CcdbApi& getAPI(const std::string& path)
6566
{
@@ -165,10 +166,12 @@ void initialiseHelper(CCDBFetcherHelper& helper, ConfigParamRegistry const& opti
165166
auto defHost = options.get<std::string>("condition-backend");
166167
auto checkRate = options.get<int>("condition-tf-per-query");
167168
auto checkMult = options.get<int>("condition-tf-per-query-multiplier");
169+
helper.useTFSlice = options.get<bool>("condition-use-slice-for-prescaling");
168170
helper.timeToleranceMS = options.get<int64_t>("condition-time-tolerance");
169171
helper.queryPeriodGlo = checkRate > 0 ? checkRate : std::numeric_limits<int>::max();
170172
helper.queryPeriodFactor = checkMult > 0 ? checkMult : 1;
171-
LOGP(info, "CCDB Backend at: {}, validity check for every {} TF{}", defHost, helper.queryPeriodGlo, helper.queryPeriodFactor == 1 ? std::string{} : fmt::format(", (query for high-rate objects downscaled by {})", helper.queryPeriodFactor));
173+
LOGP(info, "CCDB Backend at: {}, validity check for every {} TF{}{}", defHost, helper.queryPeriodGlo, helper.useTFSlice ? "(slice!)" : "",
174+
helper.queryPeriodFactor == 1 ? std::string{} : fmt::format(", (query for high-rate objects downscaled by {})", helper.queryPeriodFactor));
172175
LOGP(info, "Hook to enable signposts for CCDB messages at {}", (void*)&private_o2_log_ccdb->stacktrace);
173176
auto remapString = options.get<std::string>("condition-remap");
174177
CCDBHelpers::ParserResult result = CCDBHelpers::parseRemappings(remapString.c_str());
@@ -280,6 +283,7 @@ auto populateCacheWith(std::shared_ptr<CCDBFetcherHelper> const& helper,
280283
}
281284
}
282285
const auto url2uuid = helper->mapURL2UUID.find(path);
286+
uint32_t counter = helper->useTFSlice ? timingInfo.slice : timingInfo.tfCounter;
283287
if (url2uuid != helper->mapURL2UUID.end()) {
284288
etag = url2uuid->second.etag;
285289
// We check validity every chRate timeslices or if the cache is expired
@@ -289,12 +293,12 @@ auto populateCacheWith(std::shared_ptr<CCDBFetcherHelper> const& helper,
289293
// If timestamp is before the time the element was cached or after the claimed validity, we need to check validity, again
290294
// when online.
291295
bool cacheExpired = (validUntil <= timestampToUse) || (timestamp < cachePopulatedAt);
292-
checkValidity = (std::abs(int(timingInfo.tfCounter - url2uuid->second.lastCheckedTF)) >= chRate) && (isOnline || cacheExpired);
296+
checkValidity = (std::abs(int(counter - url2uuid->second.lastCheckedTF)) >= chRate) && (isOnline || cacheExpired);
293297
} else {
294298
checkValidity = true; // never skip check if the cache is empty
295299
}
296300

297-
O2_SIGNPOST_EVENT_EMIT(ccdb, sid, "populateCacheWith", "checkValidity is %{public}s for tfID %d of %{public}s", checkValidity ? "true" : "false", timingInfo.tfCounter, path.data());
301+
O2_SIGNPOST_EVENT_EMIT(ccdb, sid, "populateCacheWith", "checkValidity is %{public}s for tf%{public}s %d of %{public}s", checkValidity ? "true" : "false", helper->useTFSlice ? "ID" : "Slice", counter, path.data());
298302

299303
const auto& api = helper->getAPI(path);
300304
if (checkValidity && (!api.isSnapshotMode() || etag.empty())) { // in the snapshot mode the object needs to be fetched only once
@@ -309,7 +313,7 @@ auto populateCacheWith(std::shared_ptr<CCDBFetcherHelper> const& helper,
309313
if (headers.find("default") != headers.end()) {
310314
LOGP(detail, "******** Default entry used for {} ********", path);
311315
}
312-
helper->mapURL2UUID[path].lastCheckedTF = timingInfo.tfCounter;
316+
helper->mapURL2UUID[path].lastCheckedTF = counter;
313317
if (etag.empty()) {
314318
helper->mapURL2UUID[path].etag = headers["ETag"]; // update uuid
315319
helper->mapURL2UUID[path].cachePopulatedAt = timestampToUse;
@@ -382,21 +386,22 @@ AlgorithmSpec CCDBHelpers::fetchFromCCDB()
382386
std::map<std::string, std::string> metadata;
383387
std::map<std::string, std::string> headers;
384388
std::string etag;
385-
bool checkValidity = std::abs(int(timingInfo.tfCounter - helper->lastCheckedTFCounterOrbReset)) >= helper->queryPeriodGlo;
389+
uint32_t counter = helper->useTFSlice ? timingInfo.slice : timingInfo.tfCounter;
390+
bool checkValidity = std::abs(int(counter - helper->lastCheckedTFCounterOrbReset)) >= helper->queryPeriodGlo;
386391
const auto url2uuid = helper->mapURL2UUID.find(path);
387392
if (url2uuid != helper->mapURL2UUID.end()) {
388393
etag = url2uuid->second.etag;
389394
} else {
390395
checkValidity = true; // never skip check if the cache is empty
391396
}
392-
O2_SIGNPOST_EVENT_EMIT(ccdb, sid, "fetchFromCCDB", "checkValidity is %{public}s for tfID %d of %{public}s",
393-
checkValidity ? "true" : "false", timingInfo.tfCounter, path.data());
397+
O2_SIGNPOST_EVENT_EMIT(ccdb, sid, "fetchFromCCDB", "checkValidity is %{public}s for tf%{public}s %d of %{public}s",
398+
checkValidity ? "true" : "false", helper->useTFSlice ? "ID" : "Slice", counter, path.data());
394399
Output output{"CTP", "OrbitReset", 0};
395400
Long64_t newOrbitResetTime = orbitResetTime;
396401
auto&& v = allocator.makeVector<char>(output);
397402
const auto& api = helper->getAPI(path);
398403
if (checkValidity && (!api.isSnapshotMode() || etag.empty())) { // in the snapshot mode the object needs to be fetched only once
399-
helper->lastCheckedTFCounterOrbReset = timingInfo.tfCounter;
404+
helper->lastCheckedTFCounterOrbReset = counter;
400405
api.loadFileToMemory(v, path, metadata, timingInfo.creation, &headers, etag, helper->createdNotAfter, helper->createdNotBefore);
401406
if ((headers.count("Error") != 0) || (etag.empty() && v.empty())) {
402407
LOGP(fatal, "Unable to find CCDB object {}/{}", path, timingInfo.creation);

Framework/Core/src/WorkflowHelpers.cxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ void WorkflowHelpers::injectServiceDevices(WorkflowSpec& workflow, ConfigContext
178178
{"condition-remap", VariantType::String, "", {"remap condition path in CCDB based on the provided string."}},
179179
{"condition-tf-per-query", VariantType::Int, defaultConditionQueryRate(), {"check condition validity per requested number of TFs, fetch only once if <=0"}},
180180
{"condition-tf-per-query-multiplier", VariantType::Int, defaultConditionQueryRateMultiplier(), {"check conditions once per this amount of nominal checks"}},
181+
{"condition-use-slice-for-prescaling", VariantType::Bool, false, {"use TFslice instead of TFcounter to control validation frequency"}},
181182
{"condition-time-tolerance", VariantType::Int64, 5000ll, {"prefer creation time if its difference to orbit-derived time exceeds threshold (ms), impose if <0"}},
182183
{"orbit-offset-enumeration", VariantType::Int64, 0ll, {"initial value for the orbit"}},
183184
{"orbit-multiplier-enumeration", VariantType::Int64, 0ll, {"multiplier to get the orbit from the counter"}},
@@ -196,6 +197,7 @@ void WorkflowHelpers::injectServiceDevices(WorkflowSpec& workflow, ConfigContext
196197
{"condition-remap", VariantType::String, "", {"remap condition path in CCDB based on the provided string."}},
197198
{"condition-tf-per-query", VariantType::Int, defaultConditionQueryRate(), {"check condition validity per requested number of TFs, fetch only once if <=0"}},
198199
{"condition-tf-per-query-multiplier", VariantType::Int, defaultConditionQueryRateMultiplier(), {"check conditions once per this amount of nominal checks"}},
200+
{"condition-use-slice-for-prescaling", VariantType::Bool, false, {"use TFslice instead of TFcounter to control validation frequency"}},
199201
{"condition-time-tolerance", VariantType::Int64, 5000ll, {"prefer creation time if its difference to orbit-derived time exceeds threshold (ms), impose if <0"}},
200202
{"start-value-enumeration", VariantType::Int64, 0ll, {"initial value for the enumeration"}},
201203
{"end-value-enumeration", VariantType::Int64, -1ll, {"final value for the enumeration"}},

0 commit comments

Comments
 (0)