Make only a part of `stop()` method a critical section. (#49756) (#49788)

This commit is contained in:
Przemysław Witek 2019-12-03 09:54:16 +01:00 committed by GitHub
parent 3bbaa01764
commit 1d8e3d69d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 5 deletions

View File

@ -93,7 +93,7 @@ public class AnalyticsProcessManager {
Consumer<Exception> finishHandler) {
executorServiceForJob.execute(() -> {
ProcessContext processContext = new ProcessContext(config.getId());
synchronized (this) {
synchronized (processContextByAllocation) {
if (task.isStopping()) {
// The task was requested to stop before we created the process context
finishHandler.accept(null);
@ -295,14 +295,17 @@ public class AnalyticsProcessManager {
processContext.process.close();
LOGGER.info("[{}] Closed process", configId);
} catch (Exception e) {
String errorMsg = new ParameterizedMessage("[{}] Error closing data frame analyzer process [{}]"
, configId, e.getMessage()).getFormattedMessage();
String errorMsg = new ParameterizedMessage(
"[{}] Error closing data frame analyzer process [{}]", configId, e.getMessage()).getFormattedMessage();
processContext.setFailureReason(errorMsg);
}
}
public synchronized void stop(DataFrameAnalyticsTask task) {
ProcessContext processContext = processContextByAllocation.get(task.getAllocationId());
public void stop(DataFrameAnalyticsTask task) {
ProcessContext processContext;
synchronized (processContextByAllocation) {
processContext = processContextByAllocation.get(task.getAllocationId());
}
if (processContext != null) {
LOGGER.debug("[{}] Stopping process", task.getParams().getId());
processContext.stop();