Skip to content

Commit 6f86ed4

Browse files
Change cache limit to 99% capacity
Signed-off-by: Finn Carroll <[email protected]>
1 parent 9b494b6 commit 6f86ed4

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

server/src/main/java/org/opensearch/index/store/remote/utils/TransferManager.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import org.opensearch.index.store.remote.filecache.CachedIndexInput;
1616
import org.opensearch.index.store.remote.filecache.FileCache;
1717
import org.opensearch.index.store.remote.filecache.FileCachedIndexInput;
18-
import org.opensearch.index.store.remote.utils.cache.CacheUsage;
1918

2019
import java.io.BufferedOutputStream;
2120
import java.io.IOException;
@@ -29,6 +28,7 @@
2928
import java.util.concurrent.CompletableFuture;
3029
import java.util.concurrent.CompletionException;
3130
import 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

Comments
 (0)