wu-sheng commented on a change in pull request #6499:
URL: https://github.com/apache/skywalking/pull/6499#discussion_r588878964



##########
File path: 
oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/base/StorageEsInstaller.java
##########
@@ -68,40 +78,87 @@ protected boolean isExists(Model model) throws 
StorageException {
     @Override
     protected void createTable(Model model) throws StorageException {
         ElasticSearchClient esClient = (ElasticSearchClient) client;
-
         Map<String, Object> settings = createSetting(model);
         Map<String, Object> mapping = createMapping(model);
-        log.info("index {}'s columnTypeEsMapping builder str: {}", 
esClient.formatIndexName(model.getName()), mapping
-            .toString());
+        String tableName = PhysicalIndexManager.INSTANCE.getTableName(model);
+        PhysicalIndices.registerRelation(model.getName(), tableName);
+        log.info("index {}'s columnTypeEsMapping builder str: {}",
+                 esClient.formatIndexName(tableName), mapping.toString()
+        );
 
+        String indexName;
         try {
-            String indexName;
-            if (!model.isTimeSeries()) {
-                indexName = model.getName();
-            } else {
-                if (!esClient.isExistsTemplate(model.getName())) {
-                    boolean isAcknowledged = 
esClient.createTemplate(model.getName(), settings, mapping);
-                    log.info(
-                        "create {} index template finished, isAcknowledged: 
{}", model.getName(), isAcknowledged);
+            if (model.isTimeSeries()) {
+                if (!esClient.isExistsTemplate(tableName) || 
!isTemplateMappingCompatible(tableName, mapping)) {
+                    Map<String, Object> templateMapping = 
appendTemplateMapping(tableName, mapping);
+                    boolean isAcknowledged = esClient.putTemplate(tableName, 
settings, templateMapping);
+                    log.info("create {} index template finished, 
isAcknowledged: {}", tableName, isAcknowledged);
                     if (!isAcknowledged) {
-                        throw new StorageException("create " + model.getName() 
+ " index template failure, ");
+                        throw new StorageException("create " + tableName + " 
index template failure, ");
                     }
                 }
                 indexName = TimeSeriesUtils.latestWriteIndexName(model);
+            } else {
+                indexName = tableName;
             }
-            if (!esClient.isExistsIndex(indexName)) {
-                boolean isAcknowledged = esClient.createIndex(indexName);
+
+            if (esClient.isExistsIndex(indexName)) {

Review comment:
       Still not correct, I think. If you are going to delete an existing 
index, all data will be deleted in every rebooting process. I think you have 2 
options
   1. Don't recreate index, like we used to. Make the deleting as the user's 
responsibility
   2. Deleting index only when columns don't match as expected like template. 
But still, you could make the OAP accidentally removes all existing data, when 
users are not aware.
   
   So, I recommend (1). What do you think?




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