Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to also refresh dest index in this method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to use the config's headers to refresh the dest index which is why I kept it separate.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, thanks for explanation.

RefreshRequest refreshRequest = new RefreshRequest(
AnomalyDetectorsIndex.jobStateIndexPattern(),
MlStatsIndex.indexPattern()
);
refreshRequest.indicesOptions(IndicesOptions.lenientExpandOpen());

LOGGER.debug("[{}] Refreshing indices {}", jobId, Arrays.toString(refreshRequest.indices()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
LOGGER.debug("[{}] Refreshing indices {}", jobId, Arrays.toString(refreshRequest.indices()));
LOGGER.debug(() -> new ParameterizedMessage("[{}] Refreshing indices {}", jobId, Arrays.toString(refreshRequest.indices())));

I think the string is created eagerly. This is not strictly necessary unless the logging level is debug.

This is a minor thing as most of our logging does not take this into account.


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