cecemei commented on code in PR #18176:
URL: https://github.com/apache/druid/pull/18176#discussion_r2230216622


##########
server/src/main/java/org/apache/druid/segment/loading/SegmentLocalCacheManager.java:
##########
@@ -209,382 +272,172 @@ public void removeInfoFile(DataSegment segment)
   }
 
   @Override
-  public ReferenceCountedSegmentProvider getSegment(final DataSegment 
dataSegment) throws SegmentLoadingException
-  {
-    final File segmentFiles = getSegmentFiles(dataSegment);
-    final SegmentizerFactory factory = getSegmentFactory(segmentFiles);
-
-    final Segment segment = factory.factorize(dataSegment, segmentFiles, 
false, SegmentLazyLoadFailCallback.NOOP);
-    return ReferenceCountedSegmentProvider.wrapSegment(segment, 
dataSegment.getShardSpec());
-  }
-
-  @Override
-  public ReferenceCountedSegmentProvider getBootstrapSegment(
-      final DataSegment dataSegment,
-      final SegmentLazyLoadFailCallback loadFailed
-  ) throws SegmentLoadingException
-  {
-    final File segmentFiles = getSegmentFiles(dataSegment);
-    final SegmentizerFactory factory = getSegmentFactory(segmentFiles);
-
-    final Segment segment = factory.factorize(dataSegment, segmentFiles, 
config.isLazyLoadOnStart(), loadFailed);
-    return ReferenceCountedSegmentProvider.wrapSegment(segment, 
dataSegment.getShardSpec());
-  }
-
-  private SegmentizerFactory getSegmentFactory(final File segmentFiles) throws 
SegmentLoadingException
-  {
-    final File factoryJson = new File(segmentFiles, "factory.json");
-    final SegmentizerFactory factory;
-
-    if (factoryJson.exists()) {
-      try {
-        factory = jsonMapper.readValue(factoryJson, SegmentizerFactory.class);
-      }
-      catch (IOException e) {
-        throw new SegmentLoadingException(e, "Failed to get segment facotry 
for %s", e.getMessage());
-      }
-    } else {
-      factory = new MMappedQueryableSegmentizerFactory(indexIO);
-    }
-    return factory;
-  }
-
-  /**
-   * Returns the effective segment info directory based on the configuration 
settings.
-   * The directory is selected based on the following configurations injected 
into this class:
-   * <ul>
-   *   <li>{@link SegmentLoaderConfig#getInfoDir()} - If {@code infoDir} is 
set, it is used as the info directory.</li>
-   *   <li>{@link SegmentLoaderConfig#getLocations()} - If the info directory 
is not set, the first location from this list is used.</li>
-   *   <li>List of {@link StorageLocation}s injected - If both the info 
directory and locations list are not set, the
-   *   first storage location is used.</li>
-   * </ul>
-   *
-   * @throws DruidException if none of the configurations are set, and the 
info directory cannot be determined.
-   */
-  private File getEffectiveInfoDir()
-  {
-    final File infoDir;
-    if (config.getInfoDir() != null) {
-      infoDir = config.getInfoDir();
-    } else if (!config.getLocations().isEmpty()) {
-      infoDir = new File(config.getLocations().get(0).getPath(), "info_dir");
-    } else if (!locations.isEmpty()) {
-      infoDir = new File(locations.get(0).getPath(), "info_dir");
-    } else {
-      throw DruidException.forPersona(DruidException.Persona.OPERATOR)
-          .ofCategory(DruidException.Category.NOT_FOUND)
-          .build("Could not determine infoDir. Make sure 
'druid.segmentCache.infoDir' "
-                 + "or 'druid.segmentCache.locations' is set correctly.");
-    }
-    return infoDir;
-  }
-
-  private static String getSegmentDir(DataSegment segment)
-  {
-    return DataSegmentPusher.getDefaultStorageDir(segment, false);
-  }
-
-  /**
-   * Checks whether a segment is already cached. It can return false even if 
{@link #reserve(DataSegment)}
-   * has been successful for a segment but is not downloaded yet.
-   */
-  boolean isSegmentCached(final DataSegment segment)
-  {
-    return findStoragePathIfCached(segment) != null;
-  }
-
-  /**
-   * 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.
-   */
-  @Nullable
-  private File findStoragePathIfCached(final DataSegment segment)
+  public Optional<Segment> acquireSegment(final DataSegment dataSegment)
   {
+    final SegmentCacheEntryIdentifier cacheEntryIdentifier = new 
SegmentCacheEntryIdentifier(dataSegment.getId());

Review Comment:
   gotcha - i was just wondering maybe we could simplify the class



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to