You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@gobblin.apache.org by GitBox <gi...@apache.org> on 2020/03/02 17:47:33 UTC

[GitHub] [incubator-gobblin] vikrambohra commented on a change in pull request #2900: [GOBBLIN-1040] HighLevelConsumer re-design by removing references to …

vikrambohra commented on a change in pull request #2900: [GOBBLIN-1040] HighLevelConsumer re-design by removing references to …
URL: https://github.com/apache/incubator-gobblin/pull/2900#discussion_r386547675
 
 

 ##########
 File path: gobblin-modules/gobblin-kafka-09/src/main/java/org/apache/gobblin/kafka/client/Kafka09ConsumerClient.java
 ##########
 @@ -160,14 +164,30 @@ public long getLatestOffset(KafkaPartition partition) throws KafkaOffsetRetrieva
 
     this.consumer.assign(Lists.newArrayList(new TopicPartition(partition.getTopicName(), partition.getId())));
     this.consumer.seek(new TopicPartition(partition.getTopicName(), partition.getId()), nextOffset);
-    ConsumerRecords<K, V> consumerRecords = consumer.poll(super.fetchTimeoutMillis);
-    return Iterators.transform(consumerRecords.iterator(), new Function<ConsumerRecord<K, V>, KafkaConsumerRecord>() {
+    return consume();
+  }
 
-      @Override
-      public KafkaConsumerRecord apply(ConsumerRecord<K, V> input) {
-        return new Kafka09ConsumerRecord<>(input);
-      }
-    });
+  @Override
+  public synchronized Iterator<KafkaConsumerRecord> consume() {
 
 Review comment:
   Underlying Kafka Consumer is not thread safe. consume() commitAsync(), committed() all try to acquire a lock (and they are different threads) the consumer throws a ConcurrentModificationException if it detects that the lock has been acquired by another thread.
   
       /**
        * Acquire the light lock protecting this consumer from multi-threaded access. Instead of blocking
        * when the lock is not available, however, we just throw an exception (since multi-threaded usage is not
        * supported).
        * @throws IllegalStateException if the consumer has been closed
        * @throws ConcurrentModificationException if another thread already has the lock
        */
       private void acquire() {
           ensureNotClosed();
           long threadId = Thread.currentThread().getId();
           if (threadId != currentThread.get() && !currentThread.compareAndSet(NO_CURRENT_THREAD, threadId))
               throw new ConcurrentModificationException("KafkaConsumer is not safe for multi-threaded access");
           refcount.incrementAndGet();
       }

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services