This is an automated email from the ASF dual-hosted git repository.

kfaraz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/druid.git


The following commit(s) were added to refs/heads/master by this push:
     new b9cf125ab4f Refactor: Reduce nesting in 
`SegmentLocalCacheManager.addFilesToCachedSegments` (#18852)
b9cf125ab4f is described below

commit b9cf125ab4f0c7f6e85f85f09b2b4415b575081c
Author: Virushade <[email protected]>
AuthorDate: Fri Dec 19 18:44:04 2025 +0800

    Refactor: Reduce nesting in 
`SegmentLocalCacheManager.addFilesToCachedSegments` (#18852)
---
 .../segment/loading/SegmentLocalCacheManager.java  | 71 +++++++++++-----------
 1 file changed, 36 insertions(+), 35 deletions(-)

diff --git 
a/server/src/main/java/org/apache/druid/segment/loading/SegmentLocalCacheManager.java
 
b/server/src/main/java/org/apache/druid/segment/loading/SegmentLocalCacheManager.java
index ec499dc0205..a38e63450a3 100644
--- 
a/server/src/main/java/org/apache/druid/segment/loading/SegmentLocalCacheManager.java
+++ 
b/server/src/main/java/org/apache/druid/segment/loading/SegmentLocalCacheManager.java
@@ -255,47 +255,48 @@ public class SegmentLocalCacheManager implements 
SegmentCacheManager
   private void addFilesToCachedSegments(File file, AtomicInteger ignored, 
List<DataSegment> cachedSegments) throws IOException
   {
     final DataSegment segment = jsonMapper.readValue(file, DataSegment.class);
-    boolean removeInfo = false;
     if (!segment.getId().toString().equals(file.getName())) {
       log.warn("Ignoring cache file[%s] for segment[%s].", file.getPath(), 
segment.getId());
       ignored.incrementAndGet();
-    } else {
-      removeInfo = true;
-      final SegmentCacheEntry cacheEntry = new SegmentCacheEntry(segment);
-      for (StorageLocation location : locations) {
-        // check for migrate from old nested local storage path format
-        final File legacyPath = new File(location.getPath(), 
DataSegmentPusher.getDefaultStorageDir(segment, false));
-        if (legacyPath.exists()) {
-          final File destination = 
cacheEntry.toPotentialLocation(location.getPath());
-          FileUtils.mkdirp(destination);
-          final File[] oldFiles = legacyPath.listFiles();
-          final File[] newFiles = destination.listFiles();
-          // make sure old files exist and new files do not exist
-          if (oldFiles != null && oldFiles.length > 0 && newFiles != null && 
newFiles.length == 0) {
-            Files.move(legacyPath.toPath(), destination.toPath(), 
StandardCopyOption.ATOMIC_MOVE);
-          }
-          cleanupLegacyCacheLocation(location.getPath(), legacyPath);
+      return;
+    }
+
+    boolean removeInfo = true;
+
+    final SegmentCacheEntry cacheEntry = new SegmentCacheEntry(segment);
+    for (StorageLocation location : locations) {
+      // check for migrate from old nested local storage path format
+      final File legacyPath = new File(location.getPath(), 
DataSegmentPusher.getDefaultStorageDir(segment, false));
+      if (legacyPath.exists()) {
+        final File destination = 
cacheEntry.toPotentialLocation(location.getPath());
+        FileUtils.mkdirp(destination);
+        final File[] oldFiles = legacyPath.listFiles();
+        final File[] newFiles = destination.listFiles();
+        // make sure old files exist and new files do not exist
+        if (oldFiles != null && oldFiles.length > 0 && newFiles != null && 
newFiles.length == 0) {
+          Files.move(legacyPath.toPath(), destination.toPath(), 
StandardCopyOption.ATOMIC_MOVE);
         }
+        cleanupLegacyCacheLocation(location.getPath(), legacyPath);
+      }
 
-        if (cacheEntry.checkExists(location.getPath())) {
-          removeInfo = false;
-          final boolean reserveResult;
-          if (config.isVirtualStorage()) {
-            reserveResult = location.reserveWeak(cacheEntry);
-          } else {
-            reserveResult = location.reserve(cacheEntry);
-          }
-          if (!reserveResult) {
-            log.makeAlert(
-                "storage[%s:%,d] has more segments than it is allowed. 
Currently loading Segment[%s:%,d]. Please increase druid.segmentCache.locations 
maxSize param",
-                location.getPath(),
-                location.availableSizeBytes(),
-                segment.getId(),
-                segment.getSize()
-            ).emit();
-          }
-          cachedSegments.add(segment);
+      if (cacheEntry.checkExists(location.getPath())) {
+        removeInfo = false;
+        final boolean reserveResult;
+        if (config.isVirtualStorage()) {
+          reserveResult = location.reserveWeak(cacheEntry);
+        } else {
+          reserveResult = location.reserve(cacheEntry);
+        }
+        if (!reserveResult) {
+          log.makeAlert(
+              "storage[%s:%,d] has more segments than it is allowed. Currently 
loading Segment[%s:%,d]. Please increase druid.segmentCache.locations maxSize 
param",
+              location.getPath(),
+              location.availableSizeBytes(),
+              segment.getId(),
+              segment.getSize()
+          ).emit();
         }
+        cachedSegments.add(segment);
       }
     }
 


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

Reply via email to