Skip to content

Commit 558e68a

Browse files
committed
Review feedback
1 parent d69d468 commit 558e68a

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/index/store/BaseSearchableSnapshotIndexInput.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,21 @@ public BaseSearchableSnapshotIndexInput(
4545

4646
protected InputStream openInputStream(final long position, final long length) throws IOException {
4747
assert assertCurrentThreadMayAccessBlobStore();
48-
final long startPart = getPartNumberForPosition(position);
49-
final long endPart = getPartNumberForPosition(position + length);
50-
if ((startPart == endPart) || fileInfo.numberOfParts() == 1L) {
51-
return blobContainer.readBlob(fileInfo.partName(startPart), getRelativePositionInPart(position), length);
48+
if (fileInfo.numberOfParts() == 1L) {
49+
assert position + length <= fileInfo.partBytes(0)
50+
: "cannot read [" + position + "-" + (position + length) + "] from [" + fileInfo + "]";
51+
return blobContainer.readBlob(fileInfo.partName(0L), position, length);
5252
} else {
53+
final long startPart = getPartNumberForPosition(position);
54+
final long endPart = getPartNumberForPosition(position + length);
5355
return new SlicedInputStream(endPart - startPart + 1L) {
5456
@Override
5557
protected InputStream openSlice(long slice) throws IOException {
5658
final long currentPart = startPart + slice;
5759
final long startInPart = (currentPart == startPart) ? getRelativePositionInPart(position) : 0L;
5860
final long endInPart
5961
= (currentPart == endPart) ? getRelativePositionInPart(position + length) : getLengthOfPart(currentPart);
60-
return blobContainer.readBlob(
61-
fileInfo.partName(currentPart),
62-
startInPart,
63-
endInPart - startInPart
64-
);
62+
return blobContainer.readBlob(fileInfo.partName(currentPart), startInPart, endInPart - startInPart);
6563
}
6664
};
6765
}

0 commit comments

Comments
 (0)