use of com.hedera.mirror.grpc.domain.TopicMessageFilter in project hedera-mirror-node by hashgraph.
the class TopicMessageServiceImpl method missingMessages.
/**
* A flow can have missing messages if the importer is down for a long time when the client subscribes. When the
* incoming flow catches up and receives the next message for the topic, it will fill in any missing messages from
* when it was down.
*/
private Flux<TopicMessage> missingMessages(TopicContext topicContext, TopicMessage current) {
if (topicContext.isNext(current)) {
return Flux.just(current);
}
TopicMessage last = topicContext.getLast();
long numMissingMessages = current.getSequenceNumber() - last.getSequenceNumber() - 1;
// fail fast on out of order messages
if (numMissingMessages < -1) {
throw new IllegalStateException(String.format("Encountered out of order missing messages, last: %s, current: %s", last, current));
}
// ignore duplicate message already processed by larger subscribe context
if (numMissingMessages == -1) {
log.debug("Encountered duplicate missing message to be ignored, last: {}, current: {}", last, current);
return Flux.empty();
}
TopicMessageFilter newFilter = topicContext.getFilter().toBuilder().endTime(current.getConsensusTimestampInstant()).limit(numMissingMessages).startTime(last.getConsensusTimestampInstant().plusNanos(1)).build();
log.info("[{}] Querying topic {} for missing messages between sequence {} and {}", newFilter.getSubscriberId(), topicContext.getTopicId(), last.getSequenceNumber(), current.getSequenceNumber());
return topicMessageRetriever.retrieve(newFilter, false).concatWithValues(current).name("findMissing").metrics();
}
use of com.hedera.mirror.grpc.domain.TopicMessageFilter in project hedera-mirror-node by hashgraph.
the class PollingTopicListener method poll.
private Flux<TopicMessage> poll(PollingContext context) {
TopicMessageFilter filter = context.getFilter();
TopicMessage last = context.getLast();
int limit = filter.hasLimit() ? (int) (filter.getLimit() - context.getCount().get()) : Integer.MAX_VALUE;
int pageSize = Math.min(limit, listenerProperties.getMaxPageSize());
Instant startTime = last != null ? last.getConsensusTimestampInstant().plusNanos(1) : filter.getStartTime();
TopicMessageFilter newFilter = filter.toBuilder().limit(pageSize).startTime(startTime).build();
return Flux.fromStream(topicMessageRepository.findByFilter(newFilter)).name("findByFilter").metrics();
}
Aggregations