From 5e26dfe768be08e6fc6087a66a451c206fdb9fef Mon Sep 17 00:00:00 2001 From: Finn Carroll Date: Mon, 22 Jul 2024 14:29:16 -0700 Subject: [PATCH 1/2] Surface OnDemandBlockIndexInput blockSizeShift to RemoteSnapshotDirectory constructor Signed-off-by: Finn Carroll --- .../directory/RemoteSnapshotDirectory.java | 34 +++++++++++++++++-- .../remote/file/OnDemandBlockIndexInput.java | 4 +-- .../file/OnDemandBlockSnapshotIndexInput.java | 2 +- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/server/src/main/java/org/opensearch/index/store/remote/directory/RemoteSnapshotDirectory.java b/server/src/main/java/org/opensearch/index/store/remote/directory/RemoteSnapshotDirectory.java index 19ecee67bdb96..cddf4c509b9d1 100644 --- a/server/src/main/java/org/opensearch/index/store/remote/directory/RemoteSnapshotDirectory.java +++ b/server/src/main/java/org/opensearch/index/store/remote/directory/RemoteSnapshotDirectory.java @@ -39,13 +39,24 @@ public final class RemoteSnapshotDirectory extends Directory { public static final Version SEARCHABLE_SNAPSHOT_EXTENDED_COMPATIBILITY_MINIMUM_VERSION = LegacyESVersion.V_6_0_0; - private static final String VIRTUAL_FILE_PREFIX = BlobStoreRepository.VIRTUAL_DATA_BLOB_PREFIX; + private static final int ON_DEMAND_DEFAULT_BLOCK_SIZE_SHIFT = 21; private final Map fileInfoMap; private final FSDirectory localStoreDir; private final TransferManager transferManager; + private int onDemandBlockSizeShift = ON_DEMAND_DEFAULT_BLOCK_SIZE_SHIFT; + + public RemoteSnapshotDirectory(BlobStoreIndexShardSnapshot snapshot, FSDirectory localStoreDir, TransferManager transferManager, int onDemandBlockSizeShift) { + this( + snapshot, + localStoreDir, + transferManager + ); + this.onDemandBlockSizeShift = onDemandBlockSizeShift; + } + public RemoteSnapshotDirectory(BlobStoreIndexShardSnapshot snapshot, FSDirectory localStoreDir, TransferManager transferManager) { this.fileInfoMap = snapshot.indexFiles() .stream() @@ -74,7 +85,26 @@ public IndexInput openInput(String name, IOContext context) throws IOException { if (fileInfo.name().startsWith(VIRTUAL_FILE_PREFIX)) { return new ByteArrayIndexInput(fileInfo.physicalName(), fileInfo.metadata().hash().bytes); } - return new OnDemandBlockSnapshotIndexInput(fileInfo, localStoreDir, transferManager); + + String resourceDescription = "BlockedSnapshotIndexInput(path=\"" + + localStoreDir.getDirectory().toString() + + "/" + + fileInfo.physicalName() + + "\", " + + "offset=" + + 0 + + ", length= " + + fileInfo.length() + + ")"; + + OnDemandBlockSnapshotIndexInput.Builder blockIndexInputBuilder = new OnDemandBlockSnapshotIndexInput.Builder() + .resourceDescription(resourceDescription) + .isClone(false) + .offset(0L) + .length(fileInfo.length()) + .blockSizeShift(this.onDemandBlockSizeShift); + + return new OnDemandBlockSnapshotIndexInput(blockIndexInputBuilder, fileInfo, localStoreDir, transferManager); } @Override diff --git a/server/src/main/java/org/opensearch/index/store/remote/file/OnDemandBlockIndexInput.java b/server/src/main/java/org/opensearch/index/store/remote/file/OnDemandBlockIndexInput.java index 6fd198747570f..b1865f0667a8b 100644 --- a/server/src/main/java/org/opensearch/index/store/remote/file/OnDemandBlockIndexInput.java +++ b/server/src/main/java/org/opensearch/index/store/remote/file/OnDemandBlockIndexInput.java @@ -385,7 +385,7 @@ public static class Builder { private int blockSize = 1 << blockSizeShift; private int blockMask = blockSize - 1; - private Builder() {} + public Builder() {} public Builder resourceDescription(String resourceDescription) { this.resourceDescription = resourceDescription; @@ -407,7 +407,7 @@ public Builder length(long length) { return this; } - Builder blockSizeShift(int blockSizeShift) { + public Builder blockSizeShift(int blockSizeShift) { assert blockSizeShift < 31 : "blockSizeShift must be < 31"; this.blockSizeShift = blockSizeShift; this.blockSize = 1 << blockSizeShift; diff --git a/server/src/main/java/org/opensearch/index/store/remote/file/OnDemandBlockSnapshotIndexInput.java b/server/src/main/java/org/opensearch/index/store/remote/file/OnDemandBlockSnapshotIndexInput.java index ad56127394779..0462955ff2990 100644 --- a/server/src/main/java/org/opensearch/index/store/remote/file/OnDemandBlockSnapshotIndexInput.java +++ b/server/src/main/java/org/opensearch/index/store/remote/file/OnDemandBlockSnapshotIndexInput.java @@ -96,7 +96,7 @@ public OnDemandBlockSnapshotIndexInput( ); } - OnDemandBlockSnapshotIndexInput( + public OnDemandBlockSnapshotIndexInput( OnDemandBlockIndexInput.Builder builder, FileInfo fileInfo, FSDirectory directory, From a04ea2734a52623cc622ba96416f03988dd40586 Mon Sep 17 00:00:00 2001 From: Finn Carroll Date: Tue, 23 Jul 2024 12:07:35 -0700 Subject: [PATCH 2/2] Add block size setting to file_cache Signed-off-by: Finn Carroll --- .../store/remote/filecache/FileCacheSettings.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/server/src/main/java/org/opensearch/index/store/remote/filecache/FileCacheSettings.java b/server/src/main/java/org/opensearch/index/store/remote/filecache/FileCacheSettings.java index 76086be932ecb..0dea862df66bc 100644 --- a/server/src/main/java/org/opensearch/index/store/remote/filecache/FileCacheSettings.java +++ b/server/src/main/java/org/opensearch/index/store/remote/filecache/FileCacheSettings.java @@ -33,6 +33,20 @@ public class FileCacheSettings { Setting.Property.Dynamic ); + /** + * The size in bytes of blocks downloaded from the remote store into local file cache to service requests. + * Note that almost always the full block is downloaded, regardless of how much data from the block is actually + * required for an operation. + */ + public static final Setting FILE_CACHE_LOCAL_BLOCK_SHIFT_SETTING = Setting.intSetting( + "cluster.filecache.block_shift", + 23, + 10, + 30, + Setting.Property.NodeScope, + Setting.Property.Dynamic + ); + private volatile double remoteDataRatio; public FileCacheSettings(Settings settings, ClusterSettings clusterSettings) {