use of com.hedera.mirror.importer.exception.FileOperationException in project hedera-mirror-node by hashgraph.
the class ErrataMigration method missingTransactions.
// Adds the transactions and records that are missing due to the insufficient fee funding issue in services.
private void missingTransactions() throws IOException {
Set<Long> consensusTimestamps = new HashSet<>();
var resourceResolver = new PathMatchingResourcePatternResolver();
Resource[] resources = resourceResolver.getResources("classpath*:errata/mainnet/missingtransactions/*.bin");
recordStreamFileListener.onStart();
var dateRangeFilter = new DateRangeFilter(mirrorProperties.getStartDate(), mirrorProperties.getEndDate());
for (Resource resource : resources) {
String name = resource.getFilename();
log.info("Loading file: {}", name);
try (var in = new ValidatedDataInputStream(resource.getInputStream(), name)) {
byte[] recordBytes = in.readLengthAndBytes(1, MAX_TRANSACTION_LENGTH, false, "record");
byte[] transactionBytes = in.readLengthAndBytes(1, MAX_TRANSACTION_LENGTH, false, "transaction");
var transactionRecord = TransactionRecord.parseFrom(recordBytes);
var transaction = Transaction.parseFrom(transactionBytes);
var recordItem = new RecordItem(transaction, transactionRecord);
long timestamp = recordItem.getConsensusTimestamp();
if (transactionRepository.findById(timestamp).isEmpty() && dateRangeFilter.filter(timestamp)) {
entityRecordItemListener.onItem(recordItem);
consensusTimestamps.add(timestamp);
}
} catch (IOException e) {
recordStreamFileListener.onError();
throw new FileOperationException("Error parsing errata file " + name, e);
}
}
if (consensusTimestamps.isEmpty()) {
log.info("Previously inserted all missing transactions");
return;
}
recordStreamFileListener.onEnd(null);
var ids = new MapSqlParameterSource("ids", consensusTimestamps);
jdbcOperations.update("update crypto_transfer set errata = 'INSERT' where consensus_timestamp in (:ids)", ids);
jdbcOperations.update("update transaction set errata = 'INSERT' where consensus_timestamp in (:ids)", ids);
Long min = consensusTimestamps.stream().min(Long::compareTo).orElse(null);
Long max = consensusTimestamps.stream().max(Long::compareTo).orElse(null);
log.info("Inserted {} missing transactions between {} and {}", consensusTimestamps.size(), min, max);
}
Aggregations