samza-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] cameronlee314 commented on a change in pull request #918: SAMZA-2094: Implement the StartpointVisitor for the KafkaSystemConsumer.
Date Fri, 15 Feb 2019 00:12:00 GMT
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_r257061221
 
 

 ##########
 File path: samza-kafka/src/main/java/org/apache/samza/system/kafka/KafkaSystemConsumer.java
 ##########
 @@ -330,6 +387,73 @@ public String getSystemName() {
     return systemName;
   }
 
+  @VisibleForTesting
+  static class KafkaStartpointRegistrationHandler implements StartpointVisitor {
+
+    private final Consumer kafkaConsumer;
+
+    KafkaStartpointRegistrationHandler(Consumer kafkaConsumer) {
+      this.kafkaConsumer = kafkaConsumer;
+    }
+
+    @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);
 
 Review comment:
   `kafkaConsumer.seek` is wrapped in a try-catch above. Should that be done here as well?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message