Skip to content

Commit 4dd9752

Browse files
StoneDotjojochuang
authored andcommitted
HDFS-17024. Potential data race introduced by HDFS-15865 (#6223)
(cherry picked from commit 93a3c6e)
1 parent 61c7b55 commit 4dd9752

File tree

1 file changed

+8
-2
lines changed
  • hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs

1 file changed

+8
-2
lines changed

hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DataStreamer.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ boolean doWaitForRestart() {
475475
private DataOutputStream blockStream;
476476
private DataInputStream blockReplyStream;
477477
private ResponseProcessor response = null;
478+
private final Object nodesLock = new Object();
478479
private volatile DatanodeInfo[] nodes = null; // list of targets for current block
479480
private volatile StorageType[] storageTypes = null;
480481
private volatile String[] storageIDs = null;
@@ -613,7 +614,9 @@ private void setPipeline(LocatedBlock lb) {
613614

614615
private void setPipeline(DatanodeInfo[] nodes, StorageType[] storageTypes,
615616
String[] storageIDs) {
616-
this.nodes = nodes;
617+
synchronized (nodesLock) {
618+
this.nodes = nodes;
619+
}
617620
this.storageTypes = storageTypes;
618621
this.storageIDs = storageIDs;
619622
}
@@ -910,7 +913,10 @@ void waitForAckedSeqno(long seqno) throws IOException {
910913
try (TraceScope ignored = dfsClient.getTracer().
911914
newScope("waitForAckedSeqno")) {
912915
LOG.debug("{} waiting for ack for: {}", this, seqno);
913-
int dnodes = nodes != null ? nodes.length : 3;
916+
int dnodes;
917+
synchronized (nodesLock) {
918+
dnodes = nodes != null ? nodes.length : 3;
919+
}
914920
int writeTimeout = dfsClient.getDatanodeWriteTimeout(dnodes);
915921
long begin = Time.monotonicNow();
916922
try {

0 commit comments

Comments
 (0)