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@668121e274
This commit is contained in:
David Roberts 2017-08-17 14:54:31 +01:00 committed by GitHub
parent 751680e7b2
commit 44857d71b3
1 changed files with 7 additions and 7 deletions

View File

@ -23,16 +23,16 @@ import java.util.concurrent.atomic.AtomicReference;
* Represents a executor node operation that corresponds to a persistent task * Represents a executor node operation that corresponds to a persistent task
*/ */
public class AllocatedPersistentTask extends CancellableTask { public class AllocatedPersistentTask extends CancellableTask {
private String persistentTaskId; private volatile String persistentTaskId;
private long allocationId; private volatile long allocationId;
private final AtomicReference<State> state; private final AtomicReference<State> state;
@Nullable @Nullable
private Exception failure; private volatile Exception failure;
private PersistentTasksService persistentTasksService; private volatile PersistentTasksService persistentTasksService;
private Logger logger; private volatile Logger logger;
private TaskManager taskManager; private volatile TaskManager taskManager;
public AllocatedPersistentTask(long id, String type, String action, String description, TaskId parentTask) { public AllocatedPersistentTask(long id, String type, String action, String description, TaskId parentTask) {
@ -150,4 +150,4 @@ public class AllocatedPersistentTask extends CancellableTask {
} }
} }
} }
} }