yandrey321 commented on code in PR #11971:
URL: https://github.com/apache/ozone/pull/11971#discussion_r4569946730
##########
hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/BasicOzoneFileSystem.java:
##########
@@ -887,9 +892,30 @@ public BlockLocation[] getFileBlockLocations(FileStatus
fileStatus,
throws IOException {
if (fileStatus instanceof LocatedFileStatus) {
return getBlockLocationsInRange((LocatedFileStatus) fileStatus, start,
len);
- } else {
- return super.getFileBlockLocations(fileStatus, start, len);
}
+ if (needsBlockLocations(fileStatus, start, len)) {
+ // getFileStatus returns no block locations: fetch them by path, as HDFS
does.
+ return getFileBlockLocations(fileStatus.getPath(), start, len);
+ }
+ return super.getFileBlockLocations(fileStatus, start, len);
+ }
+
+ @Override
+ public BlockLocation[] getFileBlockLocations(Path p, long start, long len)
throws IOException {
+ // One GetFileStatus with block locations, instead of getFileStatus
followed by another for the locations.
+ FileStatus fileStatus = getFileStatus(p, false);
+ if (fileStatus instanceof LocatedFileStatus) {
+ return getBlockLocationsInRange((LocatedFileStatus) fileStatus, start,
len);
+ }
+ return super.getFileBlockLocations(fileStatus, start, len);
+ }
+
+ /**
+ * Whether the block locations of the range must be fetched for a status
from {@link #getFileStatus(Path)}.
+ */
+ static boolean needsBlockLocations(FileStatus fileStatus, long start, long
len) {
+ return fileStatus instanceof FileStatusWithoutBlockLocations &&
fileStatus.isFile()
+ && start >= 0 && len >= 0 && start < fileStatus.getLen();
}
Review Comment:
Kept as is, intentionally. As in HDFS, `getFileBlockLocations` with `len ==
0` returns the block that contains `start`, not an empty array:
`getBlockLocationsInRange` filters with `Math.max(len, 1)`, so that block has
to be fetched. A zero-length file never reaches OM, because `start <
fileStatus.getLen()` is false for it, and
`getFileBlockLocationsWithoutBlocksInRangeDoesNotFetch` already covers that.
Added an assertion for `len == 0` to
`getFileBlockLocationsOfStatusFetchesLocations` to pin this.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]