Search in sources :

Example 1 with DATA

use of com.hedera.mirror.importer.domain.StreamFilename.FileType.DATA in project hedera-mirror-node by hashgraph.

the class MirrorDateRangePropertiesProcessor method getLastStreamFile.

/**
 * Gets the latest stream file for downloader based on startDate in MirrorProperties, the startDateAdjustment and
 * last valid downloaded stream file.
 *
 * @param streamType What type of stream to retrieve
 * @return The latest stream file from the database or a dummy stream file if it calculated a different effective
 * start date
 */
public <T extends StreamFile> Optional<T> getLastStreamFile(StreamType streamType) {
    Instant startDate = mirrorProperties.getStartDate();
    Optional<T> streamFile = findLatest(streamType);
    Instant lastFileInstant = streamFile.map(StreamFile::getConsensusStart).map(nanos -> Instant.ofEpochSecond(0, nanos)).orElse(null);
    Instant effectiveStartDate = STARTUP_TIME;
    boolean hasStreamFile = lastFileInstant != null;
    if (startDate != null) {
        effectiveStartDate = max(startDate, hasStreamFile ? lastFileInstant : Instant.EPOCH);
    } else if (hasStreamFile) {
        effectiveStartDate = lastFileInstant;
    } else if (mirrorProperties.getNetwork() == MirrorProperties.HederaNetwork.DEMO) {
        // Demo network contains only data in the past, so don't default to now
        effectiveStartDate = Instant.EPOCH;
    }
    Instant endDate = mirrorProperties.getEndDate();
    if (startDate != null && startDate.compareTo(endDate) > 0) {
        throw new InvalidConfigurationException(String.format("Date range constraint violation: " + "startDate (%s) > endDate (%s)", startDate, endDate));
    }
    if (effectiveStartDate.compareTo(endDate) > 0) {
        throw new InvalidConfigurationException(String.format("Date range constraint violation for %s downloader: effective startDate (%s) > endDate (%s)", streamType, effectiveStartDate, endDate));
    }
    if (!effectiveStartDate.equals(lastFileInstant)) {
        Instant verifyHashAfter = mirrorProperties.getVerifyHashAfter();
        if (verifyHashAfter == null || verifyHashAfter.isBefore(effectiveStartDate)) {
            mirrorProperties.setVerifyHashAfter(effectiveStartDate);
            log.debug("Set verifyHashAfter to {}", effectiveStartDate);
        }
        String filename = StreamFilename.getFilename(streamType, DATA, effectiveStartDate);
        T effectiveStreamFile = (T) ReflectUtils.newInstance(streamType.getStreamFileClass());
        effectiveStreamFile.setConsensusStart(DomainUtils.convertToNanosMax(effectiveStartDate));
        effectiveStreamFile.setName(filename);
        effectiveStreamFile.setIndex(streamFile.map(StreamFile::getIndex).orElse(null));
        streamFile = Optional.of(effectiveStreamFile);
    }
    log.info("{}: downloader will download files in time range ({}, {}]", streamType, effectiveStartDate, mirrorProperties.getEndDate());
    return streamFile;
}
Also used : DownloaderProperties(com.hedera.mirror.importer.downloader.DownloaderProperties) InvalidConfigurationException(com.hedera.mirror.importer.exception.InvalidConfigurationException) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Value(lombok.Value) StreamFilename(com.hedera.mirror.importer.domain.StreamFilename) Duration(java.time.Duration) Map(java.util.Map) Named(javax.inject.Named) Utility(com.hedera.mirror.importer.util.Utility) DomainUtils(com.hedera.mirror.common.util.DomainUtils) ObjectUtils.max(org.apache.commons.lang3.ObjectUtils.max) EventFileRepository(com.hedera.mirror.importer.repository.EventFileRepository) ReflectUtils(org.springframework.cglib.core.ReflectUtils) DATA(com.hedera.mirror.importer.domain.StreamFilename.FileType.DATA) StreamType(com.hedera.mirror.common.domain.StreamType) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) StreamFile(com.hedera.mirror.common.domain.StreamFile) Instant(java.time.Instant) AccountBalanceFileRepository(com.hedera.mirror.importer.repository.AccountBalanceFileRepository) List(java.util.List) MirrorProperties(com.hedera.mirror.importer.MirrorProperties) RecordFileRepository(com.hedera.mirror.importer.repository.RecordFileRepository) Log4j2(lombok.extern.log4j.Log4j2) Optional(java.util.Optional) StreamFileRepository(com.hedera.mirror.importer.repository.StreamFileRepository) Instant(java.time.Instant) StreamFile(com.hedera.mirror.common.domain.StreamFile) InvalidConfigurationException(com.hedera.mirror.importer.exception.InvalidConfigurationException)

Example 2 with DATA

use of com.hedera.mirror.importer.domain.StreamFilename.FileType.DATA in project hedera-mirror-node by hashgraph.

the class ContractResultServiceImplIntegrationTest method parseRecordItemAndCommit.

protected void parseRecordItemAndCommit(RecordItem recordItem, Transaction transaction) {
    transactionTemplate.executeWithoutResult(status -> {
        Instant instant = Instant.ofEpochSecond(0, recordItem.getConsensusTimestamp());
        String filename = StreamFilename.getFilename(StreamType.RECORD, DATA, instant);
        long consensusStart = recordItem.getConsensusTimestamp();
        RecordFile recordFile = domainBuilder.recordFile().customize(x -> x.consensusStart(consensusStart).consensusEnd(consensusStart + 1).name(filename)).get();
        recordStreamFileListener.onStart();
        contractResultService.process(recordItem, transaction);
        // commit, close connection
        recordStreamFileListener.onEnd(recordFile);
    });
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) ContractResultRepository(com.hedera.mirror.importer.repository.ContractResultRepository) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) ContractID(com.hederahashgraph.api.proto.java.ContractID) DomainBuilder(com.hedera.mirror.common.domain.DomainBuilder) RecordFile(com.hedera.mirror.common.domain.transaction.RecordFile) ContractStateChangeRepository(com.hedera.mirror.importer.repository.ContractStateChangeRepository) RecordItemBuilder(com.hedera.mirror.importer.parser.domain.RecordItemBuilder) ContractResult(com.hedera.mirror.common.domain.contract.ContractResult) DomainUtils(com.hedera.mirror.common.util.DomainUtils) ContractStateChange(com.hedera.mirror.common.domain.contract.ContractStateChange) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) RecordStreamFileListener(com.hedera.mirror.importer.parser.record.RecordStreamFileListener) DATA(com.hedera.mirror.importer.domain.StreamFilename.FileType.DATA) StreamType(com.hedera.mirror.common.domain.StreamType) ContractLog(com.hedera.mirror.common.domain.contract.ContractLog) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) ByteString(com.google.protobuf.ByteString) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) TokenType(com.hederahashgraph.api.proto.java.TokenType) ContractLogRepository(com.hedera.mirror.importer.repository.ContractLogRepository) ObjectAssert(org.assertj.core.api.ObjectAssert) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) ContractFunctionResult(com.hederahashgraph.api.proto.java.ContractFunctionResult) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Transaction(com.hedera.mirror.common.domain.transaction.Transaction) RecordFile(com.hedera.mirror.common.domain.transaction.RecordFile) Instant(java.time.Instant) ByteString(com.google.protobuf.ByteString)

Aggregations

StreamType (com.hedera.mirror.common.domain.StreamType)2 DomainUtils (com.hedera.mirror.common.util.DomainUtils)2 DATA (com.hedera.mirror.importer.domain.StreamFilename.FileType.DATA)2 Instant (java.time.Instant)2 RequiredArgsConstructor (lombok.RequiredArgsConstructor)2 ByteString (com.google.protobuf.ByteString)1 DomainBuilder (com.hedera.mirror.common.domain.DomainBuilder)1 StreamFile (com.hedera.mirror.common.domain.StreamFile)1 ContractLog (com.hedera.mirror.common.domain.contract.ContractLog)1 ContractResult (com.hedera.mirror.common.domain.contract.ContractResult)1 ContractStateChange (com.hedera.mirror.common.domain.contract.ContractStateChange)1 EntityId (com.hedera.mirror.common.domain.entity.EntityId)1 RecordFile (com.hedera.mirror.common.domain.transaction.RecordFile)1 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)1 Transaction (com.hedera.mirror.common.domain.transaction.Transaction)1 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)1 MirrorProperties (com.hedera.mirror.importer.MirrorProperties)1 StreamFilename (com.hedera.mirror.importer.domain.StreamFilename)1 DownloaderProperties (com.hedera.mirror.importer.downloader.DownloaderProperties)1 InvalidConfigurationException (com.hedera.mirror.importer.exception.InvalidConfigurationException)1