HDDS-7253. Fix exception when '/' in key name
What changes were proposed in this pull request?
Fix exception when '/' in key name
What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-7253
How was this patch tested?
How to reproduce the bug
- First put a key that containing '/'
[root@Linux /root/ozone]% bin/ozone sh key put s3v/testbucket/dir1/dir2/key1 ~/testfile
[root@Linux /root/ozone]% bin/ozone sh key ls s3v/testbucket/ | grep name
"name" : "dir1/dir2/key1"
- Execute command
ls command for keys containing '/'
before this commit
[root@Linux /root/ozone]% bin/ozone fs -ls ofs://localhost/s3v/testbucket/
Found 1 items
drwxrwxrwx - root root 0 2022-09-19 14:11 ofs://localhost/s3v/testbucket/dir1
[root@Linux /root/ozone]% bin/ozone fs -ls ofs://localhost/s3v/testbucket/dir1
ls: `ofs://localhost/s3v/testbucket/dir1': No such file or directory
after this commit
[root@Linux /root/ozone]% bin/ozone fs -ls ofs://localhost/s3v/testbucket/
Found 1 items
drwxrwxrwx - root root 0 2022-09-19 14:37 ofs://localhost/s3v/testbucket/dir1
[root@Linux /root/ozone]% bin/ozone fs -ls ofs://localhost/s3v/testbucket/dir1
Found 1 items
drwxrwxrwx - root root 0 2022-09-19 14:37 ofs://localhost/s3v/testbucket/dir1/dir2
for mv, mkdir, count command for keys containing '/'
before this commit
[root@Linux /root/ozone]% bin/ozone fs -count ofs://localhost/s3v/testbucket/
count: dir1: No such file or directory!
[root@Linux /root/ozone]% bin/ozone fs -mv ofs://localhost/s3v/testbucket/dir1 ofs://localhost/s3v/testbucket/dir2
mv: `ofs://localhost/s3v/testbucket/dir1': No such file or directory
[root@Linux /root/ozone]% bin/ozone fs -mkdir ofs://localhost/s3v/testbucket/dir1/dir2/key2
mkdir: `ofs://localhost/s3v/testbucket/dir1/dir2': No such file or directory
after this commit
[root@Linux /root/ozone]% bin/ozone fs -count ofs://localhost/s3v/testbucket/
3 1 1048576 ofs://localhost/s3v/testbucket
[root@Linux /root/ozone]% bin/ozone fs -mv ofs://localhost/s3v/testbucket/dir1 ofs://localhost/s3v/testbucket/newdir1
[root@Linux /root/ozone]% bin/ozone fs -ls ofs://localhost/s3v/testbucket/
Found 1 items
drwxrwxrwx - root root 0 2022-09-19 14:39 ofs://localhost/s3v/testbucket/newdir1
[root@Linux /root/ozone]% bin/ozone fs -mkdir ofs://localhost/s3v/testbucket/newdir1/dir2/dir3
[root@Linux /root/ozone]% bin/ozone fs -ls ofs://localhost/s3v/testbucket/newdir1/dir2/
Found 2 items
drwxrwxrwx - root root 0 2022-09-19 14:43 ofs://localhost/s3v/testbucket/newdir1/dir2/dir3
-rw-rw-rw- 3 root root 1048576 2022-09-19 14:39 ofs://localhost/s3v/testbucket/newdir1/dir2/key1
when '/' in key name the listSatus will create a fake directory return to the client. The client will get the fake directory info through getfileStatus, but currently getfileStatus has no logic for fake directory, this is inconsistent with listStatus behavior, So some exceptions occur.
This PR is to make listStatus and getFileStatus have the same behavior.
https://github.com/apache/ozone/blob/6c1a5ee07eedfee3e40405bc2d36a7c07e66ab76/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/KeyManagerImpl.java#L1700-L1711
The problem I'm currently having is that I can't use the -du/-count command. Since some keys have '/' in their names.
For some already created and used buckets whose layout is LEGACY, some file system commands cannot be used due to the fake directory returned by listStatus. This should not be expected behavior, we should be able to handle this situation correctly
cc @duongkame
@sadanand48 PTAL Thanks.
Thanks @xichen01 for the work, @duongkame and @sadanand48 for the review.
Sorry I have to revert this commit because it's making ITestOzoneContractMkdir flaky.
Please take a look and submit another PR for this fix. @xichen01
@kaijchen Are there some failed operations I can refer to them? So I can find out which tests are flaky.
@kaijchen Are there some failed operations I can refer to them? So I can find out which tests are flaky.
Here is one of the failing case, but not the only one. Please run ITestOzoneContractMkdir multiple times to find out more. https://github.com/apache/ozone/actions/runs/3322837635/jobs/5492873757
@xichen01 I think it would be better to have this fix, could you please take a look at the failures.
@xichen01 I can help take a look if you need.
@sadanand48 @kaijchen Okay, I'll check this PR, I've looked at it briefly before, but I haven't identified possible reasons causing ITestOzoneContractMkdir flaky.
@xichen01 I can help take a look if you need.
yeah, thank you, I think it would be helpful, and if you have time, I will prioritize this issue as well
@xichen01 FYI, here is ITestOzoneContractMkdir repeated 100x with this PR merged. https://github.com/kaijchen/ozone/actions/runs/3570532658
this is latest MR https://github.com/apache/ozone/pull/4038
@kaijchen I think the issue of ITestOzoneContractMkdir should have been fixed, can you run it multiple times to confirm the fix, I have run it multiple times on my Linux and have not reproduced the issue again, thanks a lot.