Skip to content

Commit

Permalink
[ML] No refresh on indexing DFA stats (#53977)
Browse files Browse the repository at this point in the history
When we index data frame analytics stats docs we do not
need to refresh immediately.
  • Loading branch information
dimitris-athanasiou committed Mar 24, 2020
1 parent cbe063a commit 4cf1d1a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
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;
Expand Down Expand Up @@ -178,7 +179,7 @@ private void processData(DataFrameAnalyticsTask task, ProcessContext processCont
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()) {
Expand Down Expand Up @@ -316,12 +317,15 @@ private void refreshDest(DataFrameAnalyticsConfig config) {
() -> 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void persistWithRetry(ToXContentObject result, Function<String, String> d
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,
Expand Down

0 comments on commit 4cf1d1a

Please sign in to comment.