cameronlee314 commented on a change in pull request #918: SAMZA-2094: Implement the StartpointVisitor for the KafkaSystemConsumer. URL: https://github.com/apache/samza/pull/918#discussion_r266996590
########## File path: samza-kafka/src/main/java/org/apache/samza/system/kafka/KafkaSystemConsumer.java ########## @@ -330,6 +325,88 @@ public String getSystemName() { return systemName; } + @VisibleForTesting + class KafkaStartpointRegistrationHandler implements StartpointVisitor { + + @Override + public void visit(SystemStreamPartition systemStreamPartition, StartpointSpecific startpointSpecific) { + TopicPartition topicPartition = toTopicPartition(systemStreamPartition); + long offsetInStartpoint = Long.parseLong(startpointSpecific.getSpecificOffset()); + LOG.info("Updating the consumer fetch offsets of topic partition: {} to {}.", topicPartition, offsetInStartpoint); + + // KafkaConsumer is not thread-safe. + synchronized (kafkaConsumer) { + kafkaConsumer.seek(topicPartition, offsetInStartpoint); + } + + // add the partition to the proxy + proxy.addTopicPartition(systemStreamPartition, kafkaConsumer.position(topicPartition)); Review comment: Does `kafkaConsumer.position` need to be protected by the lock too? Also, please check below for other usages of `kafkaConsumer` outside of the lock. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services