Skip to content

Commit 6dfe00c

Browse files
committed
HADOOP-16840. AliyunOSS: getFileStatus throws FileNotFoundException in versioning bucket. Contributed by wujinhu.
1 parent 999096d commit 6dfe00c

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

hadoop-tools/hadoop-aliyun/src/main/java/org/apache/hadoop/fs/aliyun/oss/AliyunOSSFileSystem.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,18 @@ public FileStatus getFileStatus(Path path) throws IOException {
273273
}
274274
if (meta == null) {
275275
ObjectListing listing = store.listObjects(key, 1, null, false);
276-
if (CollectionUtils.isNotEmpty(listing.getObjectSummaries()) ||
277-
CollectionUtils.isNotEmpty(listing.getCommonPrefixes())) {
278-
return new OSSFileStatus(0, true, 1, 0, 0, qualifiedPath, username);
279-
} else {
280-
throw new FileNotFoundException(path + ": No such file or directory!");
281-
}
276+
do {
277+
if (CollectionUtils.isNotEmpty(listing.getObjectSummaries()) ||
278+
CollectionUtils.isNotEmpty(listing.getCommonPrefixes())) {
279+
return new OSSFileStatus(0, true, 1, 0, 0, qualifiedPath, username);
280+
} else if (listing.isTruncated()) {
281+
listing = store.listObjects(key, 1000, listing.getNextMarker(),
282+
false);
283+
} else {
284+
throw new FileNotFoundException(
285+
path + ": No such file or directory!");
286+
}
287+
} while (true);
282288
} else if (objectRepresentsDirectory(key, meta.getContentLength())) {
283289
return new OSSFileStatus(0, true, 1, 0, meta.getLastModified().getTime(),
284290
qualifiedPath, username);

hadoop-tools/hadoop-aliyun/src/test/java/org/apache/hadoop/fs/aliyun/oss/TestAliyunOSSFileSystemContract.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import java.io.FileNotFoundException;
3333
import java.io.IOException;
34+
import java.util.Arrays;
3435

3536
import static org.junit.Assert.assertFalse;
3637
import static org.junit.Assert.assertTrue;
@@ -96,6 +97,28 @@ public void testListStatus() throws IOException {
9697
UserGroupInformation.getCurrentUser().getShortUserName());
9798
}
9899

100+
@Test
101+
public void testGetFileStatusInVersioningBucket() throws Exception {
102+
Path file = this.path("/test/hadoop/file");
103+
for (int i = 1; i <= 30; ++i) {
104+
this.createFile(new Path(file, "sub" + i));
105+
}
106+
assertTrue("File exists", this.fs.exists(file));
107+
FileStatus fs = this.fs.getFileStatus(file);
108+
assertEquals(fs.getOwner(),
109+
UserGroupInformation.getCurrentUser().getShortUserName());
110+
assertEquals(fs.getGroup(),
111+
UserGroupInformation.getCurrentUser().getShortUserName());
112+
113+
AliyunOSSFileSystemStore store = ((AliyunOSSFileSystem)this.fs).getStore();
114+
for (int i = 0; i < 29; ++i) {
115+
store.deleteObjects(Arrays.asList("test/hadoop/file/sub" + i));
116+
}
117+
118+
// HADOOP-16840, will throw FileNotFoundException without this fix
119+
this.fs.getFileStatus(file);
120+
}
121+
99122
@Test
100123
public void testDeleteSubdir() throws IOException {
101124
Path parentDir = this.path("/test/hadoop");

0 commit comments

Comments
 (0)