yuqi1129 commented on code in PR #5020:
URL: https://github.com/apache/gravitino/pull/5020#discussion_r1796854218


##########
catalogs/catalog-hadoop/src/main/java/org/apache/gravitino/catalog/hadoop/fs/HDFSFileSystemProvider.java:
##########
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.catalog.hadoop.fs;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.Map;
+import org.apache.gravitino.catalog.hadoop.FileSystemProvider;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+
+public class HDFSFileSystemProvider implements FileSystemProvider {
+
+  @Override
+  public FileSystem getFileSystem(Map<String, String> config) throws 
IOException {
+    Configuration configuration = new Configuration();
+    config.forEach(configuration::set);
+
+    String pathString = configuration.get("fs.defaultFS");
+    if (pathString == null) {
+      throw new IllegalArgumentException("The path should be specified.");
+    }
+
+    URI uri = new Path(pathString).toUri();
+    if (uri.getScheme() != null && !uri.getScheme().equals("hdfs")) {
+      throw new IllegalArgumentException("The path should be a HDFS path.");
+    }
+
+    // Should we call DistributedFileSystem to create file system instance 
explicitly? If we
+    // explicitly create a HDFS file system here, we can't reuse the file 
system cache in the
+    // FileSystem class.
+    String impl = configuration.get("fs.hdfs.impl");
+    if (impl == null) {
+      configuration.set("fs.hdfs.impl", 
"org.apache.hadoop.hdfs.DistributedFileSystem");
+    } else {
+      if (!impl.equals("org.apache.hadoop.hdfs.DistributedFileSystem")) {
+        throw new IllegalArgumentException(
+            "The HDFS file system implementation class should be 
'org.apache.hadoop.hdfs.DistributedFileSystem'.");
+      }
+    }
+
+    try {
+      if 
(HDFSFileSystemProvider.class.getClassLoader().loadClass(configuration.get("fs.hdfs.impl"))
+          == null) {
+        throw new IllegalArgumentException(
+            "The HDFS file system implementation class is not found.");
+      }
+    } catch (ClassNotFoundException e) {
+      throw new IllegalArgumentException("The HDFS file system implementation 
class is not found.");
+    }
+
+    return FileSystem.newInstance(uri, configuration);

Review Comment:
   Yeah, I have noticed this scenario,  Since GVFS uses `newInstance`,  the 
Providers also need to use the same method that always creates a file system 
instance, or some test will fail.
   
   
https://github.com/apache/gravitino/blob/02c2ef0ec547351e4efdc8653eacf2d58d3c43cb/clients/filesystem-hadoop3/src/test/java/org/apache/gravitino/filesystem/hadoop/integration/test/GravitinoVirtualFileSystemIT.java#L227-L243
   
   L242 will fail as the `fs` has been closed by code in L232-L238.
   
   So I have no choice but to use `newInstance` to replace `get` in the 
providers. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to