diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 6063ba51f0..af5d1fdd0e 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -241,6 +241,9 @@ Trunk (Unreleased) HDFS-4115. TestHDFSCLI.testAll fails one test due to number format. (Trevor Robinson via suresh) + HDFS-4106. BPServiceActor#lastHeartbeat, lastBlockReport and + lastDeletedReport should be volatile. (Jing Zhao via suresh) + BREAKDOWN OF HDFS-3077 SUBTASKS HDFS-3077. Quorum-based protocol for reading and writing edit logs. diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BPServiceActor.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BPServiceActor.java index 4f00daaef5..4bbada2c02 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BPServiceActor.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BPServiceActor.java @@ -75,14 +75,18 @@ class BPServiceActor implements Runnable { BPOfferService bpos; - long lastBlockReport = 0; - long lastDeletedReport = 0; + // lastBlockReport, lastDeletedReport and lastHeartbeat may be assigned/read + // by testing threads (through BPServiceActor#triggerXXX), while also + // assigned/read by the actor thread. Thus they should be declared as volatile + // to make sure the "happens-before" consistency. + volatile long lastBlockReport = 0; + volatile long lastDeletedReport = 0; boolean resetBlockReportTime = true; Thread bpThread; DatanodeProtocolClientSideTranslatorPB bpNamenode; - private long lastHeartbeat = 0; + private volatile long lastHeartbeat = 0; private volatile boolean initialized = false; /**