From ddc50a86f7d90a052611ef947bc58e1cac12e00a Mon Sep 17 00:00:00 2001 From: zeekling Date: Sun, 28 Jul 2024 20:24:00 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=99BPServiceActor=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hadoop/hdfs/server/datanode/BPServiceActor.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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 71834f8965..ae92dfe4b6 100755 --- 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 @@ -532,7 +532,8 @@ private int calculateBlockReportPBSize( } return reportSize; } - + + // 向NN发送心跳的主要实现 HeartbeatResponse sendHeartBeat(boolean requestBlockReportLease) throws IOException { scheduler.scheduleNextHeartbeat(); @@ -587,6 +588,7 @@ void sendLifelineForTests() throws IOException { } //This must be called only by BPOfferService + // 入口函数,开始向NN注册当前DN void start() { if ((bpThread != null) && (bpThread.isAlive())) { //Thread is started already @@ -827,6 +829,7 @@ void register(NamespaceInfo nsInfo) throws IOException { while (shouldRun()) { try { // Use returned registration from namenode with updated fields + // 向NN注册DataNodde newBpRegistration = bpNamenode.registerDatanode(newBpRegistration); newBpRegistration.setNamespaceInfo(nsInfo); bpRegistration = newBpRegistration; @@ -858,6 +861,7 @@ void register(NamespaceInfo nsInfo) throws IOException { fullBlockReportLeaseId = 0; // random short delay - helps scatter the BR from all DNs + // 定时汇报block块信息给NN scheduler.scheduleBlockReport(dnConf.initialBlockReportDelayMs, true); } @@ -875,6 +879,7 @@ private void sleepAndLogInterrupts(int millis, * No matter what kind of exception we get, keep retrying to offerService(). * That's the loop that connects to the NameNode and provides basic DataNode * functionality. + * 当前类本身就是一个异步线程,当前函数为线程的入口函数,线程由start函数启动。 * * Only stop when "shouldRun" or "shouldServiceRun" is turned off, which can * happen either at shutdown or due to refreshNamenodes. @@ -888,6 +893,7 @@ public void run() { // init stuff try { // setup storage + // 开始连接NN并且注册当前DN,主要分为两个阶段:1、握手,并且校验NS等信息。2、向NN注册当前DN。 connectToNNAndHandshake(); break; } catch (IOException ioe) { @@ -1527,4 +1533,4 @@ void stopCommandProcessingThread() { commandProcessingThread.interrupt(); } } -} \ No newline at end of file +}