From fd7de4c4eb3906e8e8a2631599dec78ff021d6c0 Mon Sep 17 00:00:00 2001 From: Suresh Srinivas Date: Sun, 28 Oct 2012 19:03:57 +0000 Subject: [PATCH] HDFS-4106. BPServiceActor#lastHeartbeat, lastBlockReport and lastDeletedReport should be volatile. Contributed by Jing Zhao. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1403075 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 +++ .../hadoop/hdfs/server/datanode/BPServiceActor.java | 10 +++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) 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; /**