This is an automated email from the ASF dual-hosted git repository.
adoroszlai 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 f0ba16b0d37 HDDS-14161. getBlockLocations returns null for zero-byte
files (#9491)
f0ba16b0d37 is described below
commit f0ba16b0d37575c5c3e6bedd8dcc0f9f17ceb624
Author: Jayer <[email protected]>
AuthorDate: Tue Dec 16 16:34:30 2025 +0800
HDDS-14161. getBlockLocations returns null for zero-byte files (#9491)
---
.../fs/ozone/AbstractOzoneFileSystemTest.java | 9 ++++++
.../ozone/AbstractRootedOzoneFileSystemTest.java | 13 ++++++++
.../hadoop/fs/ozone/OzoneFileSystemTests.java | 37 ++++++++++++++++++++++
.../hadoop/fs/ozone/BasicOzoneFileSystem.java | 3 +-
.../fs/ozone/BasicRootedOzoneFileSystem.java | 3 +-
5 files changed, 63 insertions(+), 2 deletions(-)
diff --git
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/AbstractOzoneFileSystemTest.java
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/AbstractOzoneFileSystemTest.java
index 836be109a90..4a4d744446c 100644
---
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/AbstractOzoneFileSystemTest.java
+++
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/AbstractOzoneFileSystemTest.java
@@ -2143,6 +2143,15 @@ public void
testOzoneManagerListLocatedStatusAndListStatus() throws IOException
assertFalse(fileStatuses[0] instanceof LocatedFileStatus);
}
+ @Test
+ public void testOzoneManagerListLocatedStatusForZeroByteFile() throws
IOException {
+ String directory = RandomStringUtils.secure().nextAlphanumeric(5);
+ String filePath = RandomStringUtils.secure().nextAlphanumeric(5);
+ Path path = createPath("/" + directory + "/" + filePath);
+
+ OzoneFileSystemTests.listLocatedStatusForZeroByteFile(fs, path);
+ }
+
@Test
void testOzoneManagerFileSystemInterface() throws IOException {
String dirPath = RandomStringUtils.secure().nextAlphanumeric(5);
diff --git
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/AbstractRootedOzoneFileSystemTest.java
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/AbstractRootedOzoneFileSystemTest.java
index d704130e101..c41139bdd8d 100644
---
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/AbstractRootedOzoneFileSystemTest.java
+++
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/AbstractRootedOzoneFileSystemTest.java
@@ -404,6 +404,19 @@ void testDeleteCreatesFakeParentDir() throws Exception {
assertTrue(fs.delete(grandparent, true));
}
+ @Test
+ void testListLocatedStatusForZeroByteFile() throws Exception {
+ Path parent = new Path(bucketPath, "testListLocatedStatusForZeroByteFile");
+ Path path = new Path(parent, "key1");
+
+ try {
+ OzoneFileSystemTests.listLocatedStatusForZeroByteFile(fs, path);
+ } finally {
+ // Cleanup
+ fs.delete(parent, true);
+ }
+ }
+
@Test
void testListStatus() throws Exception {
Path parent = new Path(bucketPath, "testListStatus");
diff --git
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/OzoneFileSystemTests.java
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/OzoneFileSystemTests.java
index 02e81f333e0..b4fa56fc79f 100644
---
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/OzoneFileSystemTests.java
+++
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/OzoneFileSystemTests.java
@@ -24,14 +24,18 @@
import static org.apache.hadoop.ozone.OzoneConsts.OZONE_URI_SCHEME;
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.assertNotNull;
import java.io.IOException;
import java.net.URI;
import java.util.Objects;
import java.util.Set;
import java.util.TreeSet;
+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.fs.RemoteIterator;
import org.apache.hadoop.fs.contract.ContractTestUtils;
@@ -125,4 +129,37 @@ static void
createKeyWithECReplicationConfiguration(OzoneConfiguration inputConf
ContractTestUtils.touch(fileSystem, keyPath);
}
}
+
+ public static void listLocatedStatusForZeroByteFile(FileSystem fs, Path
path) throws IOException {
+ // create empty file
+ ContractTestUtils.touch(fs, path);
+
+ RemoteIterator<LocatedFileStatus> listLocatedStatus =
fs.listLocatedStatus(path);
+ int count = 0;
+
+ while (listLocatedStatus.hasNext()) {
+ LocatedFileStatus locatedFileStatus = listLocatedStatus.next();
+ assertEquals(0, locatedFileStatus.getLen());
+ BlockLocation[] blockLocations = locatedFileStatus.getBlockLocations();
+ assertNotNull(blockLocations);
+ assertEquals(0, blockLocations.length);
+
+ count++;
+ }
+ assertEquals(1, count);
+
+ count = 0;
+ RemoteIterator<FileStatus> listStatus = fs.listStatusIterator(path);
+ while (listStatus.hasNext()) {
+ FileStatus fileStatus = listStatus.next();
+ assertEquals(0, fileStatus.getLen());
+ assertFalse(fileStatus instanceof LocatedFileStatus);
+ count++;
+ }
+ assertEquals(1, count);
+
+ FileStatus[] fileStatuses = fs.listStatus(path.getParent());
+ assertEquals(1, fileStatuses.length);
+ assertFalse(fileStatuses[0] instanceof LocatedFileStatus);
+ }
}
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 93ab78dccf9..add21c3f8bb 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
@@ -954,7 +954,8 @@ public RemoteIterator<LocatedFileStatus>
listLocatedStatus(Path f)
throws IOException {
incrementCounter(Statistic.INVOCATION_LIST_LOCATED_STATUS);
return new OzoneFileStatusIterator<>(f,
- (stat) -> stat instanceof LocatedFileStatus ? (LocatedFileStatus) stat
: new LocatedFileStatus(stat, null),
+ (stat) -> stat instanceof LocatedFileStatus ? (LocatedFileStatus) stat
:
+ new LocatedFileStatus(stat, stat.isFile() ? new BlockLocation[0] :
null),
false);
}
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 ce09ba339a9..ff04093253c 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
@@ -1184,7 +1184,8 @@ public RemoteIterator<LocatedFileStatus>
listLocatedStatus(Path f)
throws IOException {
incrementCounter(Statistic.INVOCATION_LIST_LOCATED_STATUS);
return new OzoneFileStatusIterator<>(f,
- (stat) -> stat instanceof LocatedFileStatus ? (LocatedFileStatus) stat
: new LocatedFileStatus(stat, null),
+ (stat) -> stat instanceof LocatedFileStatus ? (LocatedFileStatus) stat
:
+ new LocatedFileStatus(stat, stat.isFile() ? new BlockLocation[0] :
null),
false);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]