From a600f12b8f57ccf9ac3d37cafdd6aff157020b02 Mon Sep 17 00:00:00 2001 From: Haoning Sun Date: Fri, 31 Mar 2023 10:59:06 +0800 Subject: [PATCH] Check filesystem for mount point ### What changes are proposed in this pull request? Fix #17158. pr-link: Alluxio/alluxio#17159 change-id: cid-341bd1e1a2a23530da4ab97161704b5b22c8f0ed --- .../alluxio/underfs/AbstractUfsManager.java | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) 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) {