diff --git a/core/server/common/src/main/java/alluxio/underfs/AbstractUfsManager.java b/core/server/common/src/main/java/alluxio/underfs/AbstractUfsManager.java index 4de988ca2e1b..3478edfe5dab 100644 --- a/core/server/common/src/main/java/alluxio/underfs/AbstractUfsManager.java +++ b/core/server/common/src/main/java/alluxio/underfs/AbstractUfsManager.java @@ -160,19 +160,20 @@ private UnderFileSystem getOrAddWithRecorder(AlluxioURI ufsUri, if (useManagedBlocking) { fs = new ManagedBlockingUfsForwarder(fs); } - - if (mUnderFileSystemMap.putIfAbsent(key, fs) != null) { - // This shouldn't occur unless our synchronization is incorrect - LOG.warn("UFS already existed in UFS manager"); - } mCloser.register(fs); try { connectUfs(fs); - } catch (IOException e) { + tryUseFileSystem(fs, ufsUri.getPath()); + } catch (Exception e) { String message = String.format( "Failed to perform initial connect to UFS %s: %s", ufsUri, e); recorder.record(message); LOG.warn(message); + throw new RuntimeException(e); + } + if (mUnderFileSystemMap.putIfAbsent(key, fs) != null) { + // This shouldn't occur unless our synchronization is incorrect + LOG.warn("UFS already existed in UFS manager"); } return fs; } @@ -185,6 +186,17 @@ private UnderFileSystem getOrAddWithRecorder(AlluxioURI ufsUri, */ protected abstract void connectUfs(UnderFileSystem fs) throws IOException; + /** + * To check whether the filesystem is available by calling exists. + * + * @param fs the filesystem + * @param ufsPath the UFS path + * @throws Exception + */ + private void tryUseFileSystem(UnderFileSystem fs, String ufsPath) throws Exception { + fs.exists(ufsPath); + } + @Override public void addMount(long mountId, final AlluxioURI ufsUri, final UnderFileSystemConfiguration ufsConf) {