andyzzl opened a new issue #7037:
URL: https://github.com/apache/skywalking/issues/7037
Please answer these questions before submitting your issue.
- Why do you submit this issue?
- [x] Question or discussion
- [ ] Bug
- [ ] Requirement
- [ ] Feature or performance improvement
___
### Question
- What do you want to know?
Hi, I have a question about the code of `MetricsPersistentWorker`.
```java
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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]