This is an automated email from the ASF dual-hosted git repository.
jojochuang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git
The following commit(s) were added to refs/heads/master by this push:
new d3b5f518556 HDDS-17111. OFS and O3FS getFileBlockLocations ignore
start and len (#11614)
d3b5f518556 is described below
commit d3b5f5185567967423403abd91495ddee4d938cb
Author: Siyao Meng <[email protected]>
AuthorDate: Wed Oct 21 10:00:25 2026 -0700
HDDS-17111. OFS and O3FS getFileBlockLocations ignore start and len (#11614)
Generated-by: Claude Opus 5.5 (1M context) <[email protected]>
---
.../hadoop/fs/ozone/BasicOzoneFileSystem.java | 19 +++++++++++++++-
.../fs/ozone/BasicRootedOzoneFileSystem.java | 2 +-
.../hadoop/fs/ozone/TestBasicOzoneFileSystems.java | 25 ++++++++++++++++++++++
3 files changed, 44 insertions(+), 2 deletions(-)
diff --git
a/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/BasicOzoneFileSystem.java
b/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/BasicOzoneFileSystem.java
index 8c6a38afb96..bc429016118 100644
---
a/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/BasicOzoneFileSystem.java
+++
b/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/BasicOzoneFileSystem.java
@@ -41,6 +41,7 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.EnumSet;
import java.util.Iterator;
@@ -888,12 +889,28 @@ public BlockLocation[] getFileBlockLocations(FileStatus
fileStatus,
long start, long len)
throws IOException {
if (fileStatus instanceof LocatedFileStatus) {
- return ((LocatedFileStatus) fileStatus).getBlockLocations();
+ return getBlockLocationsInRange((LocatedFileStatus) fileStatus, start,
len);
} else {
return super.getFileBlockLocations(fileStatus, start, len);
}
}
+ /**
+ * Like HDFS, return only the blocks that overlap [start, start + len), or
the block containing start if len is 0.
+ */
+ static BlockLocation[] getBlockLocationsInRange(LocatedFileStatus
fileStatus, long start, long len) {
+ if (start < 0 || len < 0) {
+ throw new IllegalArgumentException("Invalid start or len parameter");
+ }
+ BlockLocation[] blocks = fileStatus.getBlockLocations();
+ if (blocks == null) {
+ return null;
+ }
+ return Arrays.stream(blocks)
+ .filter(b -> b.getOffset() + b.getLength() > start && b.getOffset() -
start < Math.max(len, 1))
+ .toArray(BlockLocation[]::new);
+ }
+
@Override
public ContentSummary getContentSummary(Path f) throws IOException {
Path qualifiedPath = f.makeQualified(uri, workingDir);
diff --git
a/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/BasicRootedOzoneFileSystem.java
b/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/BasicRootedOzoneFileSystem.java
index bb5a0826d3e..53c521b972d 100644
---
a/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/BasicRootedOzoneFileSystem.java
+++
b/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/BasicRootedOzoneFileSystem.java
@@ -1130,7 +1130,7 @@ public BlockLocation[] getFileBlockLocations(FileStatus
fileStatus,
long start, long len)
throws IOException {
if (fileStatus instanceof LocatedFileStatus) {
- return ((LocatedFileStatus) fileStatus).getBlockLocations();
+ return BasicOzoneFileSystem.getBlockLocationsInRange((LocatedFileStatus)
fileStatus, start, len);
} else {
return super.getFileBlockLocations(fileStatus, start, len);
}
diff --git
a/hadoop-ozone/ozonefs-common/src/test/java/org/apache/hadoop/fs/ozone/TestBasicOzoneFileSystems.java
b/hadoop-ozone/ozonefs-common/src/test/java/org/apache/hadoop/fs/ozone/TestBasicOzoneFileSystems.java
index f9e9ebfc6da..30f42bfee97 100644
---
a/hadoop-ozone/ozonefs-common/src/test/java/org/apache/hadoop/fs/ozone/TestBasicOzoneFileSystems.java
+++
b/hadoop-ozone/ozonefs-common/src/test/java/org/apache/hadoop/fs/ozone/TestBasicOzoneFileSystems.java
@@ -20,6 +20,7 @@
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_SCM_BLOCK_SIZE;
import static
org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_SCM_BLOCK_SIZE_DEFAULT;
import static org.apache.hadoop.ozone.OzoneConsts.OM_SNAPSHOT_INDICATOR;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -44,7 +45,10 @@
import java.util.Arrays;
import java.util.Collection;
import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.BlockLocation;
+import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.LocatedFileStatus;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.conf.StorageSize;
@@ -291,6 +295,27 @@ public void testRootedAuthorityRejectsOutOfRangePort() {
() -> ofs.initialize(new URI("ofs://host:99999/"), new
OzoneConfiguration()));
}
+ @ParameterizedTest(autoCloseArguments = false)
+ @MethodSource("data")
+ public void fileBlockLocationsHonorRange(FileSystem subject) throws
IOException {
+ BlockLocation[] blocks = {
+ new BlockLocation(null, null, 0, 100),
+ new BlockLocation(null, null, 100, 100),
+ new BlockLocation(null, null, 200, 50),
+ };
+ LocatedFileStatus status = new LocatedFileStatus(new FileStatus(250,
false, 3, 100, 0, new Path("/f")), blocks);
+
+ assertThat(subject.getFileBlockLocations(status, 0,
250)).containsExactly(blocks);
+ assertThat(subject.getFileBlockLocations(status, 0,
Long.MAX_VALUE)).containsExactly(blocks);
+ assertThat(subject.getFileBlockLocations(status, 150,
Long.MAX_VALUE)).containsExactly(blocks[1], blocks[2]);
+ assertThat(subject.getFileBlockLocations(status, 99,
2)).containsExactly(blocks[0], blocks[1]);
+ assertThat(subject.getFileBlockLocations(status, 100,
100)).containsExactly(blocks[1]);
+ assertThat(subject.getFileBlockLocations(status, 120,
0)).containsExactly(blocks[1]);
+ assertThat(subject.getFileBlockLocations(status, 250, 10)).isEmpty();
+ assertThrows(IllegalArgumentException.class, () ->
subject.getFileBlockLocations(status, -1, 10));
+ assertThrows(IllegalArgumentException.class, () ->
subject.getFileBlockLocations(status, 0, -1));
+ }
+
private void assertDefaultBlockSize(long expected, FileSystem subject) {
assertEquals(expected, subject.getDefaultBlockSize());
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]