From 3ef0e3d6155c9c3f0e7b133222db5e6449bacf23 Mon Sep 17 00:00:00 2001 From: Mukund Thakur Date: Fri, 27 Nov 2020 01:55:32 +0530 Subject: [PATCH] HADOOP-17398. Skipping network I/O in S3A getFileStatus(/) breaks some tests (#2493) Follow-on to HADOOP-17323. Contributed by Mukund Thakur. --- .../hadoop/fs/s3a/tools/MarkerTool.java | 28 ++++++++++++------- .../fs/s3a/ITestS3ABucketExistence.java | 6 ++-- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/tools/MarkerTool.java b/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/tools/MarkerTool.java index c1e4c8a4106..3280e67dbc8 100644 --- a/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/tools/MarkerTool.java +++ b/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/tools/MarkerTool.java @@ -282,16 +282,24 @@ public final class MarkerTool extends S3GuardTool { } FileSystem fs = path.getFileSystem(getConf()); boolean nonAuth = command.getOpt(OPT_NONAUTH); - ScanResult result = execute( - new ScanArgsBuilder() - .withSourceFS(fs) - .withPath(path) - .withDoPurge(clean) - .withMinMarkerCount(expectedMin) - .withMaxMarkerCount(expectedMax) - .withLimit(limit) - .withNonAuth(nonAuth) - .build()); + ScanResult result; + try { + result = execute( + new ScanArgsBuilder() + .withSourceFS(fs) + .withPath(path) + .withDoPurge(clean) + .withMinMarkerCount(expectedMin) + .withMaxMarkerCount(expectedMax) + .withLimit(limit) + .withNonAuth(nonAuth) + .build()); + } catch (UnknownStoreException ex) { + // bucket doesn't exist. + // replace the stack trace with an error code. + throw new ExitUtil.ExitException(EXIT_NOT_FOUND, + ex.toString(), ex); + } if (verbose) { dumpFileSystemStatistics(out); } diff --git a/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/ITestS3ABucketExistence.java b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/ITestS3ABucketExistence.java index 8c215d79ea6..934ad29ed25 100644 --- a/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/ITestS3ABucketExistence.java +++ b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/ITestS3ABucketExistence.java @@ -62,8 +62,10 @@ public class ITestS3ABucketExistence extends AbstractS3ATestBase { Path root = new Path(uri); - expectUnknownStore( - () -> fs.getFileStatus(root)); + //See HADOOP-17323. + assertTrue("root path should always exist", fs.exists(root)); + assertTrue("getFileStatus on root should always return a directory", + fs.getFileStatus(root).isDirectory()); expectUnknownStore( () -> fs.listStatus(root));