[ 
https://issues.apache.org/jira/browse/GOBBLIN-2118?focusedWorklogId=928888&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-928888
 ]

ASF GitHub Bot logged work on GOBBLIN-2118:
-------------------------------------------

                Author: ASF GitHub Bot
            Created on: 06/Aug/24 10:48
            Start Date: 06/Aug/24 10:48
    Worklog Time Spent: 10m 
      Work Description: arpit09 commented on code in PR #4009:
URL: https://github.com/apache/gobblin/pull/4009#discussion_r1705323654


##########
gobblin-modules/gobblin-kafka-common/src/main/java/org/apache/gobblin/source/extractor/extract/kafka/KafkaSource.java:
##########
@@ -482,20 +487,54 @@ private static void skipWorkUnit(WorkUnit workUnit) {
     workUnit.setProp(ConfigurationKeys.WORK_UNIT_HIGH_WATER_MARK_KEY, 
workUnit.getLowWaterMark());
   }
 
-  private WorkUnit getWorkUnitForTopicPartition(KafkaPartition partition, 
SourceState state,
+  /**
+   * Get the workunits of all the partitions passed, this method fetches all 
the offsets for the partitions
+   * at once from kafka, and for each partiton creates a workunit.
+   * @param partitions
+   * @param state
+   * @param topicSpecificState
+   * @return
+   */
+  private Map<KafkaPartition, WorkUnit> 
getWorkUnits(Collection<KafkaPartition> partitions, SourceState state,
       Optional<State> topicSpecificState) {
-    Offsets offsets = new Offsets();
-
-    boolean failedToGetKafkaOffsets = false;
-
+    final Map<KafkaPartition, Offsets> partitionOffsetMap = Maps.newHashMap();
+    final Set<KafkaPartition> fetchOffsetsFailedPartitions = Sets.newHashSet();
     try (Timer.Context context = 
this.metricContext.timer(OFFSET_FETCH_TIMER).time()) {
-      offsets.setOffsetFetchEpochTime(System.currentTimeMillis());
-      
offsets.setEarliestOffset(this.kafkaConsumerClient.get().getEarliestOffset(partition));
-      
offsets.setLatestOffset(this.kafkaConsumerClient.get().getLatestOffset(partition));
-    } catch (Throwable t) {
-      failedToGetKafkaOffsets = true;
-      LOG.error("Caught error in creating work unit for {}", partition, t);
+      // Fetch the offsets for all the partitions at once
+      final Map<KafkaPartition, Long> earliestOffsetMap = 
this.kafkaConsumerClient.get().getEarliestOffsets(partitions);
+      final Map<KafkaPartition, Long> latestOffsetMap = 
this.kafkaConsumerClient.get().getLatestOffsets(partitions);
+      for (KafkaPartition partition : partitions) {
+        Offsets offsets = new Offsets();
+        offsets.setOffsetFetchEpochTime(System.currentTimeMillis());
+        if (earliestOffsetMap.containsKey(partition) && 
latestOffsetMap.containsKey(partition)) {

Review Comment:
   Added, this is to check if both earliest offset and latest offset available 
for the partitions. If there is a discrepancy, we failed to fetch the offsets 
and we should move this to failedOffsetPartitionslist. 
   Added the same in the comments 





Issue Time Tracking
-------------------

    Worklog Id:     (was: 928888)
    Time Spent: 1h  (was: 50m)

> Reduce no of network calls while fetching kafka offsets during startup
> ----------------------------------------------------------------------
>
>                 Key: GOBBLIN-2118
>                 URL: https://issues.apache.org/jira/browse/GOBBLIN-2118
>             Project: Apache Gobblin
>          Issue Type: Improvement
>            Reporter: Arpit Varshney
>            Priority: Major
>          Time Spent: 1h
>  Remaining Estimate: 0h
>
> During starting while creating work unit, in Kafkasource there are network 
> calls that tries to fetch the kafka offsets (both earliest and latest) to 
> find out the watermark (to find the offsets where the gobblin job will start 
> consuming from)
> These calls are fetched for each topic and each partition in the topic. For 
> each partition, there is a separate call that goes to kafka client, which 
> increases the no of network calls. If there are cross colo calls (calls to 
> different datacenters in different regions) this increase the time to fetch 
> and results in timeout which leads to skipping of the topic partition to 
> fetch leading to starvation. 
> This ticket targets to reduce the no of network calls, rather than doing a 
> call for each partition. Utilize kafka source to fetch the offsets for all 
> the paritions at once from kafka.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to