server/src/main/java/org/apache/druid/segment/loading/SegmentLocalCacheManager.java
/**
   * This method will try to find if the segment is already downloaded on any location. If so, the segment path
   * is returned. Along with that, location state is also updated with the segment location. Refer to
   * {@link StorageLocation#maybeReserve(String, DataSegment)} for more details.
   * If the segment files are damaged in any location, they are removed from the location.
   * @param segment - Segment to check
   * @return - Path corresponding to segment directory if found, null otherwise.
   */
This method will try to find if the segment is already downloaded on any location. If so, the segment path
is returned. Along with that, location state is also updated with the segment location. Refer to
StorageLocation#maybeReserve(String, DataSegment) for more details.
If the segment files are damaged in any location, they are removed from the location.
@param segment - Segment to check
@return - Path corresponding to segment directory if found, null otherwise.
This method will try to find if the segment is already downloaded on any location . If so the segment path is returned . Along with that location state is also updated with the segment location . Refer to StorageLocation#maybeReserve ( String DataSegment ) for more details . If the segment files are damaged in any location they are removed from the location . @param segment - Segment to check @return - Path corresponding to segment directory if found null otherwise .
@Nullable
  private File findStoragePathIfCached(final DataSegment segment)
  {
    for (StorageLocation location : locations) {
      String storageDir = getSegmentDir(segment);
      File localStorageDir = location.segmentDirectoryAsFile(storageDir);
      if (localStorageDir.exists()) {
        if (checkSegmentFilesIntact(localStorageDir)) {
          log.warn(
              "[%s] may be damaged. Delete all the segment files and pull from DeepStorage again.",
              localStorageDir.getAbsolutePath()
          );
          cleanupCacheFiles(location.getPath(), localStorageDir);
          location.removeSegmentDir(localStorageDir, segment);
          break;
        } else {
          location.maybeReserve(storageDir, segment);
          return localStorageDir;
        }
      }
    }
    return null;
  }
@ Nullable private File findStoragePathIfCached ( final DataSegment segment ) { for ( StorageLocation location : locations ) { String storageDir = getSegmentDir ( segment ) ; File localStorageDir = location . segmentDirectoryAsFile ( storageDir ) ; if ( localStorageDir . exists ( ) ) { if ( checkSegmentFilesIntact ( localStorageDir ) ) { log . warn ( "[%s] may be damaged. Delete all the segment files and pull from DeepStorage again." , localStorageDir . getAbsolutePath ( ) ) ; cleanupCacheFiles ( location . getPath ( ) , localStorageDir ) ; location . removeSegmentDir ( localStorageDir , segment ) ; break ; } else { location . maybeReserve ( storageDir , segment ) ; return localStorageDir ; } } } return null ; }
This method will try to find if the segment is already downloaded on any location.
This method will try to find if the segment is already downloaded on any location .
// Before returning, we also reserve the space. Refer to the StorageLocation#maybeReserve documentation for details.