wuyunfeng commented on a change in pull request #3454:
URL: https://github.com/apache/incubator-doris/pull/3454#discussion_r443279326



##########
File path: 
fe/src/main/java/org/apache/doris/external/elasticsearch/EsRepository.java
##########
@@ -0,0 +1,118 @@
+// 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.external.elasticsearch;
+
+import org.apache.doris.catalog.Catalog;
+import org.apache.doris.catalog.Database;
+import org.apache.doris.catalog.EsTable;
+import org.apache.doris.catalog.Table;
+import org.apache.doris.catalog.Table.TableType;
+import org.apache.doris.common.Config;
+import org.apache.doris.common.util.MasterDaemon;
+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;
+
+
+/**
+ * It is used to call es api to get shard allocation state
+ */
+public class EsRepository extends MasterDaemon {
+    
+    private static final Logger LOG = LogManager.getLogger(EsRepository.class);
+    
+    private Map<Long, EsTable> esTables;
+    
+    private Map<Long, EsRestClient> esClients;
+    
+    public EsRepository() {
+        super("es state store", Config.es_state_sync_interval_second * 1000);
+        esTables = Maps.newConcurrentMap();
+        esClients = Maps.newConcurrentMap();
+    }
+    
+    public void registerTable(EsTable esTable) {
+        if (Catalog.isCheckpointThread()) {
+            return;
+        }
+        esTables.put(esTable.getId(), esTable);
+        esClients.put(esTable.getId(),
+                new EsRestClient(esTable.getSeeds(), esTable.getUserName(), 
esTable.getPasswd()));
+        LOG.info("register a new table [{}] to sync list", esTable);
+    }
+    
+    public void deRegisterTable(long tableId) {
+        esTables.remove(tableId);
+        esClients.remove(tableId);
+        LOG.info("deregister table [{}] from sync list", tableId);
+    }
+    
+    @Override
+    protected void runAfterCatalogReady() {
+        for (EsTable esTable : esTables.values()) {
+            try {
+                EsRestClient client = esClients.get(esTable.getId());
+                
+                if (esTable.isKeywordSniffEnable() || 
esTable.isDocValueScanEnable()) {

Review comment:
       74 - 90 or 92 - 90 can be abstract to EsTable's method

##########
File path: 
fe/src/main/java/org/apache/doris/external/elasticsearch/EsRepository.java
##########
@@ -0,0 +1,118 @@
+// 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.external.elasticsearch;
+
+import org.apache.doris.catalog.Catalog;
+import org.apache.doris.catalog.Database;
+import org.apache.doris.catalog.EsTable;
+import org.apache.doris.catalog.Table;
+import org.apache.doris.catalog.Table.TableType;
+import org.apache.doris.common.Config;
+import org.apache.doris.common.util.MasterDaemon;
+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;
+
+
+/**
+ * It is used to call es api to get shard allocation state
+ */
+public class EsRepository extends MasterDaemon {
+    
+    private static final Logger LOG = LogManager.getLogger(EsRepository.class);
+    
+    private Map<Long, EsTable> esTables;
+    
+    private Map<Long, EsRestClient> esClients;
+    
+    public EsRepository() {
+        super("es state store", Config.es_state_sync_interval_second * 1000);
+        esTables = Maps.newConcurrentMap();
+        esClients = Maps.newConcurrentMap();
+    }
+    
+    public void registerTable(EsTable esTable) {
+        if (Catalog.isCheckpointThread()) {
+            return;
+        }
+        esTables.put(esTable.getId(), esTable);
+        esClients.put(esTable.getId(),
+                new EsRestClient(esTable.getSeeds(), esTable.getUserName(), 
esTable.getPasswd()));
+        LOG.info("register a new table [{}] to sync list", esTable);
+    }
+    
+    public void deRegisterTable(long tableId) {
+        esTables.remove(tableId);
+        esClients.remove(tableId);
+        LOG.info("deregister table [{}] from sync list", tableId);
+    }
+    
+    @Override
+    protected void runAfterCatalogReady() {
+        for (EsTable esTable : esTables.values()) {
+            try {
+                EsRestClient client = esClients.get(esTable.getId());
+                
+                if (esTable.isKeywordSniffEnable() || 
esTable.isDocValueScanEnable()) {
+                    EsFieldInfos fieldInfos = 
client.getFieldInfos(esTable.getIndexName(), esTable.getMappingType(), 
esTable.getFullSchema());
+                    if (fieldInfos == null) {
+                        continue;

Review comment:
       fieldInfos == null 逻辑上不应该continue,因为如果我一个表既没有docvalue 
有没有keyword,难道就不该进行下面的逻辑?




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

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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to