chihsuan commented on code in PR #10209:
URL: https://github.com/apache/ozone/pull/10209#discussion_r3585991830
##########
hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/BasicOzoneFileSystem.java:
##########
@@ -865,6 +866,91 @@ public BlockLocation[] getFileBlockLocations(FileStatus
fileStatus,
}
}
+ @Override
+ public ContentSummary getContentSummary(Path f) throws IOException {
+ Path qualifiedPath = f.makeQualified(uri, workingDir);
+ String key = pathToKey(qualifiedPath);
+ FileStatusAdapter status;
+ try {
+ status = adapter.getFileStatus(key, uri, qualifiedPath, getUsername());
+ } catch (OMException ex) {
+ if (ex.getResult().equals(OMException.ResultCodes.KEY_NOT_FOUND)) {
+ throw new FileNotFoundException("File not found. path:" + f);
+ }
+ throw ex;
+ }
+
+ if (status.isFile()) {
+ long length = status.getLength();
+ long spaceConsumed = status.getDiskConsumed();
+ ContentSummary.Builder builder = new
ContentSummary.Builder().length(length).
+ fileCount(1).directoryCount(0).spaceConsumed(spaceConsumed);
+ applyEcPolicy(builder, status.getErasureCodingPolicy());
+ return builder.build();
+ }
+
+ long[] summary = {0, 0, 0, 1};
+ for (FileStatusAdapter s : listStatusAdapter(f)) {
+ long length = s.getLength();
+ long spaceConsumed = s.getDiskConsumed();
+ ContentSummary c;
+ if (s.isDir()) {
+ c = getContentSummary(s.getPath());
+ } else {
+ ContentSummary.Builder childBuilder = new
ContentSummary.Builder().length(length).
+ fileCount(1).directoryCount(0).spaceConsumed(spaceConsumed);
+ applyEcPolicy(childBuilder, s.getErasureCodingPolicy());
+ c = childBuilder.build();
+ }
+
+ summary[0] += c.getLength();
+ summary[1] += c.getSpaceConsumed();
+ summary[2] += c.getFileCount();
+ summary[3] += c.getDirectoryCount();
+ }
+
+ ContentSummary.Builder builder = new
ContentSummary.Builder().length(summary[0]).
+ fileCount(summary[2]).directoryCount(summary[3]).
+ spaceConsumed(summary[1]);
+ applyEcPolicy(builder, status.getErasureCodingPolicy());
+ return builder.build();
+ }
+
+ /**
+ * Apply the erasure coding policy on the {@link ContentSummary.Builder}.
+ * Default implementation is a no-op so that this class can compile and run
+ * against Hadoop 2, where {@code ContentSummary.Builder.erasureCodingPolicy}
+ * does not exist. The Hadoop 3 subclass overrides this to set the policy.
+ */
+ protected void applyEcPolicy(ContentSummary.Builder builder, String
ecPolicy) {
Review Comment:
Yeah, Hadoop 2.10.2 doesn’t support ls -e, and I’ve noted that in the PR
description.
--
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]