Source:
<code>protected ConsumerRecords<?, ?> pollRecords(long pollInterval) throws Exception { ConsumerRecords<?, ?> records; try { long curPollTime = System.currentTimeMillis(); _lastPolledTimeMillis = curPollTime; records = _consumer.poll(pollInterval); long pollDurationMillis = System.currentTimeMillis() - curPollTime; if (pollDurationMillis > pollInterval + POLL_BUFFER_TIME_MILLIS) { _logger.warn("ConsumerId: {}, Kafka client poll took ms (> poll timeout + buffer time ms)", _taskName, pollDurationMillis, pollInterval, POLL_BUFFER_TIME_MILLIS); _consumerMetrics.updateClientPollOverTimeout(1); } _consumerMetrics.updateNumPolls(1); _consumerMetrics.updateEventCountsPerPoll(records.count()); if (!records.isEmpty()) { _consumerMetrics.updateEventsProcessedRate(records.count()); _consumerMetrics.updateLastEventReceivedTime(Instant.now()); } _pollAttempts = 0; _kafkaPositionTracker.ifPresent(tracker -> { for (final TopicPartition topicPartition : tracker.getPartitionsNeedingInit()) { try { <START> tracker.initializePartition(topicPartition, _consumer.position(topicPartition)); <END> } catch (IllegalStateException ignored) { } catch (InvalidOffsetException ignored) { } } tracker.onRecordsReceived(records, _consumer.metrics()); }); return records; } catch (NoOffsetForPartitionException e) { handleNoOffsetForPartitionException(e); return ConsumerRecords.EMPTY; } catch (WakeupException e) { _logger.warn("Got a WakeupException, shutdown in progress.", e); return ConsumerRecords.EMPTY; } catch (Exception e) { handlePollRecordsException(e); return ConsumerRecords.EMPTY; } }</code><technical_language>cynic in mind reads this wonders: Kafka position tracker a dedicated consumer ScheduledExecutorService. is making RPC call task's consumer (even if optimizing invoking right poll()), especially positions() invoked else. I understand share a single consumer multiple threads, tracker dedicated consumer fetch broker offsets _and_ assigned partition offsets? Is consumer poll</technical_language>

Target:
protected ConsumerRecords<?, ?> pollRecords(long pollInterval) throws Exception { ConsumerRecords<?, ?> records; try { long curPollTime = System.currentTimeMillis(); _lastPolledTimeMillis = curPollTime; records = _consumer.poll(pollInterval); long pollDurationMillis = System.currentTimeMillis() - curPollTime; if (pollDurationMillis > pollInterval + POLL_BUFFER_TIME_MILLIS) { _logger.warn("ConsumerId: {}, Kafka client poll took ms (> poll timeout + buffer time ms)", _taskName, pollDurationMillis, pollInterval, POLL_BUFFER_TIME_MILLIS); _consumerMetrics.updateClientPollOverTimeout(1); } _consumerMetrics.updateNumPolls(1); _consumerMetrics.updateEventCountsPerPoll(records.count()); if (!records.isEmpty()) { _consumerMetrics.updateEventsProcessedRate(records.count()); _consumerMetrics.updateLastEventReceivedTime(Instant.now()); } _pollAttempts = 0; try { _kafkaPositionTracker.ifPresent(tracker -> { for (final TopicPartition topicPartition : tracker.getPartitionsNeedingInit()) { try { tracker.initializePartition(topicPartition, _consumer.position(topicPartition)); } catch (IllegalStateException e) { _logger.trace("Got IllegalStateException when processing partition {}", topicPartition, e); } catch (InvalidOffsetException e) { _logger.trace("Got InvalidOffsetException when processing partition {}", topicPartition, e); } } tracker.onRecordsReceived(records, _consumer.metrics()); }); } catch (WakeupException | InterruptException e) { throw e; } catch (Exception e) { _logger.warn("Got uncaught exception while processing position tracker code (swallowing and continuing)", e); } return records; } catch (NoOffsetForPartitionException e) { handleNoOffsetForPartitionException(e); return ConsumerRecords.EMPTY; } catch (WakeupException e) { _logger.warn("Got a WakeupException, shutdown in progress.", e); return ConsumerRecords.EMPTY; } catch (Exception e) { handlePollRecordsException(e); return ConsumerRecords.EMPTY; } }