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


##########
fe/fe-core/src/main/java/org/apache/doris/datasource/doris/DorisExternalMetaCacheMgr.java:
##########
@@ -0,0 +1,83 @@
+// 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.datasource.doris;
+
+import org.apache.doris.catalog.Env;
+import org.apache.doris.common.CacheFactory;
+import org.apache.doris.common.Config;
+import org.apache.doris.system.Backend;
+
+import com.github.benmanes.caffeine.cache.LoadingCache;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.util.List;
+import java.util.Map;
+import java.util.OptionalLong;
+import java.util.concurrent.ExecutorService;
+import java.util.stream.Collectors;
+
+public class DorisExternalMetaCacheMgr {
+    private static final Logger LOG = 
LogManager.getLogger(DorisExternalMetaCacheMgr.class);
+    private final LoadingCache<Long, ImmutableMap<Long, Backend>> 
backendsCache;
+
+    public DorisExternalMetaCacheMgr(ExecutorService executor) {
+        CacheFactory cacheFactory = new CacheFactory(
+                
OptionalLong.of(Config.external_cache_expire_time_seconds_after_access),
+                OptionalLong.of(Config.external_cache_refresh_time_minutes * 
60),
+                Config.max_external_table_cache_num,

Review Comment:
   It is strange to use `max_external_table_cache_num` for `backendsCache`. 
Actually the cache size if "num of catalogs". And there won't be too many 
catalogs there. So I suggest to use a fixed small number is enough, like 10 or 
20? Or we can just add a new config for this.



##########
fe/fe-core/src/main/java/org/apache/doris/datasource/doris/RemoteDorisExternalTable.java:
##########
@@ -50,6 +55,27 @@ protected synchronized void makeSureInitialized() {
         }
     }
 
+    private RemoteOlapTable getDorisOlapTable() {
+        // TODO if multi thread call this method, only call once

Review Comment:
   So for new, we will get olap table from remote cluster in every query?
   



##########
fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java:
##########
@@ -3698,4 +3699,44 @@ public Index getInvertedIndex(Column column, 
List<String> subPath) {
                                         
.filter(Index::isAnalyzedInvertedIndex).findFirst().orElse(null);
         }
     }
+
+    /**
+     * caller should acquire the read lock and should not modify any field of 
the return obj
+     */
+    public OlapTable copyTableMeta() {

Review Comment:
   This is very error-prone. If someone add new field in this class, he may 
forget to modify here. 



##########
fe/fe-core/src/main/java/org/apache/doris/datasource/doris/DorisExternalMetaCacheMgr.java:
##########
@@ -0,0 +1,83 @@
+// 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.datasource.doris;
+
+import org.apache.doris.catalog.Env;
+import org.apache.doris.common.CacheFactory;
+import org.apache.doris.common.Config;
+import org.apache.doris.system.Backend;
+
+import com.github.benmanes.caffeine.cache.LoadingCache;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.util.List;
+import java.util.Map;
+import java.util.OptionalLong;
+import java.util.concurrent.ExecutorService;
+import java.util.stream.Collectors;
+
+public class DorisExternalMetaCacheMgr {
+    private static final Logger LOG = 
LogManager.getLogger(DorisExternalMetaCacheMgr.class);
+    private final LoadingCache<Long, ImmutableMap<Long, Backend>> 
backendsCache;
+
+    public DorisExternalMetaCacheMgr(ExecutorService executor) {
+        CacheFactory cacheFactory = new CacheFactory(
+                
OptionalLong.of(Config.external_cache_expire_time_seconds_after_access),
+                OptionalLong.of(Config.external_cache_refresh_time_minutes * 
60),
+                Config.max_external_table_cache_num,
+                true,
+                null);
+        backendsCache = cacheFactory.buildCache(key -> loadBackends(key), 
executor);
+    }
+
+    private ImmutableMap<Long, Backend> loadBackends(Long catalogId) {
+        RemoteDorisExternalCatalog catalog = (RemoteDorisExternalCatalog) 
Env.getCurrentEnv().getCatalogMgr()
+                .getCatalog(catalogId);
+        List<Backend> backends = catalog.getFeServiceClient().listBackends();
+        if (LOG.isDebugEnabled()) {
+            List<String> names = backends.stream().map(b -> 
b.getAddress()).collect(Collectors.toList());
+            LOG.debug("load backends:{} from:{}", String.join(",", names), 
catalog.getName());

Review Comment:
   if (LOG.isDebugEnable()) {
    xxxx
   }



##########
fe/fe-core/src/main/java/org/apache/doris/datasource/doris/RemoteOlapTable.java:
##########
@@ -0,0 +1,137 @@
+// 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.datasource.doris;
+
+import org.apache.doris.catalog.Env;
+import org.apache.doris.catalog.OlapTable;
+import org.apache.doris.catalog.Partition;
+import org.apache.doris.catalog.Tablet;
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.system.Backend;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class RemoteOlapTable extends OlapTable {
+    private static final Logger LOG = 
LogManager.getLogger(RemoteOlapTable.class);
+
+    private RemoteDorisExternalCatalog catalog;
+    private RemoteDorisExternalDatabase database;
+    private ImmutableMap<Long, Backend> backends = ImmutableMap.of();

Review Comment:
   I think this info should be in Catalog level? not table level



##########
fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java:
##########
@@ -3698,4 +3699,44 @@ public Index getInvertedIndex(Column column, 
List<String> subPath) {
                                         
.filter(Index::isAnalyzedInvertedIndex).findFirst().orElse(null);
         }
     }
+
+    /**
+     * caller should acquire the read lock and should not modify any field of 
the return obj
+     */
+    public OlapTable copyTableMeta() {

Review Comment:
   Can we use `selectiveCopy()` method to do this. This method is used for 
backup.



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