You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by ww...@apache.org on 2020/03/09 05:02:31 UTC
[hadoop] branch branch-3.1 updated: HADOOP-16840. AliyunOSS:
getFileStatus throws FileNotFoundException in versioning bucket.
Contributed by wujinhu.
This is an automated email from the ASF dual-hosted git repository.
wwei pushed a commit to branch branch-3.1
in repository https://gitbox.apache.org/repos/asf/hadoop.git
The following commit(s) were added to refs/heads/branch-3.1 by this push:
new 79e5633 HADOOP-16840. AliyunOSS: getFileStatus throws FileNotFoundException in versioning bucket. Contributed by wujinhu.
79e5633 is described below
commit 79e56338679d853ffb9875d3aa80d49da93e634b
Author: Weiwei Yang <ww...@apache.org>
AuthorDate: Sun Mar 8 21:01:34 2020 -0700
HADOOP-16840. AliyunOSS: getFileStatus throws FileNotFoundException in versioning bucket. Contributed by wujinhu.
(cherry picked from commit 6dfe00c71eb3721e9be3fc42349a81c4b013ada1)
---
.../hadoop/fs/aliyun/oss/AliyunOSSFileSystem.java | 18 +++++++++++------
.../oss/TestAliyunOSSFileSystemContract.java | 23 ++++++++++++++++++++++
2 files changed, 35 insertions(+), 6 deletions(-)
diff --git a/hadoop-tools/hadoop-aliyun/src/main/java/org/apache/hadoop/fs/aliyun/oss/AliyunOSSFileSystem.java b/hadoop-tools/hadoop-aliyun/src/main/java/org/apache/hadoop/fs/aliyun/oss/AliyunOSSFileSystem.java
index ad359c6..3f87289 100644
--- a/hadoop-tools/hadoop-aliyun/src/main/java/org/apache/hadoop/fs/aliyun/oss/AliyunOSSFileSystem.java
+++ b/hadoop-tools/hadoop-aliyun/src/main/java/org/apache/hadoop/fs/aliyun/oss/AliyunOSSFileSystem.java
@@ -273,12 +273,18 @@ public class AliyunOSSFileSystem extends FileSystem {
}
if (meta == null) {
ObjectListing listing = store.listObjects(key, 1, null, false);
- if (CollectionUtils.isNotEmpty(listing.getObjectSummaries()) ||
- CollectionUtils.isNotEmpty(listing.getCommonPrefixes())) {
- return new OSSFileStatus(0, true, 1, 0, 0, qualifiedPath, username);
- } else {
- throw new FileNotFoundException(path + ": No such file or directory!");
- }
+ do {
+ if (CollectionUtils.isNotEmpty(listing.getObjectSummaries()) ||
+ CollectionUtils.isNotEmpty(listing.getCommonPrefixes())) {
+ return new OSSFileStatus(0, true, 1, 0, 0, qualifiedPath, username);
+ } else if (listing.isTruncated()) {
+ listing = store.listObjects(key, 1000, listing.getNextMarker(),
+ false);
+ } else {
+ throw new FileNotFoundException(
+ path + ": No such file or directory!");
+ }
+ } while (true);
} else if (objectRepresentsDirectory(key, meta.getContentLength())) {
return new OSSFileStatus(0, true, 1, 0, meta.getLastModified().getTime(),
qualifiedPath, username);
diff --git a/hadoop-tools/hadoop-aliyun/src/test/java/org/apache/hadoop/fs/aliyun/oss/TestAliyunOSSFileSystemContract.java b/hadoop-tools/hadoop-aliyun/src/test/java/org/apache/hadoop/fs/aliyun/oss/TestAliyunOSSFileSystemContract.java
index a83c6da..e6467f4 100644
--- a/hadoop-tools/hadoop-aliyun/src/test/java/org/apache/hadoop/fs/aliyun/oss/TestAliyunOSSFileSystemContract.java
+++ b/hadoop-tools/hadoop-aliyun/src/test/java/org/apache/hadoop/fs/aliyun/oss/TestAliyunOSSFileSystemContract.java
@@ -31,6 +31,7 @@ import org.junit.Test;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.util.Arrays;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -97,6 +98,28 @@ public class TestAliyunOSSFileSystemContract
}
@Test
+ public void testGetFileStatusInVersioningBucket() throws Exception {
+ Path file = this.path("/test/hadoop/file");
+ for (int i = 1; i <= 30; ++i) {
+ this.createFile(new Path(file, "sub" + i));
+ }
+ assertTrue("File exists", this.fs.exists(file));
+ FileStatus fs = this.fs.getFileStatus(file);
+ assertEquals(fs.getOwner(),
+ UserGroupInformation.getCurrentUser().getShortUserName());
+ assertEquals(fs.getGroup(),
+ UserGroupInformation.getCurrentUser().getShortUserName());
+
+ AliyunOSSFileSystemStore store = ((AliyunOSSFileSystem)this.fs).getStore();
+ for (int i = 0; i < 29; ++i) {
+ store.deleteObjects(Arrays.asList("test/hadoop/file/sub" + i));
+ }
+
+ // HADOOP-16840, will throw FileNotFoundException without this fix
+ this.fs.getFileStatus(file);
+ }
+
+ @Test
public void testDeleteSubdir() throws IOException {
Path parentDir = this.path("/test/hadoop");
Path file = this.path("/test/hadoop/file");
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org