HDFS-17024. Potential data race introduced by HDFS-15865 (#6223)

This commit is contained in:
Hiroaki Segawa 2023-10-27 14:25:00 +09:00 committed by GitHub
parent 652908519e
commit 93a3c6e2cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;
@ -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;
}
@ -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 {