Skip to content

Commit

Permalink
HDFS-17024. Potential data race introduced by HDFS-15865 (#6223)
Browse files Browse the repository at this point in the history
  • Loading branch information
StoneDot authored Oct 27, 2023
1 parent 6529085 commit 93a3c6e
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ boolean doWaitForRestart() {
private DataOutputStream blockStream;
private DataInputStream blockReplyStream;
private ResponseProcessor response = null;
private final Object nodesLock = new Object();
private volatile DatanodeInfo[] nodes = null; // list of targets for current block
private volatile StorageType[] storageTypes = null;
private volatile String[] storageIDs = null;
Expand Down Expand Up @@ -619,7 +620,9 @@ private void setPipeline(LocatedBlock lb) {

private void setPipeline(DatanodeInfo[] nodes, StorageType[] storageTypes,
String[] storageIDs) {
this.nodes = nodes;
synchronized (nodesLock) {
this.nodes = nodes;
}
this.storageTypes = storageTypes;
this.storageIDs = storageIDs;
}
Expand Down Expand Up @@ -916,7 +919,10 @@ void waitForAckedSeqno(long seqno) throws IOException {
try (TraceScope ignored = dfsClient.getTracer().
newScope("waitForAckedSeqno")) {
LOG.debug("{} waiting for ack for: {}", this, seqno);
int dnodes = nodes != null ? nodes.length : 3;
int dnodes;
synchronized (nodesLock) {
dnodes = nodes != null ? nodes.length : 3;
}
int writeTimeout = dfsClient.getDatanodeWriteTimeout(dnodes);
long begin = Time.monotonicNow();
try {
Expand Down

0 comments on commit 93a3c6e

Please sign in to comment.