use of io.datarouter.batchsizeoptimizer.storage.performancerecord.OpPerformanceRecordKey in project datarouter by hotpads.
the class OpPerformanceRecordAggregationJob method run.
@Override
public void run(TaskTracker tracker) {
String currentOpName = null;
List<OpPerformanceRecordKey> recordsToDelete = new ArrayList<>(BATCH_SIZE);
Map<Integer, AggregatedRecord> aggregatedRecordsByBatchSize = new HashMap<>();
for (OpPerformanceRecord record : opPerformanceRecordDao.scan().iterable()) {
if (currentOpName != null && !currentOpName.equals(record.getKey().getOpName())) {
saveAggregatedRecord(aggregatedRecordsByBatchSize);
aggregatedRecordsByBatchSize.clear();
}
currentOpName = record.getKey().getOpName();
aggregatedRecordsByBatchSize.computeIfAbsent(record.getBatchSize(), $ -> new AggregatedRecord(record.getKey().getOpName(), record.getBatchSize())).addRecord(record);
recordsToDelete.add(record.getKey());
if (recordsToDelete.size() > BATCH_SIZE) {
opPerformanceRecordDao.deleteMulti(new ArrayList<>(recordsToDelete));
recordsToDelete.clear();
}
}
saveAggregatedRecord(aggregatedRecordsByBatchSize);
opPerformanceRecordDao.deleteMulti(recordsToDelete);
}
Aggregations