jihoonson commented on a change in pull request #8114: Fix race between 
canHandle() and addSegment() in StorageLocation
URL: https://github.com/apache/incubator-druid/pull/8114#discussion_r306573880
 
 

 ##########
 File path: 
indexing-service/src/main/java/org/apache/druid/indexing/worker/IntermediaryDataManager.java
 ##########
 @@ -279,53 +279,65 @@ public static void addSegment(
       String subTaskId,
       DataSegment segment,
       File segmentFile
-  ) throws IOException
-  {
-    final StorageLocation location = findLocationForSegment(cyclicIterator, 
numLocations, segment);
-    final File destFile = new File(
-        getPartitionDir(location, supervisorTaskId, segment.getInterval(), 
segment.getShardSpec().getPartitionNum()),
-        subTaskId
-    );
-    FileUtils.forceMkdirParent(destFile);
-    final long copiedBytes = 
Files.asByteSource(segmentFile).copyTo(Files.asByteSink(destFile));
-    if (copiedBytes == 0) {
-      throw new IOE(
-          "0 bytes copied after copying a segment file from [%s] to [%s]",
-          segmentFile.getAbsolutePath(),
-          destFile.getAbsolutePath()
-      );
-    }
-    location.addFile(destFile);
-  }
-
-  private static StorageLocation findLocationForSegment(
-      Iterator<StorageLocation> cyclicIterator,
-      int numLocations,
-      DataSegment segment
   )
   {
     for (int i = 0; i < numLocations; i++) {
       final StorageLocation location = cyclicIterator.next();
-      if (location.canHandle(segment)) {
-        return location;
+      final File destFile = location.reserve(
+          getPartitionFilePath(
+              supervisorTaskId,
+              subTaskId,
+              segment.getInterval(),
+              segment.getShardSpec().getPartitionNum()
+          ),
+          segment.getId(),
+          segmentFile.length()
+      );
+      if (destFile != null) {
+        try {
+          FileUtils.forceMkdirParent(destFile);
+          final long copiedBytes = 
Files.asByteSource(segmentFile).copyTo(Files.asByteSink(destFile));
+          if (copiedBytes == 0) {
+            throw new IOE(
+                "0 bytes copied after copying a segment file from [%s] to 
[%s]",
+                segmentFile.getAbsolutePath(),
+                destFile.getAbsolutePath()
+            );
+          } else {
+            return;
+          }
+        }
+        catch (Exception e) {
 
 Review comment:
   This is to print something in the log file so that operators could notice 
that something happened.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to