Search in sources :

Example 1 with DateRangeFilter

use of com.hedera.mirror.importer.config.MirrorDateRangePropertiesProcessor.DateRangeFilter in project hedera-mirror-node by hashgraph.

the class RecordFileParserTest method endDate.

@ParameterizedTest(name = "endDate with offset {0}ns")
@CsvSource({ "-1", "0", "1" })
void endDate(long offset) {
    // given
    RecordFile recordFile = (RecordFile) getStreamFile();
    RecordItem firstItem = recordFile.getItems().blockFirst();
    long end = recordFile.getConsensusStart() + offset;
    DateRangeFilter filter = new DateRangeFilter(Instant.EPOCH, Instant.ofEpochSecond(0, end));
    doReturn(filter).when(mirrorDateRangePropertiesProcessor).getDateRangeFilter(parserProperties.getStreamType());
    // when
    parser.parse(recordFile);
    // then
    verify(recordStreamFileListener).onStart();
    if (offset >= 0) {
        verify(recordItemListener).onItem(firstItem);
    }
    verify(recordStreamFileListener).onEnd(recordFile);
    assertPostParseStreamFile(recordFile, true);
}
Also used : RecordFile(com.hedera.mirror.common.domain.transaction.RecordFile) DateRangeFilter(com.hedera.mirror.importer.config.MirrorDateRangePropertiesProcessor.DateRangeFilter) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with DateRangeFilter

use of com.hedera.mirror.importer.config.MirrorDateRangePropertiesProcessor.DateRangeFilter in project hedera-mirror-node by hashgraph.

the class RecordFileParserTest method startDate.

@ParameterizedTest(name = "startDate with offset {0}ns")
@CsvSource({ "-1", "0", "1" })
void startDate(long offset) {
    // given
    RecordFile recordFile = (RecordFile) getStreamFile();
    RecordItem firstItem = recordFile.getItems().blockFirst();
    long start = recordFile.getConsensusStart() + offset;
    DateRangeFilter filter = new DateRangeFilter(Instant.ofEpochSecond(0, start), null);
    doReturn(filter).when(mirrorDateRangePropertiesProcessor).getDateRangeFilter(parserProperties.getStreamType());
    // when
    parser.parse(recordFile);
    // then
    verify(recordStreamFileListener).onStart();
    if (offset < 0) {
        verify(recordItemListener).onItem(firstItem);
    }
    verify(recordStreamFileListener).onEnd(recordFile);
    assertPostParseStreamFile(recordFile, true);
}
Also used : RecordFile(com.hedera.mirror.common.domain.transaction.RecordFile) DateRangeFilter(com.hedera.mirror.importer.config.MirrorDateRangePropertiesProcessor.DateRangeFilter) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with DateRangeFilter

use of com.hedera.mirror.importer.config.MirrorDateRangePropertiesProcessor.DateRangeFilter 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);
}
Also used : FileOperationException(com.hedera.mirror.importer.exception.FileOperationException) Resource(org.springframework.core.io.Resource) IOException(java.io.IOException) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) ValidatedDataInputStream(com.hedera.mirror.importer.reader.ValidatedDataInputStream) DateRangeFilter(com.hedera.mirror.importer.config.MirrorDateRangePropertiesProcessor.DateRangeFilter) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) HashSet(java.util.HashSet)

Example 4 with DateRangeFilter

use of com.hedera.mirror.importer.config.MirrorDateRangePropertiesProcessor.DateRangeFilter in project hedera-mirror-node by hashgraph.

the class MirrorDateRangePropertiesProcessorTest method startDateSetAndDatabaseEmpty.

@Test
void startDateSetAndDatabaseEmpty() {
    var startDate = STARTUP_TIME.plusSeconds(10L);
    mirrorProperties.setStartDate(startDate);
    DateRangeFilter expectedFilter = new DateRangeFilter(mirrorProperties.getStartDate(), null);
    Instant expectedDate = mirrorProperties.getStartDate();
    for (var downloaderProperties : downloaderPropertiesList) {
        StreamType streamType = downloaderProperties.getStreamType();
        assertThat(mirrorDateRangePropertiesProcessor.getLastStreamFile(streamType)).isEqualTo(streamFile(streamType, expectedDate));
        assertThat(mirrorDateRangePropertiesProcessor.getDateRangeFilter(streamType)).isEqualTo(expectedFilter);
    }
    assertThat(mirrorProperties.getVerifyHashAfter()).isEqualTo(startDate);
}
Also used : StreamType(com.hedera.mirror.common.domain.StreamType) Instant(java.time.Instant) DateRangeFilter(com.hedera.mirror.importer.config.MirrorDateRangePropertiesProcessor.DateRangeFilter) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with DateRangeFilter

use of com.hedera.mirror.importer.config.MirrorDateRangePropertiesProcessor.DateRangeFilter in project hedera-mirror-node by hashgraph.

the class MirrorDateRangePropertiesProcessorTest method startDateNotSetAndEndDateAfterLongMaxAndDatabaseNotEmpty.

@Test
void startDateNotSetAndEndDateAfterLongMaxAndDatabaseNotEmpty() {
    Instant past = STARTUP_TIME.minusSeconds(100);
    mirrorProperties.setEndDate(Utility.MAX_INSTANT_LONG.plusNanos(1));
    doReturn(streamFile(StreamType.BALANCE, past)).when(accountBalanceFileRepository).findLatest();
    doReturn(streamFile(StreamType.EVENT, past)).when(eventFileRepository).findLatest();
    doReturn(streamFile(StreamType.RECORD, past)).when(recordFileRepository).findLatest();
    for (var downloaderProperties : downloaderPropertiesList) {
        StreamType streamType = downloaderProperties.getStreamType();
        assertThat(mirrorDateRangePropertiesProcessor.getLastStreamFile(streamType)).matches(s -> matches(s, past));
        assertThat(mirrorDateRangePropertiesProcessor.getDateRangeFilter(streamType)).isEqualTo(new DateRangeFilter(past, Utility.MAX_INSTANT_LONG));
    }
    assertThat(mirrorProperties.getVerifyHashAfter()).isEqualTo(Instant.EPOCH);
}
Also used : StreamType(com.hedera.mirror.common.domain.StreamType) Instant(java.time.Instant) DateRangeFilter(com.hedera.mirror.importer.config.MirrorDateRangePropertiesProcessor.DateRangeFilter) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

DateRangeFilter (com.hedera.mirror.importer.config.MirrorDateRangePropertiesProcessor.DateRangeFilter)14 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 StreamType (com.hedera.mirror.common.domain.StreamType)8 Instant (java.time.Instant)8 Test (org.junit.jupiter.api.Test)5 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)4 CsvSource (org.junit.jupiter.params.provider.CsvSource)3 ValueSource (org.junit.jupiter.params.provider.ValueSource)3 RecordFile (com.hedera.mirror.common.domain.transaction.RecordFile)2 StreamFile (com.hedera.mirror.common.domain.StreamFile)1 AccountBalance (com.hedera.mirror.common.domain.balance.AccountBalance)1 AccountBalanceFile (com.hedera.mirror.common.domain.balance.AccountBalanceFile)1 TokenBalance (com.hedera.mirror.common.domain.balance.TokenBalance)1 MirrorDateRangePropertiesProcessor (com.hedera.mirror.importer.config.MirrorDateRangePropertiesProcessor)1 FileOperationException (com.hedera.mirror.importer.exception.FileOperationException)1 Leader (com.hedera.mirror.importer.leader.Leader)1 AbstractStreamFileParser (com.hedera.mirror.importer.parser.AbstractStreamFileParser)1 BatchPersister (com.hedera.mirror.importer.parser.batch.BatchPersister)1 ValidatedDataInputStream (com.hedera.mirror.importer.reader.ValidatedDataInputStream)1 StreamFileRepository (com.hedera.mirror.importer.repository.StreamFileRepository)1