From 44857d71b325f8542f5454aed66cb540182c5e4f Mon Sep 17 00:00:00 2001 From: David Roberts Date: Thu, 17 Aug 2017 14:54:31 +0100 Subject: [PATCH] Make AllocatedPersistentTask members volatile (elastic/x-pack-elasticsearch#2297) These members are default initialized on contruction and then set by the init() method. It's possible that another thread accessing the object after init() is called could still see the null/0 values, depending on how the compiler optimizes the code. Original commit: elastic/x-pack-elasticsearch@668121e2747bb637c50baa23bdcf46b70b33effa --- .../xpack/persistent/AllocatedPersistentTask.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/plugin/src/main/java/org/elasticsearch/xpack/persistent/AllocatedPersistentTask.java b/plugin/src/main/java/org/elasticsearch/xpack/persistent/AllocatedPersistentTask.java index 7c85539e9b2..40cf9cc9fd0 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/persistent/AllocatedPersistentTask.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/persistent/AllocatedPersistentTask.java @@ -23,16 +23,16 @@ import java.util.concurrent.atomic.AtomicReference; * Represents a executor node operation that corresponds to a persistent task */ public class AllocatedPersistentTask extends CancellableTask { - private String persistentTaskId; - private long allocationId; + private volatile String persistentTaskId; + private volatile long allocationId; private final AtomicReference state; @Nullable - private Exception failure; + private volatile Exception failure; - private PersistentTasksService persistentTasksService; - private Logger logger; - private TaskManager taskManager; + private volatile PersistentTasksService persistentTasksService; + private volatile Logger logger; + private volatile TaskManager taskManager; public AllocatedPersistentTask(long id, String type, String action, String description, TaskId parentTask) { @@ -150,4 +150,4 @@ public class AllocatedPersistentTask extends CancellableTask { } } } -} \ No newline at end of file +}