CalvinKirs commented on code in PR #62023:
URL: https://github.com/apache/doris/pull/62023#discussion_r3043324409


##########
fe/fe-core/src/main/java/org/apache/doris/fs/FileSystemFactory.java:
##########
@@ -17,29 +17,198 @@
 
 package org.apache.doris.fs;
 
+import org.apache.doris.analysis.BrokerDesc;
+import org.apache.doris.catalog.Env;
+import org.apache.doris.catalog.FsBroker;
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.common.Config;
 import org.apache.doris.common.UserException;
+import org.apache.doris.common.util.NetUtils;
+import org.apache.doris.datasource.property.storage.BrokerProperties;
 import org.apache.doris.datasource.property.storage.StorageProperties;
-import org.apache.doris.fs.remote.RemoteFileSystem;
+import org.apache.doris.filesystem.spi.FileSystemProvider;
+import org.apache.doris.service.FrontendOptions;
 
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.ServiceLoader;
+
+/**
+ * Factory for filesystem instances.
+ *
+ * <p>Call {@link #initPluginManager(FileSystemPluginManager)} at FE startup 
before any
+ * {@code getFileSystem()} call. In production, providers are loaded from the 
plugin directory
+ * configured via {@code filesystem_plugin_root}. In unit tests, providers are 
discovered from
+ * the test classpath via ServiceLoader.
+ */
+public final class FileSystemFactory {
+
+    private static final Logger LOG = 
LogManager.getLogger(FileSystemFactory.class);
+
+    // Plugin manager singleton, set at FE startup
+    private static volatile FileSystemPluginManager pluginManager;
+
+    // Fallback provider cache for non-initialized environments (tests, 
migration phase)
+    private static volatile List<FileSystemProvider> cachedProviders = null;
+
+    private FileSystemFactory() {}
 
-public class FileSystemFactory {
+    // =========================================================
+    // SPI API — returns spi.FileSystem
+    // =========================================================
 
-    public static RemoteFileSystem get(StorageProperties storageProperties) {
-        return StorageTypeMapper.create(storageProperties);
+    /**
+     * Sets the plugin manager singleton. Called once at FE startup before any
+     * {@code getFileSystem()} invocation.
+     */
+    public static void initPluginManager(FileSystemPluginManager manager) {
+        pluginManager = manager;
     }
 
-    //todo remove when catalog use storage properties
-    public static RemoteFileSystem get(FileSystemType fileSystemType, 
Map<String, String> properties)
-            throws UserException {
-        List<StorageProperties> storagePropertiesList = 
StorageProperties.createAll(properties);
+    /**
+     * SPI entry point: selects a provider and creates the filesystem.
+     *
+     * <p>If {@link #initPluginManager} has been called (production path),
+     * delegates to {@link FileSystemPluginManager#createFileSystem}.
+     * Otherwise falls back to ServiceLoader discovery (unit-test / migration 
path).
+     *
+     * @param properties key-value storage configuration
+     * @return initialized {@code org.apache.doris.filesystem.FileSystem}
+     * @throws IOException if no provider matches or creation fails
+     */
+    public static org.apache.doris.filesystem.FileSystem 
getFileSystem(Map<String, String> properties)
+            throws IOException {
+        FileSystemPluginManager mgr = pluginManager;

Review Comment:
   @CalvinKirs 



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to