Please answer these questions before submitting your issue.
Question
- What do you want to know?
Hi, I have a question about the code of MetricsPersistentWorker.
private void flushDataToStorage(List<Metrics> metricsList,
List<PrepareRequest> prepareRequests) {
try {
loadFromStorage(metricsList);
for (Metrics metrics : metricsList) {
Metrics cachedMetrics = context.get(metrics);
if (cachedMetrics != null) {
/*
* If the metrics is not supportUpdate, defined through MetricsExtension#supportUpdate,
* then no merge and further process happens.
*/
if (!supportUpdate) {
continue;
}
/*
* Merge metrics into cachedMetrics, change only happens inside cachedMetrics.
*/
final boolean isAbandoned = !cachedMetrics.combine(metrics);
if (isAbandoned) {
continue;
}
cachedMetrics.calculate();
prepareRequests.add(metricsDAO.prepareBatchUpdate(model, cachedMetrics));
nextWorker(cachedMetrics);
} else {
metrics.calculate();
prepareRequests.add(metricsDAO.prepareBatchInsert(model, metrics));
nextWorker(metrics);
}
/*
* The `metrics` should be not changed in all above process. Exporter is an async process.
*/
nextExportWorker.ifPresent(exportEvenWorker -> exportEvenWorker.in(
new ExportEvent(metrics, ExportEvent.EventType.INCREMENT)));
}
} catch (Throwable t) {
log.error(t.getMessage(), t);
} finally {
metricsList.clear();
}
}
In the function flushDataToStorage, a metrics object which not stored in context is considered as a new metrics, otherwise, it needs to be combined with the old metrics in context. After prepareRequests of a new metrics generated, we don't put this new metrics into context. So in the next run of PersistenceTimer, when a metrics with same id comes, we have to query db again. Is there some problems cause that we can't put a new metrics object into context?
Thanks.
Please answer these questions before submitting your issue.
Question
Hi, I have a question about the code of
MetricsPersistentWorker.In the function
flushDataToStorage, a metrics object which not stored incontextis considered as a new metrics, otherwise, it needs to be combined with the old metrics incontext. AfterprepareRequestsof a new metrics generated, we don't put this new metrics intocontext. So in the next run ofPersistenceTimer, when a metrics with same id comes, we have to query db again. Is there some problems cause that we can't put a new metrics object into context?Thanks.