Skip to content

Commit 762c70b

Browse files
authored
Implement range reads in HDFS repository (opensearch-project#9524)
Resolves opensearch-project#9513 Signed-off-by: Andrew Ross <andrross@amazon.com>
1 parent 4e68808 commit 762c70b

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
8989
- [BWC and API enforcement] Define the initial set of annotations, their meaning and relations between them ([#9223](https://github.com/opensearch-project/OpenSearch/pull/9223))
9090
- [Segment Replication] Support realtime reads for GET requests ([#9212](https://github.com/opensearch-project/OpenSearch/pull/9212))
9191
- [Feature] Expose term frequency in Painless script score context ([#9081](https://github.com/opensearch-project/OpenSearch/pull/9081))
92+
- Add support for reading partial files to HDFS repository ([#9513](https://github.com/opensearch-project/OpenSearch/issues/9513))
9293

9394
### Dependencies
9495
- Bump `org.apache.logging.log4j:log4j-core` from 2.17.1 to 2.20.0 ([#8307](https://github.com/opensearch-project/OpenSearch/pull/8307))

plugins/repository-hdfs/src/main/java/org/opensearch/repositories/hdfs/HdfsBlobContainer.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
package org.opensearch.repositories.hdfs;
3333

3434
import org.apache.hadoop.fs.CreateFlag;
35+
import org.apache.hadoop.fs.FSDataInputStream;
3536
import org.apache.hadoop.fs.FSDataOutputStream;
3637
import org.apache.hadoop.fs.FileContext;
3738
import org.apache.hadoop.fs.FileStatus;
@@ -46,6 +47,7 @@
4647
import org.opensearch.common.blobstore.fs.FsBlobContainer;
4748
import org.opensearch.common.blobstore.support.AbstractBlobContainer;
4849
import org.opensearch.common.blobstore.support.PlainBlobMetadata;
50+
import org.opensearch.common.io.Streams;
4951
import org.opensearch.repositories.hdfs.HdfsBlobStore.Operation;
5052

5153
import java.io.FileNotFoundException;
@@ -125,8 +127,23 @@ public InputStream readBlob(String blobName) throws IOException {
125127
}
126128

127129
@Override
128-
public InputStream readBlob(String blobName, long position, long length) {
129-
throw new UnsupportedOperationException();
130+
public InputStream readBlob(String blobName, long position, long length) throws IOException {
131+
return store.execute(fileContext -> {
132+
final FSDataInputStream stream;
133+
try {
134+
stream = fileContext.open(new Path(path, blobName), bufferSize);
135+
} catch (FileNotFoundException fnfe) {
136+
throw new NoSuchFileException("[" + blobName + "] blob not found");
137+
}
138+
// Seek to the desired start position, closing the stream if any error occurs
139+
try {
140+
stream.seek(position);
141+
} catch (Exception e) {
142+
stream.close();
143+
throw e;
144+
}
145+
return Streams.limitStream(new HDFSPrivilegedInputSteam(stream, securityContext), length);
146+
});
130147
}
131148

132149
@Override

plugins/repository-hdfs/src/test/java/org/opensearch/repositories/hdfs/HdfsBlobStoreRepositoryTests.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,4 @@ protected Settings repositorySettings() {
6666
protected Collection<Class<? extends Plugin>> nodePlugins() {
6767
return Collections.singletonList(HdfsPlugin.class);
6868
}
69-
70-
@AwaitsFix(bugUrl = "https://github.com/opensearch-project/OpenSearch/issues/9513")
71-
@Override
72-
public void testReadRange() {}
7369
}

0 commit comments

Comments
 (0)