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

kezhenxu94 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking.git


The following commit(s) were added to refs/heads/master by this push:
     new 58352ce6dc Fix Elasticsearch storage TTL timer, move creation of the 
latest index before retrieval indexes by aliases to avoid the 404 exception. 
(#11119)
58352ce6dc is described below

commit 58352ce6dcdcc49dec0876d707aad505089b107d
Author: Wan Kai <[email protected]>
AuthorDate: Thu Jul 20 21:37:10 2023 +0800

    Fix Elasticsearch storage TTL timer, move creation of the latest index 
before retrieval indexes by aliases to avoid the 404 exception. (#11119)
---
 docs/en/changes/changes.md                         |  1 +
 .../elasticsearch/base/HistoryDeleteEsDAO.java     | 39 +++++++++++-----------
 2 files changed, 21 insertions(+), 19 deletions(-)

diff --git a/docs/en/changes/changes.md b/docs/en/changes/changes.md
index 391424959d..09de7230c4 100644
--- a/docs/en/changes/changes.md
+++ b/docs/en/changes/changes.md
@@ -50,6 +50,7 @@
 * Apply MQE on Virtual-Cache layer UI-templates
 * Add Echo component ID(5015) language: Golang.
 * Fix `index out of bounds exception` in `aggregate_labels` MQE function.
+* Move created the latest index before retrieval indexes by aliases to avoid 
the 404 exception. This just prevents some interference from manual operations.
 
 #### UI
 
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 06bc7eda12..ebafa6451f 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
@@ -63,6 +63,26 @@ public class HistoryDeleteEsDAO extends EsDAO implements 
IHistoryDeleteDAO {
             }
             return;
         }
+
+        String latestIndex = TimeSeriesUtils.latestWriteIndexName(model);
+        if (!client.isExistsIndex(latestIndex)) {
+            try {
+                client.createIndex(latestIndex);
+                if (log.isDebugEnabled()) {
+                    log.debug("Latest index = {} is not exist, create.", 
latestIndex);
+                }
+            } catch (ResponseException e) {
+                if (e.getStatusCode() == 400 && 
client.isExistsIndex(latestIndex)) {
+                    if (log.isDebugEnabled()) {
+                        log.debug(
+                            "Failed to create index {}, index is already 
created.", latestIndex);
+                    }
+                } else {
+                    throw e;
+                }
+            }
+        }
+
         Collection<String> indices = client.retrievalIndexByAliases(tableName);
 
         if (log.isDebugEnabled()) {
@@ -70,13 +90,10 @@ public class HistoryDeleteEsDAO extends EsDAO implements 
IHistoryDeleteDAO {
         }
 
         List<String> prepareDeleteIndexes = new ArrayList<>();
-        List<String> leftIndices = new ArrayList<>();
         for (String index : indices) {
             long timeSeries = TimeSeriesUtils.isolateTimeFromIndexName(index);
             if (deadline >= timeSeries) {
                 prepareDeleteIndexes.add(index);
-            } else {
-                leftIndices.add(index);
             }
         }
         if (log.isDebugEnabled()) {
@@ -85,22 +102,6 @@ public class HistoryDeleteEsDAO extends EsDAO implements 
IHistoryDeleteDAO {
         for (String prepareDeleteIndex : prepareDeleteIndexes) {
             client.deleteByIndexName(prepareDeleteIndex);
         }
-        String latestIndex = TimeSeriesUtils.latestWriteIndexName(model);
-        String formattedLatestIndex = client.formatIndexName(latestIndex);
-        if (!leftIndices.contains(formattedLatestIndex)) {
-            try {
-                client.createIndex(latestIndex);
-            } catch (ResponseException e) {
-                if (e.getStatusCode() == 400 && 
client.isExistsIndex(latestIndex)) {
-                    if (log.isDebugEnabled()) {
-                        log.debug(
-                            "Failed to create index {}, index is already 
created.", latestIndex);
-                    }
-                } else {
-                    throw e;
-                }
-            }
-        }
         this.indexLatestSuccess.put(tableName, deadline);
     }
 }

Reply via email to