This is an automated email from the ASF dual-hosted git repository.

junrao pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/kafka.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 6437135bc08 KAFKA-19451: fix flaky test 
RemoteIndexCacheTest.testCacheEntryIsDeletedOnRemoval() (#20085)
6437135bc08 is described below

commit 6437135bc08468a0849ae2225c731483a220e9e2
Author: Lan Ding <[email protected]>
AuthorDate: Tue Jul 15 03:01:50 2025 +0800

    KAFKA-19451: fix flaky test 
RemoteIndexCacheTest.testCacheEntryIsDeletedOnRemoval() (#20085)
    
    **Problem Description**
    In the `RemoteIndexCache.cleanup()` method, the asynchronous invocation
    of `index.deleteIfExists()` may cause a conflict. When the
    `getIndexFileFromRemoteCacheDir()` method is executed, it utilizes
    `Files.walk()` to traverse all files in the directory path. If
    `index.deleteIfExists()` is triggered during this traversal, a
    `NoSuchFileException` will be thrown.
    
    **Solution**
    To resolve this issue, ensure that `index.deleteIfExists()` has been
    fully executed before invoking `getIndexFileFromRemoteCacheDir()`.
    
    Reviewers: Jun Rao <[email protected]>
---
 .../kafka/storage/internals/log/RemoteIndexCacheTest.java    | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git 
a/storage/src/test/java/org/apache/kafka/storage/internals/log/RemoteIndexCacheTest.java
 
b/storage/src/test/java/org/apache/kafka/storage/internals/log/RemoteIndexCacheTest.java
index b1480d36775..6111cb783a4 100644
--- 
a/storage/src/test/java/org/apache/kafka/storage/internals/log/RemoteIndexCacheTest.java
+++ 
b/storage/src/test/java/org/apache/kafka/storage/internals/log/RemoteIndexCacheTest.java
@@ -331,6 +331,18 @@ public class RemoteIndexCacheTest {
         verify(cacheEntry.offsetIndex()).renameTo(any(File.class));
         verify(cacheEntry.txnIndex()).renameTo(any(File.class));
 
+        // wait until the delete method is invoked
+        TestUtils.waitForCondition(() -> {
+            try {
+                verify(cacheEntry.timeIndex()).deleteIfExists();
+                verify(cacheEntry.offsetIndex()).deleteIfExists();
+                verify(cacheEntry.txnIndex()).deleteIfExists();
+                return true;
+            } catch (Exception e) {
+                return false;
+            }
+        }, "Failed to delete index file");
+
         // verify no index files on disk
         assertFalse(getIndexFileFromRemoteCacheDir(cache, 
LogFileUtils.INDEX_FILE_SUFFIX).isPresent(),
                 "Offset index file should not be present on disk at " + 
tpDir.toPath());

Reply via email to