Fix Elasticsearch storage TTL timer, move creation of the latest index before retrieval indexes by aliases to avoid the 404 exception. (#11119)
This commit is contained in:
parent
55da7cd9b7
commit
58352ce6dc
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -63,33 +63,14 @@ public class HistoryDeleteEsDAO extends EsDAO implements IHistoryDeleteDAO {
|
|||
}
|
||||
return;
|
||||
}
|
||||
Collection<String> indices = client.retrievalIndexByAliases(tableName);
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Deadline = {}, indices = {}, ttl = {}", deadline, indices, ttl);
|
||||
}
|
||||
|
||||
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()) {
|
||||
log.debug("Indices to be deleted: {}", prepareDeleteIndexes);
|
||||
}
|
||||
for (String prepareDeleteIndex : prepareDeleteIndexes) {
|
||||
client.deleteByIndexName(prepareDeleteIndex);
|
||||
}
|
||||
String latestIndex = TimeSeriesUtils.latestWriteIndexName(model);
|
||||
String formattedLatestIndex = client.formatIndexName(latestIndex);
|
||||
if (!leftIndices.contains(formattedLatestIndex)) {
|
||||
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()) {
|
||||
|
|
@ -101,6 +82,26 @@ public class HistoryDeleteEsDAO extends EsDAO implements IHistoryDeleteDAO {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
Collection<String> indices = client.retrievalIndexByAliases(tableName);
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Deadline = {}, indices = {}, ttl = {}", deadline, indices, ttl);
|
||||
}
|
||||
|
||||
List<String> prepareDeleteIndexes = new ArrayList<>();
|
||||
for (String index : indices) {
|
||||
long timeSeries = TimeSeriesUtils.isolateTimeFromIndexName(index);
|
||||
if (deadline >= timeSeries) {
|
||||
prepareDeleteIndexes.add(index);
|
||||
}
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Indices to be deleted: {}", prepareDeleteIndexes);
|
||||
}
|
||||
for (String prepareDeleteIndex : prepareDeleteIndexes) {
|
||||
client.deleteByIndexName(prepareDeleteIndex);
|
||||
}
|
||||
this.indexLatestSuccess.put(tableName, deadline);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue