Skip to content

Commit

Permalink
Surface OnDemandBlockIndexInput blockSizeShift to RemoteSnapshotDirec…
Browse files Browse the repository at this point in the history
…tory constructor

Signed-off-by: Finn Carroll <[email protected]>
  • Loading branch information
finnegancarroll committed Jul 22, 2024
1 parent b35690c commit 5e26dfe
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, BlobStoreIndexShardSnapshot.FileInfo> 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()
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public OnDemandBlockSnapshotIndexInput(
);
}

OnDemandBlockSnapshotIndexInput(
public OnDemandBlockSnapshotIndexInput(
OnDemandBlockIndexInput.Builder builder,
FileInfo fileInfo,
FSDirectory directory,
Expand Down

0 comments on commit 5e26dfe

Please sign in to comment.