From 6d2f104f94063b9abe6a8190574958c3ebe1556d Mon Sep 17 00:00:00 2001 From: Finn Carroll Date: Tue, 6 Aug 2024 22:27:03 +0000 Subject: [PATCH] Hide overflow protection behind setting Signed-off-by: Finn Carroll --- .../index/store/remote/filecache/FileCache.java | 10 +++++++++- .../index/store/remote/utils/TransferManager.java | 2 +- server/src/main/java/org/opensearch/node/Node.java | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/org/opensearch/index/store/remote/filecache/FileCache.java b/server/src/main/java/org/opensearch/index/store/remote/filecache/FileCache.java index 219ed2efa6473..12cf1241e83d2 100644 --- a/server/src/main/java/org/opensearch/index/store/remote/filecache/FileCache.java +++ b/server/src/main/java/org/opensearch/index/store/remote/filecache/FileCache.java @@ -53,7 +53,7 @@ public class FileCache implements RefCountedCache { private final SegmentedCache theCache; private final CircuitBreaker circuitBreaker; - private boolean allowOverflow = true; + private boolean enableOverflow = true; public FileCache(SegmentedCache cache, CircuitBreaker circuitBreaker) { this.theCache = cache; @@ -64,6 +64,14 @@ public long capacity() { return theCache.capacity(); } + public void enableOverflow(boolean enable) { + this.enableOverflow = enable; + } + + public boolean canOverflow() { + return enableOverflow; + } + @Override public CachedIndexInput put(Path filePath, CachedIndexInput indexInput) { CachedIndexInput cachedIndexInput = theCache.put(filePath, indexInput); diff --git a/server/src/main/java/org/opensearch/index/store/remote/utils/TransferManager.java b/server/src/main/java/org/opensearch/index/store/remote/utils/TransferManager.java index 5dfc613e6c437..11b7f752559f0 100644 --- a/server/src/main/java/org/opensearch/index/store/remote/utils/TransferManager.java +++ b/server/src/main/java/org/opensearch/index/store/remote/utils/TransferManager.java @@ -98,7 +98,7 @@ private static FileCachedIndexInput createIndexInput(FileCache fileCache, Stream try { // This local file cache is ref counted and may not strictly enforce configured capacity. // If we find available capacity is exceeded, deny further BlobFetchRequests. - if (fileCache.capacity() < fileCache.usage().usage() + request.getBlobLength()) { + if (fileCache.capacity() < fileCache.usage().usage() + request.getBlobLength() && !fileCache.canOverflow()) { throw new IOException("Local file cache capacity exceeded - BlobFetchRequest failed: " + request.getFilePath()); } if (Files.exists(request.getFilePath()) == false) { diff --git a/server/src/main/java/org/opensearch/node/Node.java b/server/src/main/java/org/opensearch/node/Node.java index c9cfc3c860a79..a7b00ac7b2341 100644 --- a/server/src/main/java/org/opensearch/node/Node.java +++ b/server/src/main/java/org/opensearch/node/Node.java @@ -2083,7 +2083,7 @@ private void initializeFileCache(Settings settings, CircuitBreaker circuitBreake fileCacheNodePath.fileCacheReservedSize = new ByteSizeValue(this.fileCache.capacity(), ByteSizeUnit.BYTES); List fileCacheDataPaths = collectFileCacheDataPath(fileCacheNodePath); this.fileCache.restoreFromDirectory(fileCacheDataPaths); -// this.fileCache.overflowEnabled(NODE_SEARCH_CACHE_SIZE_SETTING.get(settings)); + this.fileCache.enableOverflow(NODE_SEARCH_CACHE_OVERFLOW_SETTING.get(settings)); } private static long calculateFileCacheSize(String capacityRaw, long totalSpace) {