EvanLjp commented on a change in pull request #6499:
URL: https://github.com/apache/skywalking/pull/6499#discussion_r589226909



##########
File path: 
oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/base/StorageEsInstaller.java
##########
@@ -38,68 +42,165 @@
 @Slf4j
 public class StorageEsInstaller extends ModelInstaller {
     private final Gson gson = new Gson();
-
     private final StorageModuleElasticsearchConfig config;
     protected final ColumnTypeEsMapping columnTypeEsMapping;
 
+    /**
+     * The mappings of the template .
+     */
+    private final Map<String, Map<String, Object>> tables;
+
     public StorageEsInstaller(Client client,
                               ModuleManager moduleManager,
-                              final StorageModuleElasticsearchConfig config) {
+                              StorageModuleElasticsearchConfig config) throws 
StorageException {
         super(client, moduleManager);
         this.columnTypeEsMapping = new ColumnTypeEsMapping();
         this.config = config;
+        this.tables = new HashMap<>();
     }
 
     @Override
     protected boolean isExists(Model model) throws StorageException {
         ElasticSearchClient esClient = (ElasticSearchClient) client;
+        String tableName = IndexController.INSTANCE.getTableName(model);
+        IndexController.LogicIndicesRegister.registerRelation(model.getName(), 
tableName);
         try {
-            if (model.isTimeSeries()) {
-                return esClient.isExistsTemplate(model.getName()) && 
esClient.isExistsIndex(
-                    TimeSeriesUtils.latestWriteIndexName(model));
-            } else {
-                return esClient.isExistsIndex(model.getName());
+            if (!model.isTimeSeries()) {
+                return esClient.isExistsIndex(tableName);
             }
+            boolean exist = esClient.isExistsTemplate(tableName)
+                && 
esClient.isExistsIndex(TimeSeriesUtils.latestWriteIndexName(model));
+            if (RunningMode.isInitMode() && 
IndexController.INSTANCE.isAggregationMode(model)) {
+                appendTemplateMapping(tableName, (Map<String, Object>) 
esClient.getTemplate(tableName).get("mappings"));
+                exist = exist && isTemplateMappingCompatible(tableName, 
createMapping(model));
+            }
+            return exist;
         } catch (IOException e) {
             throw new StorageException(e.getMessage());
         }
     }
 
     @Override
     protected void createTable(Model model) throws StorageException {
+        if (model.isTimeSeries()) {
+            createTimeSeriesTable(model);
+        } else {
+            createNormalTable(model);
+        }
+    }
+
+    private void createNormalTable(Model model) throws StorageException {
         ElasticSearchClient esClient = (ElasticSearchClient) client;
+        String tableName = IndexController.INSTANCE.getTableName(model);
+        IndexController.LogicIndicesRegister.registerRelation(model.getName(), 
tableName);

Review comment:
       
![image](https://user-images.githubusercontent.com/31562192/110290899-41717800-8026-11eb-9641-ab28b70a206a.png)
   already checked , the 2 lines only for register the relation of the logic 
table and the physical table




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


Reply via email to