divijvaidya commented on code in PR #13850:
URL: https://github.com/apache/kafka/pull/13850#discussion_r1229867810


##########
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:
   Thank you for jumping in this review and providing your expert opinion on 
this cache. Appreciate it!



-- 
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: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to