HADOOP-16840. AliyunOSS: getFileStatus throws FileNotFoundException in versioning bucket. Contributed by wujinhu.

This commit is contained in:
Weiwei Yang 2020-03-08 21:01:34 -07:00
parent 999096d82e
commit 6dfe00c71e
2 changed files with 35 additions and 6 deletions

View File

@ -273,12 +273,18 @@ public FileStatus getFileStatus(Path path) throws IOException {
}
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);

View File

@ -31,6 +31,7 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Arrays;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@ -96,6 +97,28 @@ public void testListStatus() throws IOException {
UserGroupInformation.getCurrentUser().getShortUserName());
}
@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");