1515import org .opensearch .index .store .remote .filecache .CachedIndexInput ;
1616import org .opensearch .index .store .remote .filecache .FileCache ;
1717import org .opensearch .index .store .remote .filecache .FileCachedIndexInput ;
18- import org .opensearch .index .store .remote .utils .cache .CacheUsage ;
1918
2019import java .io .BufferedOutputStream ;
2120import java .io .IOException ;
2928import java .util .concurrent .CompletableFuture ;
3029import java .util .concurrent .CompletionException ;
3130import java .util .concurrent .atomic .AtomicBoolean ;
31+ import java .util .function .Supplier ;
3232
3333/**
3434 * This acts as entry point to fetch {@link BlobFetchRequest} and return actual {@link IndexInput}. Utilizes the BlobContainer interface to
@@ -99,7 +99,10 @@ private static FileCachedIndexInput createIndexInput(FileCache fileCache, Stream
9999 // This local file cache is ref counted and may not strictly enforce capacity.
100100 // In our use case capacity directly relates to disk usage.
101101 // If we find available capacity is exceeded deny further BlobFetchRequests.
102- if (fileCache .usage ().usage () > fileCache .capacity ()) {
102+ Supplier <Short > cacheUsagePerc = () ->
103+ fileCache .capacity () <= 0 ? 0 : (short ) (Math .round ((100d * fileCache .usage ().usage ()) / fileCache .capacity ()));
104+
105+ if (cacheUsagePerc .get () >= 99 ) {
103106 System .gc ();
104107
105108 // File reference cleanup is not immediate and is processed
@@ -111,7 +114,7 @@ private static FileCachedIndexInput createIndexInput(FileCache fileCache, Stream
111114 }
112115
113116 fileCache .prune ();
114- if (fileCache . usage (). usage () > fileCache . capacity () ) {
117+ if (cacheUsagePerc . get () >= 99 ) {
115118 throw new IOException ("Local file cache capacity exceeded - BlobFetchRequest failed: " + request .getFilePath ());
116119 }
117120 }
0 commit comments