HDFS-15651. Client could not obtain block when DN CommandProcessingThread exit. Contributed by Aiphago.

Reviewed-by: He Xiaoqiao <hexiaoqiao@apache.org>
Reviewed-by: Yiqun Lin <yqlin@apache.org>
This commit is contained in:
He Xiaoqiao 2020-11-04 13:53:46 +08:00
parent 7ac7840fc3
commit 3067a25fa1
No known key found for this signature in database
GPG Key ID: A80CC124E9A0FA63
2 changed files with 35 additions and 1 deletions

View File

@ -1312,6 +1312,10 @@ class BPServiceActor implements Runnable {
processQueue();
} catch (Throwable t) {
LOG.error("{} encountered fatal exception and exit.", getName(), t);
runningState = RunningState.FAILED;
} finally {
LOG.warn("Ending command processor service for: " + this);
shouldServiceRun = false;
}
}
@ -1327,6 +1331,7 @@ class BPServiceActor implements Runnable {
dn.getMetrics().incrNumProcessedCommands();
} catch (InterruptedException e) {
LOG.error("{} encountered interrupt and exit.", getName());
Thread.currentThread().interrupt();
// ignore unless thread was specifically interrupted.
if (Thread.interrupted()) {
break;
@ -1398,4 +1403,11 @@ class BPServiceActor implements Runnable {
dn.getMetrics().incrActorCmdQueueLength(1);
}
}
@VisibleForTesting
void stopCommandProcessingThread() {
if (commandProcessingThread != null) {
commandProcessingThread.interrupt();
}
}
}

View File

@ -1211,4 +1211,26 @@ public class TestBPOfferService {
}
}
}
}
@Test(timeout = 5000)
public void testCommandProcessingThreadExit() throws Exception {
Configuration conf = new HdfsConfiguration();
MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).
numDataNodes(1).build();
try {
List<DataNode> datanodes = cluster.getDataNodes();
DataNode dataNode = datanodes.get(0);
List<BPOfferService> allBpOs = dataNode.getAllBpOs();
BPOfferService bpos = allBpOs.get(0);
waitForInitialization(bpos);
BPServiceActor actor = bpos.getBPServiceActors().get(0);
// Stop and wait util actor exit.
actor.stopCommandProcessingThread();
GenericTestUtils.waitFor(() -> !actor.isAlive(), 100, 3000);
} finally {
if (cluster != null) {
cluster.shutdown();
}
}
}
}