From be20bb5755fa27f88f2a65cb4a41f4fd0eee2550 Mon Sep 17 00:00:00 2001 From: Dimitris Athanasiou Date: Tue, 24 Mar 2020 13:13:03 +0200 Subject: [PATCH] [7.x][ML] No refresh on indexing DFA stats (#53977) (#54064) When we index data frame analytics stats docs we do not need to refresh immediately. Backport of #53977 --- .../process/AnalyticsProcessManager.java | 16 ++++++++++------ .../xpack/ml/dataframe/stats/StatsPersister.java | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/process/AnalyticsProcessManager.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/process/AnalyticsProcessManager.java index c1f09ff3fb3..cc3852f32f0 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/process/AnalyticsProcessManager.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/process/AnalyticsProcessManager.java @@ -46,6 +46,7 @@ import org.elasticsearch.xpack.ml.notifications.DataFrameAnalyticsAuditor; import org.elasticsearch.xpack.ml.utils.persistence.ResultsPersisterService; import java.io.IOException; +import java.util.Arrays; import java.util.List; import java.util.Objects; import java.util.Optional; @@ -178,7 +179,7 @@ public class AnalyticsProcessManager { processContext.setFailureReason(resultProcessor.getFailure()); refreshDest(config); - refreshStateIndex(config.getId()); + refreshIndices(config.getId()); LOGGER.info("[{}] Result processor has completed", config.getId()); } catch (Exception e) { if (task.isStopping()) { @@ -316,12 +317,15 @@ public class AnalyticsProcessManager { () -> client.execute(RefreshAction.INSTANCE, new RefreshRequest(config.getDest().getIndex())).actionGet()); } - private void refreshStateIndex(String jobId) { - String indexName = AnomalyDetectorsIndex.jobStateIndexPattern(); - LOGGER.debug("[{}] Refresh index {}", jobId, indexName); - - RefreshRequest refreshRequest = new RefreshRequest(indexName); + private void refreshIndices(String jobId) { + RefreshRequest refreshRequest = new RefreshRequest( + AnomalyDetectorsIndex.jobStateIndexPattern(), + MlStatsIndex.indexPattern() + ); refreshRequest.indicesOptions(IndicesOptions.lenientExpandOpen()); + + LOGGER.debug("[{}] Refreshing indices {}", jobId, Arrays.toString(refreshRequest.indices())); + try (ThreadContext.StoredContext ignore = client.threadPool().getThreadContext().stashWithOrigin(ML_ORIGIN)) { client.admin().indices().refresh(refreshRequest).actionGet(); } diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/stats/StatsPersister.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/stats/StatsPersister.java index eeb8924928c..e553ac18107 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/stats/StatsPersister.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/stats/StatsPersister.java @@ -47,7 +47,7 @@ public class StatsPersister { MlStatsIndex.writeAlias(), result, new ToXContent.MapParams(Collections.singletonMap(ToXContentParams.FOR_INTERNAL_STORAGE, "true")), - WriteRequest.RefreshPolicy.IMMEDIATE, + WriteRequest.RefreshPolicy.NONE, docIdSupplier.apply(jobId), () -> isCancelled == false, errorMsg -> auditor.error(jobId,