You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by ha...@apache.org on 2020/04/15 04:45:27 UTC

[skywalking] 01/01: Keep latest index always present. * Avoid TTL timer to remove latest index * Create a latest index even without any data.

This is an automated email from the ASF dual-hosted git repository.

hanahmily pushed a commit to branch es/ttl
in repository https://gitbox.apache.org/repos/asf/skywalking.git

commit e8a1edf94ad17ee5a912861b9fffe4109b870a4a
Author: Gao Hongtao <ha...@gmail.com>
AuthorDate: Wed Apr 15 12:42:23 2020 +0800

    Keep latest index always present.
      * Avoid TTL timer to remove latest index
      * Create a latest index even without any data.
    
    Signed-off-by: Gao Hongtao <ha...@gmail.com>
---
 .../plugin/elasticsearch/base/HistoryDeleteEsDAO.java        | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/base/HistoryDeleteEsDAO.java b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/base/HistoryDeleteEsDAO.java
index d86bb43..a38c8fa 100644
--- a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/base/HistoryDeleteEsDAO.java
+++ b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/base/HistoryDeleteEsDAO.java
@@ -54,19 +54,21 @@ public class HistoryDeleteEsDAO extends EsDAO implements IHistoryDeleteDAO {
         List<String> indexes = client.retrievalIndexByAliases(model.getName());
 
         List<String> prepareDeleteIndexes = new ArrayList<>();
+        List<String> leftIndices = new ArrayList<>();
         for (String index : indexes) {
             long timeSeries = TimeSeriesUtils.isolateTimeFromIndexName(index);
             if (deadline >= timeSeries) {
                 prepareDeleteIndexes.add(index);
+            } else {
+                leftIndices.add(index);
             }
         }
-
-        if (indexes.size() == prepareDeleteIndexes.size()) {
-            client.createIndex(TimeSeriesUtils.latestWriteIndexName(model));
-        }
-
         for (String prepareDeleteIndex : prepareDeleteIndexes) {
             client.deleteByIndexName(prepareDeleteIndex);
         }
+        String latestIndex = TimeSeriesUtils.latestWriteIndexName(model);
+        if (!leftIndices.contains(latestIndex)) {
+            client.createIndex(TimeSeriesUtils.timeSeries(model));
+        }
     }
 }