showuon commented on code in PR #21088:
URL: https://github.com/apache/kafka/pull/21088#discussion_r2605453945


##########
storage/src/main/java/org/apache/kafka/storage/internals/log/RemoteIndexCache.java:
##########
@@ -345,7 +368,18 @@ public Entry getIndexEntry(RemoteLogSegmentMetadata 
metadata) {
         lock.readLock().lock();
         try {
             throwIfCacheClosed(uuid);
-            return internalCache.get(uuid, k -> createCacheEntry(metadata));
+            Entry entry = internalCache.get(uuid, k -> 
createCacheEntry(metadata));
+
+            // Handle race where entry is evicted and marked for cleanup, but 
still returned by cache.get().
+            // Treat as cache miss and refetch to avoid IllegalStateException 
during subsequent lookups.
+            if (entry.isMarkedForCleanup()) {
+                log.debug("Entry for segment {} is marked for cleanup, 
invalidating and refetching", uuid);
+                refetchAfterEvictionCount.incrementAndGet();
+                internalCache.invalidate(uuid);

Review Comment:
   Do you think it'd be better we invalidate the cache when `evictionListener` 
is invoked? After all, when this listener is triggered, it means this cache is 
not valid anymore.



##########
storage/src/main/java/org/apache/kafka/storage/internals/log/RemoteIndexCache.java:
##########
@@ -98,6 +106,8 @@ public class RemoteIndexCache implements Closeable {
     private final RemoteStorageManager remoteStorageManager;
     private final KafkaScheduler cleanerScheduler = new KafkaScheduler(1, 
true, REMOTE_LOG_INDEX_CACHE_CLEANER_THREAD);
     private int fileDeleteDelayMs = 10_000;
+    private final KafkaMetricsGroup metricsGroup = new 
KafkaMetricsGroup("kafka.log.remote", "RemoteIndexCache");

Review Comment:
   Please remove the new metrics addition in this PR and go through the KIP 
process first. Let's focus on the bug fix on this PR only. Thanks.



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