Skip to content

Commit

Permalink
Hide overflow protection behind setting
Browse files Browse the repository at this point in the history
Signed-off-by: Finn Carroll <[email protected]>
  • Loading branch information
finnegancarroll committed Aug 14, 2024
1 parent 400802a commit 6d2f104
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class FileCache implements RefCountedCache<Path, CachedIndexInput> {
private final SegmentedCache<Path, CachedIndexInput> theCache;

private final CircuitBreaker circuitBreaker;
private boolean allowOverflow = true;
private boolean enableOverflow = true;

public FileCache(SegmentedCache<Path, CachedIndexInput> cache, CircuitBreaker circuitBreaker) {
this.theCache = cache;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion server/src/main/java/org/opensearch/node/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -2083,7 +2083,7 @@ private void initializeFileCache(Settings settings, CircuitBreaker circuitBreake
fileCacheNodePath.fileCacheReservedSize = new ByteSizeValue(this.fileCache.capacity(), ByteSizeUnit.BYTES);
List<Path> 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) {
Expand Down

0 comments on commit 6d2f104

Please sign in to comment.