New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HDFS-16963. Remove the unnecessary use of Optional from DistributedFileSystem #5505
base: trunk
Are you sure you want to change the base?
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a need to have three possibilities as discussed in comments. What if we create a new enum like Trilean (ex: https://github.com/apache/hadoop/blob/trunk/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/enums/Trilean.java). The Optional.empty() can be replaced with Trilean.UNKOWN.
Trilean trilean = DfsPathCapabilities.hasPathCapability(p, capability);
if(trilean != UNKNOWN) {return trilean.toBoolean();}
capability); | ||
if (cap.isPresent()) { | ||
return cap.get(); | ||
if (DfsPathCapabilities.hasPathCapability(p, capability)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if validatePathCapabilityArgs(path, capability)
in DfsPathCapablity.hasPathCapablity gives CommonPathCapabilities.FS_SYMLINKS
. Now, FileSystem.areSymlinksEnabled()
can be true or false.
In earlier code, if FileSystem.areSymlinksEnabled()
is false, we would retrn from old-line 2213 cap.get()
. But now, it will go ahead and invoke super.hasPathCapability(p, capability);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@saxenapranav , thanks for reviewing this!
For FS_SYMLINKS
, the result is the same since super.hasPathCapability(p, capability)
always return the same value as FileSystem.areSymlinksEnabled()
. However, it may be non-trivial.
Let's use upper case Boolean
and use null to represent unknown.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, findbugs does not like Boolean
. Let me revert the previous change and adds a test to ensure the correctness.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi. I understand that at present making call to FileSystem.hasPathCapability()
is not going to make any issue as it checks for symlinks. But what if there is more logic added in the FileSystem.hasPathCapability()
in future which expects the child classes to call the super method only in required cases.
My thought is that what ever is in FileSystem.hasPathCapablity
should be abstract to any dev reading hasPathCapablity
in DistributedFileSystem
and WebHdfsFileSystem
, and super.hasPathCapablity should be called only when required. if Optional<Boolean> cap
gets true/false, it should return from there and not go to the super method. In my view, super method should only get invoked in case given capability doesn't match any of the
Lines 45 to 57 in b9fa5e0
case CommonPathCapabilities.FS_ACLS: | |
case CommonPathCapabilities.FS_APPEND: | |
case CommonPathCapabilities.FS_CHECKSUMS: | |
case CommonPathCapabilities.FS_CONCAT: | |
case CommonPathCapabilities.FS_LIST_CORRUPT_FILE_BLOCKS: | |
case CommonPathCapabilities.FS_MULTIPART_UPLOADER: | |
case CommonPathCapabilities.FS_PATHHANDLES: | |
case CommonPathCapabilities.FS_PERMISSIONS: | |
case CommonPathCapabilities.FS_SNAPSHOTS: | |
case CommonPathCapabilities.FS_STORAGEPOLICY: | |
case CommonPathCapabilities.FS_XATTRS: | |
return Optional.of(true); | |
case CommonPathCapabilities.FS_SYMLINKS: |
I feel having an enum which can say TRUE, FALSE, UNKNOWN would be great. And the super method getting called only if
DfsPathCapablities.hasPathCapablity
gives UNKNOWN.
Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@saxenapranav , we cannot fix a potential "future" problem. Since there is a unit test, such future change will be detected by the test. At that time, we may think about how to solve the problem such as adding the enum.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am completely understanding your point. But my only difference is that if something is returned from DfsPathCapabilities.hasPathCapability
should be returned back to caller of `DistributedFileSystem.hasPathCapablity), without going to super's method.
I understand that super.hasPathCapability call doesn't pose any issue as of now and we can see for Enum in case more complications are added in future. I have a suggestion in the tests szetszwo@6ddc4f2. In this commit it has added asserts on the conditions used in FileSystem.hasPathCapablity
Would be awesome if you can pick my commit in your pr.
Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@saxenapranav , I am fine to merge your test code. Thanks. Is there a way to do it in Github? Or I have to download it and merge it manually?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much. I have opened pr on your fork: https://github.com/szetszwo/hadoop/pull/2/files. Thanks.
capability); | ||
if (cap.isPresent()) { | ||
return cap.get(); | ||
if (DfsPathCapabilities.hasPathCapability(p, capability)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as given in WebHdfsFileSystem.
This comment was marked as outdated.
This comment was marked as outdated.
This reverts commit 5d1d04c.
This comment was marked as outdated.
This comment was marked as outdated.
The checkstyle warning is about the test method name |
HDFS-16963: added asserts on the conditions used in FileSystem.hasPathCapablity
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking my suggestions. Just a comment for the addition of supportsSymlinks
method call.
if (cap.isPresent()) { | ||
return cap.get(); | ||
if (DfsPathCapabilities.hasPathCapability(p, capability) | ||
&& supportsSymlinks()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why we are adding supportsSymlinks()
? capablity can be anything different from FS_SYMLINKS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In szetszwo@6ddc4f2 , line 62 supportsSymlinks()
returns false but line 64 dfs.hasPathCapability(..)
still returns true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had added supportsSymlinks()
returns false to just assert the behaviour at super.hasPathCapablity()
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
💔 -1 overall
This message was automatically generated. |
Description of PR
See https://issues.apache.org/jira/browse/HDFS-16963
How was this patch tested?
Just a small code improvement. Tested by the existing tests and added a new test.
For code changes:
LICENSE
,LICENSE-binary
,NOTICE-binary
files?