Search in sources :

Example 11 with DateRangeFilter

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

the class MirrorDateRangePropertiesProcessorTest method filter.

@ParameterizedTest(name = "filter [{0}, {1}], timestamp {2}, pass: {3}")
@CsvSource(value = { "1, 1, 1, true", "1, 10, 1, true", "1, 10, 10, true", "1, 10, 6, true", "1, 10, 0, false", "1, 10, 11, false", "1, 10, -1, false" })
void filter(long start, long end, long timestamp, boolean expected) {
    DateRangeFilter filter = new DateRangeFilter(Instant.ofEpochSecond(0, start), Instant.ofEpochSecond(0, end));
    assertThat(filter.filter(timestamp)).isEqualTo(expected);
}
Also used : DateRangeFilter(com.hedera.mirror.importer.config.MirrorDateRangePropertiesProcessor.DateRangeFilter) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 12 with DateRangeFilter

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

the class MirrorDateRangePropertiesProcessorTest method notSetAndDatabaseEmpty.

@Test
void notSetAndDatabaseEmpty() {
    Instant expectedDate = STARTUP_TIME;
    DateRangeFilter expectedFilter = new DateRangeFilter(expectedDate, null);
    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(expectedDate);
}
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 13 with DateRangeFilter

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

the class AccountBalanceFileParser method doParse.

@Override
protected void doParse(AccountBalanceFile accountBalanceFile) {
    log.info("Starting processing account balances file {}", accountBalanceFile.getName());
    DateRangeFilter filter = mirrorDateRangePropertiesProcessor.getDateRangeFilter(StreamType.BALANCE);
    int batchSize = ((BalanceParserProperties) parserProperties).getBatchSize();
    long count = 0L;
    if (filter.filter(accountBalanceFile.getConsensusTimestamp())) {
        List<AccountBalance> accountBalances = new ArrayList<>(batchSize);
        Map<TokenBalance.Id, TokenBalance> tokenBalances = new HashMap<>(batchSize);
        count = accountBalanceFile.getItems().doOnNext(accountBalance -> {
            accountBalances.add(accountBalance);
            for (var tokenBalance : accountBalance.getTokenBalances()) {
                if (tokenBalances.putIfAbsent(tokenBalance.getId(), tokenBalance) != null) {
                    log.warn("Skipping duplicate token balance: {}", tokenBalance);
                }
            }
            if (accountBalances.size() >= batchSize) {
                batchPersister.persist(accountBalances);
                accountBalances.clear();
            }
            if (tokenBalances.size() >= batchSize) {
                batchPersister.persist(tokenBalances.values());
                tokenBalances.clear();
            }
        }).count().block();
        batchPersister.persist(accountBalances);
        batchPersister.persist(tokenBalances.values());
    }
    Instant loadEnd = Instant.now();
    accountBalanceFile.setCount(count);
    accountBalanceFile.setLoadEnd(loadEnd.getEpochSecond());
    streamFileListener.onEnd(accountBalanceFile);
    streamFileRepository.save(accountBalanceFile);
}
Also used : MirrorDateRangePropertiesProcessor(com.hedera.mirror.importer.config.MirrorDateRangePropertiesProcessor) Leader(com.hedera.mirror.importer.leader.Leader) StreamType(com.hedera.mirror.common.domain.StreamType) AccountBalanceFile(com.hedera.mirror.common.domain.balance.AccountBalanceFile) HashMap(java.util.HashMap) Instant(java.time.Instant) TokenBalance(com.hedera.mirror.common.domain.balance.TokenBalance) Backoff(org.springframework.retry.annotation.Backoff) ArrayList(java.util.ArrayList) DateRangeFilter(com.hedera.mirror.importer.config.MirrorDateRangePropertiesProcessor.DateRangeFilter) List(java.util.List) AccountBalance(com.hedera.mirror.common.domain.balance.AccountBalance) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Map(java.util.Map) Named(javax.inject.Named) AbstractStreamFileParser(com.hedera.mirror.importer.parser.AbstractStreamFileParser) Retryable(org.springframework.retry.annotation.Retryable) BatchPersister(com.hedera.mirror.importer.parser.batch.BatchPersister) StreamFileRepository(com.hedera.mirror.importer.repository.StreamFileRepository) Transactional(org.springframework.transaction.annotation.Transactional) HashMap(java.util.HashMap) Instant(java.time.Instant) ArrayList(java.util.ArrayList) TokenBalance(com.hedera.mirror.common.domain.balance.TokenBalance) AccountBalance(com.hedera.mirror.common.domain.balance.AccountBalance) DateRangeFilter(com.hedera.mirror.importer.config.MirrorDateRangePropertiesProcessor.DateRangeFilter)

Example 14 with DateRangeFilter

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

the class RecordFileParser method doParse.

@Override
protected void doParse(RecordFile recordFile) {
    DateRangeFilter dateRangeFilter = mirrorDateRangePropertiesProcessor.getDateRangeFilter(parserProperties.getStreamType());
    try {
        Flux<RecordItem> recordItems = recordFile.getItems();
        if (log.getLevel().isInRange(Level.DEBUG, Level.TRACE)) {
            recordItems = recordItems.doOnNext(this::logItem);
        }
        recordStreamFileListener.onStart();
        long count = recordItems.doOnNext(recordFile::processItem).filter(r -> dateRangeFilter.filter(r.getConsensusTimestamp())).doOnNext(recordItemListener::onItem).doOnNext(this::recordMetrics).count().block();
        recordFile.finishLoad(count);
        recordStreamFileListener.onEnd(recordFile);
    } catch (Exception ex) {
        recordStreamFileListener.onError();
        throw ex;
    }
}
Also used : DateRangeFilter(com.hedera.mirror.importer.config.MirrorDateRangePropertiesProcessor.DateRangeFilter) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem)

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