sashidhar commented on a change in pull request #7764: #7316 Use 
Map.putIfAbsent() instead of containsKey() + put()
URL: https://github.com/apache/incubator-druid/pull/7764#discussion_r287866880
 
 

 ##########
 File path: 
indexing-service/src/main/java/org/apache/druid/indexing/firehose/IngestSegmentFirehoseFactory.java
 ##########
 @@ -204,87 +204,87 @@ public Firehose connect(InputRowParser inputRowParser, 
File temporaryDirectory)
         segmentIds
     );
 
-    try {
-      final List<TimelineObjectHolder<String, DataSegment>> timeLineSegments = 
getTimeline();
-
-      // Download all segments locally.
-      // Note: this requires enough local storage space to fit all of the 
segments, even though
-      // IngestSegmentFirehose iterates over the segments in series. We may 
want to change this
-      // to download files lazily, perhaps sharing code with 
PrefetchableTextFilesFirehoseFactory.
-      final SegmentLoader segmentLoader = 
segmentLoaderFactory.manufacturate(temporaryDirectory);
-      Map<DataSegment, File> segmentFileMap = Maps.newLinkedHashMap();
-      for (TimelineObjectHolder<String, DataSegment> holder : 
timeLineSegments) {
-        for (PartitionChunk<DataSegment> chunk : holder.getObject()) {
-          final DataSegment segment = chunk.getObject();
-          if (!segmentFileMap.containsKey(segment)) {
-            segmentFileMap.put(segment, 
segmentLoader.getSegmentFiles(segment));
+    final List<TimelineObjectHolder<String, DataSegment>> timeLineSegments = 
getTimeline();
+
+    // Download all segments locally.
+    // Note: this requires enough local storage space to fit all of the 
segments, even though
+    // IngestSegmentFirehose iterates over the segments in series. We may want 
to change this
+    // to download files lazily, perhaps sharing code with 
PrefetchableTextFilesFirehoseFactory.
+    final SegmentLoader segmentLoader = 
segmentLoaderFactory.manufacturate(temporaryDirectory);
+    Map<DataSegment, File> segmentFileMap = Maps.newLinkedHashMap();
+    for (TimelineObjectHolder<String, DataSegment> holder : timeLineSegments) {
+      for (PartitionChunk<DataSegment> chunk : holder.getObject()) {
+        final DataSegment segment = chunk.getObject();
+
+        segmentFileMap.computeIfAbsent(segment, k -> {
+          try {
+            return segmentLoader.getSegmentFiles(segment);
 
 Review comment:
   segmentLoader.getSegmentFiles(segment) throws SegmentLoadingException, which 
needs to be caught and re thrown as RuntimeException. This makes the outer try 
catch redundant (compilation error) as the SegmentLoadingException has already 
been caught.

----------------------------------------------------------------
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

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org
For additional commands, e-mail: commits-h...@druid.apache.org

Reply via email to