diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportStartDataFrameAnalyticsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportStartDataFrameAnalyticsAction.java index 31efa34c529aa..64734979072ed 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportStartDataFrameAnalyticsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportStartDataFrameAnalyticsAction.java @@ -618,7 +618,8 @@ protected AllocatedPersistentTask createTask( @Override public PersistentTasksCustomMetadata.Assignment getAssignment(TaskParams params, ClusterState clusterState) { boolean isMemoryTrackerRecentlyRefreshed = memoryTracker.isRecentlyRefreshed(); - Optional optionalAssignment = getPotentialAssignment(params, clusterState); + Optional optionalAssignment = + getPotentialAssignment(params, clusterState, isMemoryTrackerRecentlyRefreshed); if (optionalAssignment.isPresent()) { return optionalAssignment.get(); } diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/snapshot/upgrader/SnapshotUpgradeTaskExecutor.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/snapshot/upgrader/SnapshotUpgradeTaskExecutor.java index 8e954249d84d3..415a04f5cf804 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/snapshot/upgrader/SnapshotUpgradeTaskExecutor.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/snapshot/upgrader/SnapshotUpgradeTaskExecutor.java @@ -79,7 +79,8 @@ public SnapshotUpgradeTaskExecutor(Settings settings, @Override public PersistentTasksCustomMetadata.Assignment getAssignment(SnapshotUpgradeTaskParams params, ClusterState clusterState) { boolean isMemoryTrackerRecentlyRefreshed = memoryTracker.isRecentlyRefreshed(); - Optional optionalAssignment = getPotentialAssignment(params, clusterState); + Optional optionalAssignment = + getPotentialAssignment(params, clusterState, isMemoryTrackerRecentlyRefreshed); if (optionalAssignment.isPresent()) { return optionalAssignment.get(); } diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/task/OpenJobPersistentTasksExecutor.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/task/OpenJobPersistentTasksExecutor.java index 77bd1afad1aaf..c3d8f3f2b341e 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/task/OpenJobPersistentTasksExecutor.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/task/OpenJobPersistentTasksExecutor.java @@ -105,7 +105,8 @@ public PersistentTasksCustomMetadata.Assignment getAssignment(OpenJobAction.JobP return AWAITING_MIGRATION; } boolean isMemoryTrackerRecentlyRefreshed = memoryTracker.isRecentlyRefreshed(); - Optional optionalAssignment = getPotentialAssignment(params, clusterState); + Optional optionalAssignment = + getPotentialAssignment(params, clusterState, isMemoryTrackerRecentlyRefreshed); if (optionalAssignment.isPresent()) { return optionalAssignment.get(); } diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/task/AbstractJobPersistentTasksExecutor.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/task/AbstractJobPersistentTasksExecutor.java index 2da8135cf01bb..8189b5ba20246 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/task/AbstractJobPersistentTasksExecutor.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/task/AbstractJobPersistentTasksExecutor.java @@ -104,7 +104,8 @@ protected boolean allowsMissingIndices() { return true; } - public Optional getPotentialAssignment(Params params, ClusterState clusterState) { + public Optional getPotentialAssignment(Params params, ClusterState clusterState, + boolean isMemoryTrackerRecentlyRefreshed) { // If we are waiting for an upgrade to complete, we should not assign to a node if (MlMetadata.getMlMetadata(clusterState).isUpgradeMode()) { return Optional.of(AWAITING_UPGRADE); @@ -117,7 +118,7 @@ public Optional getPotentialAssignment if (missingIndices.isPresent()) { return missingIndices; } - Optional staleMemory = checkMemoryFreshness(jobId); + Optional staleMemory = checkMemoryFreshness(jobId, isMemoryTrackerRecentlyRefreshed); if (staleMemory.isPresent()) { return staleMemory; } @@ -164,8 +165,7 @@ public Optional checkRequiredIndices(S return Optional.empty(); } - public Optional checkMemoryFreshness(String jobId) { - boolean isMemoryTrackerRecentlyRefreshed = memoryTracker.isRecentlyRefreshed(); + public Optional checkMemoryFreshness(String jobId, boolean isMemoryTrackerRecentlyRefreshed) { if (isMemoryTrackerRecentlyRefreshed == false) { boolean scheduledRefresh = memoryTracker.asyncRefresh(); if (scheduledRefresh) {