nandini12396 commented on code in PR #21088:
URL: https://github.com/apache/kafka/pull/21088#discussion_r2618832041
##########
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:
I'm not sure. It is possible that a thread already may have a reference to
the entry from a previous `getIndexEntry()` call before the evictionListener is
invoked so it will still throw the exception.
--
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]