private void prepareFlushDataToStorage(List<Metrics> metricsList,
                                           List<PrepareRequest> prepareRequests) {
        try {
            loadFromStorage(metricsList);

            long timestamp = System.currentTimeMillis();
            for (Metrics metrics : metricsList) {
                Metrics cachedMetrics = sessionCache.get(metrics);
                if (cachedMetrics != null) {
                    cachedMetrics.setLastUpdateTimestamp(timestamp);
                    /*
                     * 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,
                            new SessionCacheCallback(sessionCache, cachedMetrics)
                        ));
                    nextWorker(cachedMetrics);
                } else {
                    metrics.calculate();
                    prepareRequests.add(
                        metricsDAO.prepareBatchInsert(
                            model,
                            metrics,
                            new SessionCacheCallback(sessionCache, metrics)
                        ));
                    nextWorker(metrics);
                    metrics.setLastUpdateTimestamp(timestamp);
                }

                /*
                 * 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();
        }
    }
Build given prepareRequests to prepare database flush

@param metricsList     the metrics in the last read from the in-memory aggregated cache.
@param prepareRequests the results for final execution.
oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/worker/MetricsPersistentWorker.java