Skip to content

Commit 9b494b6

Browse files
Mitigation for overflowed filecache
Signed-off-by: Finn Carroll <[email protected]>
1 parent 59302a3 commit 9b494b6

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
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;
1819

1920
import java.io.BufferedOutputStream;
2021
import java.io.IOException;
@@ -95,6 +96,25 @@ public IndexInput fetchBlob(BlobFetchRequest blobFetchRequest) throws IOExceptio
9596
@SuppressWarnings("removal")
9697
private static FileCachedIndexInput createIndexInput(FileCache fileCache, StreamReader streamReader, BlobFetchRequest request) {
9798
try {
99+
// This local file cache is ref counted and may not strictly enforce capacity.
100+
// In our use case capacity directly relates to disk usage.
101+
// If we find available capacity is exceeded deny further BlobFetchRequests.
102+
if (fileCache.usage().usage() > fileCache.capacity()) {
103+
System.gc();
104+
105+
// File reference cleanup is not immediate and is processed
106+
// in a dedicated thread.
107+
try {
108+
Thread.sleep(10);
109+
} catch (InterruptedException e) {
110+
Thread.currentThread().interrupt();
111+
}
112+
113+
fileCache.prune();
114+
if (fileCache.usage().usage() > fileCache.capacity()) {
115+
throw new IOException("Local file cache capacity exceeded - BlobFetchRequest failed: " + request.getFilePath());
116+
}
117+
}
98118
if (Files.exists(request.getFilePath()) == false) {
99119
logger.trace("Fetching from Remote in createIndexInput of Transfer Manager");
100120
try (

0 commit comments

Comments
 (0)