ben-manes commented on code in PR #13850:
URL: https://github.com/apache/kafka/pull/13850#discussion_r1229867001


##########
core/src/main/scala/kafka/log/remote/RemoteIndexCache.scala:
##########
@@ -266,13 +309,21 @@ class RemoteIndexCache(maxSize: Int = 1024, 
remoteStorageManager: RemoteStorageM
     getIndexEntry(remoteLogSegmentMetadata).lookupTimestamp(timestamp, 
startingOffset).position
   }
 
+  /**
+   * Close should synchronously cleanup the resources used by this cache.
+   * This index is closed when [[RemoteLogManager]] is closed.
+   */
   def close(): Unit = {
-    closed = true
-    cleanerThread.shutdown()
-    // Close all the opened indexes.
-    lock synchronized {
-      entries.values().stream().forEach(entry => entry.close())
+    // make close idempotent
+    if (!closed.getAndSet(true)) {
+      // Initiate shutdown for cleaning thread
+      val shutdownRequired = cleanerThread.initiateShutdown()
+      // Close all the opened indexes to force unload mmap memory. This does 
not delete the index files from disk.
+      internalCache.asMap().forEach((_, entry) => entry.close())
+      // Perform any pending activities required by the cache for cleanup
+      internalCache.cleanUp()

Review Comment:
   Yep, it is just a fancy in-memory hash map. Caffeine doesn’t create threads, 
files, whatever. The cleanUp() method simply runs the maintenance work like 
discarding expired or weak/soft collected entries, which might occur before it 
realizes otherwise. It is fully gc’able.



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

Reply via email to