Skip to content

Commit

Permalink
Change cache limit to 99% capacity
Browse files Browse the repository at this point in the history
Signed-off-by: Finn Carroll <carrofin@amazon.com>
  • Loading branch information
finnegancarroll committed Aug 3, 2024
1 parent 9b494b6 commit 6f86ed4
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.opensearch.index.store.remote.filecache.CachedIndexInput;
import org.opensearch.index.store.remote.filecache.FileCache;
import org.opensearch.index.store.remote.filecache.FileCachedIndexInput;
import org.opensearch.index.store.remote.utils.cache.CacheUsage;

import java.io.BufferedOutputStream;
import java.io.IOException;
Expand All @@ -29,6 +28,7 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Supplier;

/**
* This acts as entry point to fetch {@link BlobFetchRequest} and return actual {@link IndexInput}. Utilizes the BlobContainer interface to
Expand Down Expand Up @@ -99,7 +99,10 @@ private static FileCachedIndexInput createIndexInput(FileCache fileCache, Stream
// This local file cache is ref counted and may not strictly enforce capacity.
// In our use case capacity directly relates to disk usage.
// If we find available capacity is exceeded deny further BlobFetchRequests.
if (fileCache.usage().usage() > fileCache.capacity()) {
Supplier<Short> cacheUsagePerc = () ->
fileCache.capacity() <= 0 ? 0 : (short) (Math.round((100d * fileCache.usage().usage()) / fileCache.capacity()));

if (cacheUsagePerc.get() >= 99) {
System.gc();

// File reference cleanup is not immediate and is processed
Expand All @@ -111,7 +114,7 @@ private static FileCachedIndexInput createIndexInput(FileCache fileCache, Stream
}

fileCache.prune();
if (fileCache.usage().usage() > fileCache.capacity()) {
if (cacheUsagePerc.get() >= 99) {
throw new IOException("Local file cache capacity exceeded - BlobFetchRequest failed: " + request.getFilePath());
}
}
Expand Down

0 comments on commit 6f86ed4

Please sign in to comment.