1818
1919import java .lang .reflect .Method ;
2020import java .net .URI ;
21+ import java .net .URISyntaxException ;
2122import java .util .LinkedHashSet ;
2223import java .util .Optional ;
2324import java .util .Set ;
2425import org .apache .arrow .dataset .jni .NativeDatasetFactory ;
2526import org .apache .arrow .dataset .jni .NativeMemoryPool ;
2627import org .apache .arrow .dataset .scanner .FragmentScanOptions ;
2728import org .apache .arrow .memory .BufferAllocator ;
29+ import org .slf4j .Logger ;
30+ import org .slf4j .LoggerFactory ;
2831
2932/** Java binding of the C++ FileSystemDatasetFactory. */
3033public class FileSystemDatasetFactory extends NativeDatasetFactory {
3134
35+ private static final Logger LOGGER = LoggerFactory .getLogger (FileSystemDatasetFactory .class );
36+
3237 private final Set <URI > hdfsFileSystems ;
3338
3439 public FileSystemDatasetFactory (
@@ -78,11 +83,10 @@ public synchronized void close() {
7883 }
7984
8085 /**
81- * For each {@code hdfs://} URI, close the cached Hadoop FileSystem.
82- * When Arrow C++ accesses HDFS via libhdfs, the Hadoop Java client creates cached FileSystem
83- * instances with non-daemon threads (IPC connections, lease renewers) that prevent JVM exit.
84- * Closing the FileSystem terminates these connections. Uses reflection to avoid a compile-time
85- * dependency on hadoop-common.
86+ * For each {@code hdfs://} URI, close the cached Hadoop FileSystem. When Arrow C++ accesses HDFS
87+ * via libhdfs, the Hadoop Java client creates cached FileSystem instances with non-daemon threads
88+ * (IPC connections, lease renewers) that prevent JVM exit. Closing the FileSystem terminates
89+ * these connections. Uses reflection to avoid a compile-time dependency on hadoop-common.
8690 */
8791 static void closeHadoopFileSystemsIfHdfs (String ... uris ) {
8892 toHdfsFileSystems (uris ).forEach (FileSystemDatasetFactory ::closeHadoopFileSystem );
@@ -94,13 +98,16 @@ private static Set<URI> toHdfsFileSystems(String... uris) {
9498 return hdfsFileSystems ;
9599 }
96100 for (String uri : uris ) {
101+ if (uri == null ) {
102+ continue ;
103+ }
97104 try {
98105 URI parsedUri = new URI (uri );
99106 if ("hdfs" .equalsIgnoreCase (parsedUri .getScheme ())) {
100107 hdfsFileSystems .add (
101108 new URI (parsedUri .getScheme (), parsedUri .getAuthority (), null , null , null ));
102109 }
103- } catch (Exception e ) {
110+ } catch (URISyntaxException e ) {
104111 // Ignore here; native factory creation reports invalid user URIs.
105112 }
106113 }
@@ -117,7 +124,8 @@ private static void closeHadoopFileSystem(URI hdfsUri) {
117124 Method closeMethod = fsClass .getMethod ("close" );
118125 closeMethod .invoke (fs );
119126 } catch (Exception e ) {
120- // Best-effort cleanup; Hadoop may not be on classpath or FileSystem already closed
127+ // Best-effort cleanup; Hadoop may not be on classpath or FileSystem already closed.
128+ LOGGER .debug ("Failed to close Hadoop FileSystem for {}" , hdfsUri , e );
121129 }
122130 }
123131
0 commit comments