gianm commented on code in PR #18871:
URL: https://github.com/apache/druid/pull/18871#discussion_r2656724764


##########
server/src/main/java/org/apache/druid/segment/loading/StorageLocation.java:
##########
@@ -444,6 +435,52 @@ public void release(CacheEntry entry)
     }
   }
 
+  /**
+   * Creates a release runnable for a {@link WeakCacheEntry} that handles 
immediate eviction when configured.
+   * If {@link #evictImmediately} is true and there are no more holds after 
releasing, the entry is immediately
+   * evicted from the cache. For new entries (isNewEntry=true), unmounted 
entries are also removed.
+   */
+  private Runnable createWeakEntryReleaseRunnable(
+      final WeakCacheEntry weakEntry,
+      final boolean isNewEntry
+  )
+  {
+    return () -> {
+      weakEntry.release();
+
+      if (!isNewEntry && !evictImmediately) {
+        // No need to consider removal from weakCacheEntries on hold release.
+        return;
+      }
+
+      lock.writeLock().lock();
+      try {
+        weakCacheEntries.computeIfPresent(
+            weakEntry.cacheEntry.getId(),
+            (cacheEntryIdentifier, weakCacheEntry) -> {
+              // If we never successfully mounted, go ahead and remove so we 
don't have a dead entry.
+              // Futhermore, if evictImmediately is set, evict on release if 
all holds are gone.
+              final boolean isMounted = weakCacheEntry.cacheEntry.isMounted();
+              if ((isNewEntry && !isMounted)
+                  || (evictImmediately && !weakCacheEntry.isHeld())) {

Review Comment:
   Yeah, the idea is that segments are evicted as soon as they have no holds. 
I'll do the rebrand.



##########
server/src/main/java/org/apache/druid/segment/loading/StorageLocation.java:
##########
@@ -106,9 +106,7 @@ public class StorageLocation
   @GuardedBy("lock")
   private WeakCacheEntry hand;
 
-  /**
-   * Current total size of files in bytes, including weak entries.
-   */
+  private volatile boolean evictImmediately = false;

Review Comment:
   I thought `evictImmediately` was clear, since what else could "immediately" 
mean beyond "as soon as holds are released"? Will do the rebrand though.



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