Skip to content

Commit ada3ca6

Browse files
authored
Make only a part of stop() method a critical section. (#49756)
1 parent 8f42719 commit ada3ca6

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/process/AnalyticsProcessManager.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void runJob(DataFrameAnalyticsTask task, DataFrameAnalyticsConfig config,
9393
Consumer<Exception> finishHandler) {
9494
executorServiceForJob.execute(() -> {
9595
ProcessContext processContext = new ProcessContext(config.getId());
96-
synchronized (this) {
96+
synchronized (processContextByAllocation) {
9797
if (task.isStopping()) {
9898
// The task was requested to stop before we created the process context
9999
finishHandler.accept(null);
@@ -295,14 +295,17 @@ private void closeProcess(DataFrameAnalyticsTask task) {
295295
processContext.process.close();
296296
LOGGER.info("[{}] Closed process", configId);
297297
} catch (Exception e) {
298-
String errorMsg = new ParameterizedMessage("[{}] Error closing data frame analyzer process [{}]"
299-
, configId, e.getMessage()).getFormattedMessage();
298+
String errorMsg = new ParameterizedMessage(
299+
"[{}] Error closing data frame analyzer process [{}]", configId, e.getMessage()).getFormattedMessage();
300300
processContext.setFailureReason(errorMsg);
301301
}
302302
}
303303

304-
public synchronized void stop(DataFrameAnalyticsTask task) {
305-
ProcessContext processContext = processContextByAllocation.get(task.getAllocationId());
304+
public void stop(DataFrameAnalyticsTask task) {
305+
ProcessContext processContext;
306+
synchronized (processContextByAllocation) {
307+
processContext = processContextByAllocation.get(task.getAllocationId());
308+
}
306309
if (processContext != null) {
307310
LOGGER.debug("[{}] Stopping process", task.getParams().getId());
308311
processContext.stop();

0 commit comments

Comments
 (0)