morningman commented on code in PR #51177:
URL: https://github.com/apache/doris/pull/51177#discussion_r2124234383


##########
fe/fe-core/src/main/java/org/apache/doris/fsv2/FileSystemProviderImpl.java:
##########
@@ -0,0 +1,43 @@
+// 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.doris.fsv2;
+
+import org.apache.doris.datasource.ExternalMetaCacheMgr;
+import org.apache.doris.datasource.SessionContext;
+import org.apache.doris.fsv2.remote.SwitchingFileSystem;
+
+import java.util.Map;
+
+public class FileSystemProviderImpl implements FileSystemProvider {
+    private ExternalMetaCacheMgr extMetaCacheMgr;
+    private String bindBrokerName;
+
+    private Map<String, String> properties;
+
+    public FileSystemProviderImpl(ExternalMetaCacheMgr extMetaCacheMgr, String 
bindBrokerName,
+                                  Map<String, String> properties) {

Review Comment:
   Should pass `StorageProperties` instead of raw map



##########
fe/fe-core/src/main/java/org/apache/doris/fsv2/FileSystemCache.java:
##########
@@ -0,0 +1,117 @@
+// 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.doris.fsv2;
+
+import org.apache.doris.common.CacheFactory;
+import org.apache.doris.common.Config;
+import org.apache.doris.common.Pair;
+import org.apache.doris.common.UserException;
+import org.apache.doris.fsv2.remote.RemoteFileSystem;
+
+import com.github.benmanes.caffeine.cache.LoadingCache;
+import org.apache.hadoop.conf.Configuration;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.OptionalLong;
+
+public class FileSystemCache {
+
+    private final LoadingCache<FileSystemCacheKey, RemoteFileSystem> 
fileSystemCache;
+
+    public FileSystemCache() {
+        // no need to set refreshAfterWrite, because the FileSystem is created 
once and never changed
+        CacheFactory fsCacheFactory = new CacheFactory(
+                OptionalLong.of(86400L),
+                OptionalLong.empty(),
+                Config.max_remote_file_system_cache_num,
+                false,
+                null);
+        fileSystemCache = fsCacheFactory.buildCache(this::loadFileSystem);
+    }
+
+    private RemoteFileSystem loadFileSystem(FileSystemCacheKey key) throws 
UserException {
+        return FileSystemFactory.get(key.type, key.getFsProperties(), 
key.bindBrokerName);
+    }
+
+    public RemoteFileSystem getRemoteFileSystem(FileSystemCacheKey key) {
+        return fileSystemCache.get(key);
+    }
+
+    public static class FileSystemCacheKey {
+        private final FileSystemType type;
+        // eg: hdfs://nameservices1
+        private final String fsIdent;
+        private final Map<String, String> properties;
+        private final String bindBrokerName;
+        // only for creating new file system
+        private final Configuration conf;
+
+        public FileSystemCacheKey(Pair<FileSystemType, String> fs,
+                                  Map<String, String> properties,

Review Comment:
   Still using a raw map?



##########
fe/fe-core/src/main/java/org/apache/doris/fsv2/FileSystemFactory.java:
##########
@@ -52,6 +53,22 @@ public static RemoteFileSystem get(String name, Map<String, 
String> properties)
         return new BrokerFileSystem(name, properties);
     }
 
+    public static RemoteFileSystem get(FileSystemType fileSystemType, 
Map<String, String> properties,

Review Comment:
   I think in this class, we should only keep `get(StorageProperties 
storageProperties)`, and remove all other `get` method.



##########
fe/fe-core/src/main/java/org/apache/doris/fsv2/remote/SwitchingFileSystem.java:
##########
@@ -0,0 +1,132 @@
+// 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.doris.fsv2.remote;
+
+import org.apache.doris.backup.Status;
+import org.apache.doris.common.util.LocationPath;
+import org.apache.doris.datasource.ExternalMetaCacheMgr;
+import org.apache.doris.fsv2.FileSystem;
+import org.apache.doris.fsv2.FileSystemCache;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+public class SwitchingFileSystem implements FileSystem {
+
+    private final ExternalMetaCacheMgr extMetaCacheMgr;
+
+    private final String bindBrokerName;
+
+    private final Map<String, String> properties;

Review Comment:
   Should use `StorageProperties` instead of raw map



-- 
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